@@ -197,6 +197,7 @@ int NanostackSocket::accept(NanostackSocket *accepted_socket, ns_address_t *addr
197
197
198
198
bool NanostackSocket::attach (int8_t temp_socket)
199
199
{
200
+ nanostack_assert_locked ();
200
201
if (temp_socket >= NS_INTERFACE_SOCKETS_MAX) {
201
202
MBED_ASSERT (false );
202
203
return false ;
@@ -382,6 +383,7 @@ void NanostackSocket::event_connect_fail(socket_callback_t *sock_cb)
382
383
383
384
void NanostackSocket::event_incoming_connection (socket_callback_t *sock_cb)
384
385
{
386
+ nanostack_assert_locked ();
385
387
MBED_ASSERT (mode == SOCKET_MODE_LISTENING);
386
388
signal_event ();
387
389
}
@@ -429,14 +431,12 @@ NanostackInterface *NanostackInterface::_ns_interface;
429
431
430
432
NanostackInterface *NanostackInterface::get_stack ()
431
433
{
432
- nanostack_lock () ;
434
+ NanostackLockGuard lock ;
433
435
434
436
if (NULL == _ns_interface) {
435
437
_ns_interface = new NanostackInterface ();
436
438
}
437
439
438
- nanostack_unlock ();
439
-
440
440
return _ns_interface;
441
441
}
442
442
@@ -479,13 +479,11 @@ nsapi_error_t NanostackInterface::socket_open(void **handle, nsapi_protocol_t pr
479
479
480
480
NanostackSocket * socket = new NanostackSocket (ns_proto);
481
481
if (socket == NULL ) {
482
- nanostack_unlock ();
483
482
tr_debug (" socket_open() ret=%i" , NSAPI_ERROR_NO_MEMORY);
484
483
return NSAPI_ERROR_NO_MEMORY;
485
484
}
486
485
if (!socket->open ()) {
487
486
delete socket;
488
- nanostack_unlock ();
489
487
tr_debug (" socket_open() ret=%i" , NSAPI_ERROR_DEVICE_ERROR);
490
488
return NSAPI_ERROR_DEVICE_ERROR;
491
489
}
@@ -498,6 +496,7 @@ nsapi_error_t NanostackInterface::socket_open(void **handle, nsapi_protocol_t pr
498
496
499
497
nsapi_error_t NanostackInterface::socket_close (void *handle)
500
498
{
499
+ NanostackLockGuard lock;
501
500
// Validate parameters
502
501
NanostackSocket * socket = static_cast <NanostackSocket *>(handle);
503
502
if (NULL == handle) {
@@ -506,12 +505,8 @@ nsapi_error_t NanostackInterface::socket_close(void *handle)
506
505
}
507
506
tr_debug (" socket_close(socket=%p) sock_id=%d" , socket, socket->socket_id );
508
507
509
- nanostack_lock ();
510
-
511
508
delete socket;
512
509
513
- nanostack_unlock ();
514
-
515
510
return 0 ;
516
511
517
512
}
0 commit comments