diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 59a8163ca98..37b3c8bb3ef 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -301,11 +301,12 @@ void net_initialize(void); * None * * Returned Value: - * None + * Zero (OK) is returned on success; a negated errno value is returned on + * failured (probably -ECANCELED). * ****************************************************************************/ -void net_lock(void); +int net_lock(void); /**************************************************************************** * Name: net_unlock diff --git a/net/utils/net_lock.c b/net/utils/net_lock.c index 0512beb19aa..0b5146a0f5d 100644 --- a/net/utils/net_lock.c +++ b/net/utils/net_lock.c @@ -80,7 +80,7 @@ static unsigned int g_count = 0; * ****************************************************************************/ -static void _net_takesem(void) +static int _net_takesem(void) { int ret; @@ -94,9 +94,11 @@ static void _net_takesem(void) * awakened by a signal. */ - DEBUGASSERT(ret == OK || ret == -EINTR); + DEBUGASSERT(ret == OK || ret == -EINTR || ret == -ECANCELED); } while (ret == -EINTR); + + return ret; } /**************************************************************************** @@ -126,16 +128,18 @@ void net_lockinitialize(void) * None * * Returned Value: - * None + * Zero (OK) is returned on success; a negated errno value is returned on + * failured (probably -ECANCELED). * ****************************************************************************/ -void net_lock(void) +int net_lock(void) { #ifdef CONFIG_SMP irqstate_t flags = enter_critical_section(); #endif pid_t me = getpid(); + int ret = OK; /* Does this thread already hold the semaphore? */ @@ -149,17 +153,20 @@ void net_lock(void) { /* No.. take the semaphore (perhaps waiting) */ - _net_takesem(); + ret = _net_takesem(); + if (ret >= 0) + { + /* Now this thread holds the semaphore */ - /* Now this thread holds the semaphore */ - - g_holder = me; - g_count = 1; + g_holder = me; + g_count = 1; + } } #ifdef CONFIG_SMP leave_critical_section(flags); #endif + return ret; } /**************************************************************************** @@ -243,24 +250,34 @@ int net_breaklock(FAR unsigned int *count) } /**************************************************************************** - * Name: net_breaklock + * Name: net_restorelock * * Description: * Restore the locked state * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * failured (probably -ECANCELED). + * ****************************************************************************/ -void net_restorelock(unsigned int count) +int net_restorelock(unsigned int count) { pid_t me = getpid(); + int ret; DEBUGASSERT(g_holder != me); /* Recover the network lock at the proper count */ - _net_takesem(); - g_holder = me; - g_count = count; + ret = _net_takesem(); + if (ret >= 0) + { + g_holder = me; + g_count = count; + } + + return ret; } /**************************************************************************** diff --git a/net/utils/utils.h b/net/utils/utils.h index 4e6e301c91c..a09b905da48 100644 --- a/net/utils/utils.h +++ b/net/utils/utils.h @@ -103,9 +103,13 @@ int net_breaklock(FAR unsigned int *count); * Description: * Restore the locked state * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * failured (probably -ECANCELED). + * ****************************************************************************/ -void net_restorelock(unsigned int count); +int net_restorelock(unsigned int count); /**************************************************************************** * Name: net_dsec2timeval