Skip to content

Commit 1f24533

Browse files
author
Hasnain Virk
committed
Minor amendments
NanostackLockGuard usage is now consistent throughout. Missing Lock assertion added at a few locations in the code
1 parent 7dc2dc8 commit 1f24533

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

features/nanostack/FEATURE_NANOSTACK/nanostack-interface/NanostackInterface.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ int NanostackSocket::accept(NanostackSocket *accepted_socket, ns_address_t *addr
197197

198198
bool NanostackSocket::attach(int8_t temp_socket)
199199
{
200+
nanostack_assert_locked();
200201
if (temp_socket >= NS_INTERFACE_SOCKETS_MAX) {
201202
MBED_ASSERT(false);
202203
return false;
@@ -382,6 +383,7 @@ void NanostackSocket::event_connect_fail(socket_callback_t *sock_cb)
382383

383384
void NanostackSocket::event_incoming_connection(socket_callback_t *sock_cb)
384385
{
386+
nanostack_assert_locked();
385387
MBED_ASSERT(mode == SOCKET_MODE_LISTENING);
386388
signal_event();
387389
}
@@ -429,14 +431,12 @@ NanostackInterface *NanostackInterface::_ns_interface;
429431

430432
NanostackInterface *NanostackInterface::get_stack()
431433
{
432-
nanostack_lock();
434+
NanostackLockGuard lock;
433435

434436
if (NULL == _ns_interface) {
435437
_ns_interface = new NanostackInterface();
436438
}
437439

438-
nanostack_unlock();
439-
440440
return _ns_interface;
441441
}
442442

@@ -479,13 +479,11 @@ nsapi_error_t NanostackInterface::socket_open(void **handle, nsapi_protocol_t pr
479479

480480
NanostackSocket * socket = new NanostackSocket(ns_proto);
481481
if (socket == NULL) {
482-
nanostack_unlock();
483482
tr_debug("socket_open() ret=%i", NSAPI_ERROR_NO_MEMORY);
484483
return NSAPI_ERROR_NO_MEMORY;
485484
}
486485
if (!socket->open()) {
487486
delete socket;
488-
nanostack_unlock();
489487
tr_debug("socket_open() ret=%i", NSAPI_ERROR_DEVICE_ERROR);
490488
return NSAPI_ERROR_DEVICE_ERROR;
491489
}
@@ -498,6 +496,7 @@ nsapi_error_t NanostackInterface::socket_open(void **handle, nsapi_protocol_t pr
498496

499497
nsapi_error_t NanostackInterface::socket_close(void *handle)
500498
{
499+
NanostackLockGuard lock;
501500
// Validate parameters
502501
NanostackSocket * socket = static_cast<NanostackSocket *>(handle);
503502
if (NULL == handle) {
@@ -506,12 +505,8 @@ nsapi_error_t NanostackInterface::socket_close(void *handle)
506505
}
507506
tr_debug("socket_close(socket=%p) sock_id=%d", socket, socket->socket_id);
508507

509-
nanostack_lock();
510-
511508
delete socket;
512509

513-
nanostack_unlock();
514-
515510
return 0;
516511

517512
}

0 commit comments

Comments
 (0)