xiaoxiang781216 commented on code in PR #8645: URL: https://github.com/apache/nuttx/pull/8645#discussion_r1126765864
########## sched/mutex/mutex_unlock.c: ########## @@ -0,0 +1,113 @@ +/**************************************************************************** + * sched/mutex/mutex_unlock.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/sched.h> +#include <nuttx/mutex.h> + Review Comment: add assert.h ########## sched/mutex/mutex_unlock.c: ########## @@ -0,0 +1,113 @@ +/**************************************************************************** + * sched/mutex/mutex_unlock.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/sched.h> +#include <nuttx/mutex.h> + +#include "mutex.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmutex_unlock + * + * Description: + * This function attempts to unlock the mutex referenced by 'mutex'. + * + * Parameters: + * mutex - mutex descriptor. + * + * Return Value: + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure. + * Possible returned errors: + * + * Assumptions: + * This function may be called from an interrupt handler. + * + ****************************************************************************/ + +int nxmutex_unlock(FAR mutex_t *mutex) +{ + int ret; + + if (nxmutex_is_reset(mutex)) + { + return OK; + } + + DEBUGASSERT(nxmutex_is_hold(mutex)); + + mutex->holder = NXMUTEX_NO_HOLDER; + + ret = nxsem_post(&mutex->sem); + if (ret < 0) + { + mutex->holder = nxsched_gettid(); + } + + return ret; +} + +/**************************************************************************** + * Name: nxrmutex_unlock + * + * Description: + * This function attempts to unlock the recursive mutex + * referenced by 'rmutex'. + * + * Parameters: + * rmutex - Recursive mutex descriptor. + * + * Return Value: + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure. + * Possible returned errors: + * + * Assumptions: + * This function may be called from an interrupt handler. + * + ****************************************************************************/ + +int nxrmutex_unlock(FAR rmutex_t *rmutex) Review Comment: could be done in libc ########## sched/mutex/mutex_timedlock.c: ########## @@ -0,0 +1,127 @@ +/**************************************************************************** + * sched/mutex/mutex_timedlock.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/sched.h> +#include <nuttx/clock.h> +#include <nuttx/mutex.h> + +#include <assert.h> + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmutex_timedlock + * + * Description: + * This function attempts to lock the mutex . If the mutex value + * is (<=) zero,then the calling task will not return until it + * successfully acquires the lock or timed out + * + * Input Parameters: + * mutex - Mutex object + * timeout - The time when mutex lock timed out + * + * Returned Value: + * OK The mutex successfully acquires + * EINVAL The mutex argument does not refer to a valid mutex. Or the + * thread would have blocked, and the abstime parameter specified + * a nanoseconds field value less than zero or greater than or + * equal to 1000 million. + * ETIMEDOUT The mutex could not be locked before the specified timeout + * expired. + * EDEADLK A deadlock condition was detected. + * + ****************************************************************************/ + +int nxmutex_timedlock(FAR mutex_t *mutex, unsigned int timeout) +{ + int ret; + struct timespec now; + struct timespec delay; + struct timespec rqtp; + + clock_gettime(CLOCK_MONOTONIC, &now); + clock_ticks2time(MSEC2TICK(timeout), &delay); + clock_timespec_add(&now, &delay, &rqtp); + + /* Wait until we get the lock or until the timeout expires */ + + do + { + ret = nxsem_clockwait(&mutex->sem, CLOCK_MONOTONIC, &rqtp); + } + while (ret == -EINTR || ret == -ECANCELED); + + if (ret >= 0) + { + mutex->holder = nxsched_gettid(); + } + + return ret; +} + +/**************************************************************************** + * Name: nxrmutex_timedlock + * + * Description: + * This function attempts to lock the mutex . If the mutex value + * is (<=) zero,then the calling task will not return until it + * successfully acquires the lock or timed out + * + * Input Parameters: + * rmutex - Rmutex object + * timeout - The time when mutex lock timed out + * + * Returned Value: + * OK The mutex successfully acquires + * EINVAL The mutex argument does not refer to a valid mutex. Or the + * thread would have blocked, and the abstime parameter specified + * a nanoseconds field value less than zero or greater than or + * equal to 1000 million. + * ETIMEDOUT The mutex could not be locked before the specified timeout + * expired. + * EDEADLK A deadlock condition was detected. + * ECANCELED May be returned if the thread is canceled while waiting. + * + ****************************************************************************/ + +int nxrmutex_timedlock(FAR rmutex_t *rmutex, unsigned int timeout) Review Comment: could be done in libc ########## sched/mutex/mutex_restorelock.c: ########## @@ -0,0 +1,85 @@ +/**************************************************************************** + * sched/mutex/mutex_restorelock.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/mutex.h> + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmutex_restorelock + * + * Description: + * This function attempts to restore the mutex. + * + * Parameters: + * mutex - mutex descriptor. + * locked - true: it's mean that the mutex is broke success + * + * Return Value: + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure + * + ****************************************************************************/ + +int nxmutex_restorelock(FAR mutex_t *mutex, bool locked) +{ + return locked ? nxmutex_lock(mutex) : OK; +} + +/**************************************************************************** + * Name: nxrmutex_restorelock + * + * Description: + * This function attempts to restore the recursive mutex. + * + * Parameters: + * rmutex - Recursive mutex descriptor. + * count - Count after restore. + * + * Return Value: + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure. + * Possible returned errors: + * + ****************************************************************************/ + +int nxrmutex_restorelock(FAR rmutex_t *rmutex, unsigned int count) Review Comment: could be done in libc ########## sched/mutex/mutex_destroy.c: ########## @@ -0,0 +1,82 @@ +/**************************************************************************** + * sched/mutex/mutex_destroy.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/mutex.h> + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmutex_destroy + * + * Description: + * This function initializes the UNNAMED mutex. Following a + * successful call to nxmutex_init(), the mutex may be used in subsequent + * calls to nxmutex_lock(), nxmutex_unlock(), and nxmutex_trylock(). The + * mutex remains usable until it is destroyed. + * + * Parameters: + * mutex - Semaphore to be destroyed + * + * Return Value: + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure. + * + ****************************************************************************/ + +int nxmutex_destroy(FAR mutex_t *mutex) +{ + int ret = nxsem_destroy(&mutex->sem); + mutex->holder = NXMUTEX_NO_HOLDER; + return ret; +} + +/**************************************************************************** + * Name: nxrmutex_destroy + * + * Description: + * This function destroy the UNNAMED recursive mutex. + * + * Parameters: + * rmutex - Recursive mutex to be destroyed + * + * Return Value: + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure. + * + ****************************************************************************/ + +int nxrmutex_destroy(FAR rmutex_t *rmutex) Review Comment: could be done in libc ########## sched/mutex/mutex_reset.c: ########## @@ -0,0 +1,89 @@ +/**************************************************************************** + * sched/mutex/mutex_reset.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/mutex.h> + +#include "mutex.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define NXMUTEX_RESET ((pid_t)-2) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmutex_is_reset + * + * Description: + * This function check whether the mutex is reset + * + * Parameters: + * mutex - mutex descriptor. + * + * Return Value: + * + ****************************************************************************/ + +bool nxmutex_is_reset(FAR mutex_t *mutex) Review Comment: could be done in libc ########## sched/mutex/mutex_reset.c: ########## @@ -0,0 +1,89 @@ +/**************************************************************************** + * sched/mutex/mutex_reset.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/mutex.h> + +#include "mutex.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define NXMUTEX_RESET ((pid_t)-2) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmutex_is_reset + * + * Description: + * This function check whether the mutex is reset + * + * Parameters: + * mutex - mutex descriptor. + * + * Return Value: + * + ****************************************************************************/ + +bool nxmutex_is_reset(FAR mutex_t *mutex) +{ + return mutex->holder == NXMUTEX_RESET; +} + +/**************************************************************************** + * Name: nxmutex_reset + * + * Description: + * This function reset lock state. + * + * Parameters: + * mutex - mutex descriptor. + * + ****************************************************************************/ + +void nxmutex_reset(FAR mutex_t *mutex) +{ + mutex->holder = NXMUTEX_RESET; + nxsem_reset(&mutex->sem, 1); +} + +/**************************************************************************** + * Name: nxrmutex_reset + * + * Description: + * This function reset lock state. + * + * Parameters: + * rmutex - rmutex descriptor. + * + ****************************************************************************/ + +void nxrmutex_reset(FAR rmutex_t *rmutex) Review Comment: could be done in libc ########## sched/mutex/mutex_restorelock.c: ########## @@ -0,0 +1,85 @@ +/**************************************************************************** + * sched/mutex/mutex_restorelock.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/mutex.h> + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmutex_restorelock + * + * Description: + * This function attempts to restore the mutex. + * + * Parameters: + * mutex - mutex descriptor. + * locked - true: it's mean that the mutex is broke success + * + * Return Value: + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure + * + ****************************************************************************/ + +int nxmutex_restorelock(FAR mutex_t *mutex, bool locked) Review Comment: could be done in libc ########## sched/mutex/mutex_trylock.c: ########## @@ -0,0 +1,112 @@ +/**************************************************************************** + * sched/mutex/mutex_trylock.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/sched.h> +#include <nuttx/mutex.h> + +#include <assert.h> + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmutex_trylock + * + * Description: + * This function locks the mutex only if the mutex is currently not locked. + * If the mutex has been locked already, the call returns without blocking. + * + * Parameters: + * mutex - mutex descriptor. + * + * Return Value: + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure. + * Possible returned errors: + * + * -EINVAL - Invalid attempt to lock the mutex + * -EAGAIN - The mutex is not available. + * + ****************************************************************************/ + +int nxmutex_trylock(FAR mutex_t *mutex) +{ + int ret; + + if (nxmutex_is_hold(mutex)) + { + return -EAGAIN; + } + + ret = nxsem_trywait(&mutex->sem); + if (ret >= 0) + { + mutex->holder = nxsched_gettid(); + } + + return ret; +} + +/**************************************************************************** + * Name: nxrmutex_trylock + * + * Description: + * This function locks the recursive mutex if the recursive mutex is + * currently not locked or the same thread call. + * If the recursive mutex is locked and other thread call it, + * the call returns without blocking. + * + * Parameters: + * rmutex - Recursive mutex descriptor. + * + * Return Value: + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure. + * Possible returned errors: + * + * -EINVAL - Invalid attempt to lock the recursive mutex + * -EAGAIN - The recursive mutex is not available. + * + ****************************************************************************/ + +int nxrmutex_trylock(FAR rmutex_t *rmutex) Review Comment: could be done in libc ########## sched/mutex/mutex_is_hold.c: ########## @@ -0,0 +1,50 @@ +/**************************************************************************** + * sched/mutex/mutex_is_hold.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/sched.h> +#include <nuttx/mutex.h> + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmutex_is_hold + * + * Description: + * This function check whether the caller hold the mutex + * referenced by 'mutex'. + * + * Parameters: + * mutex - mutex descriptor. + * + * Return Value: + * Return true if mutex is hold by current thread. + * + ****************************************************************************/ + +bool nxmutex_is_hold(FAR mutex_t *mutex) Review Comment: could be done in libc ########## sched/mutex/mutex_lock.c: ########## @@ -0,0 +1,115 @@ +/**************************************************************************** + * sched/mutex/mutex_lock.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/sched.h> +#include <nuttx/mutex.h> + +#include <assert.h> + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmutex_lock + * + * Description: + * This function attempts to lock the mutex referenced by 'mutex'. The + * mutex is implemented with a semaphore, so if the semaphore value is + * (<=) zero, then the calling task will not return until it successfully + * acquires the lock. + * + * Parameters: + * mutex - mutex descriptor. + * + * Return Value: + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure. + * Possible returned errors: + * + ****************************************************************************/ + +int nxmutex_lock(FAR mutex_t *mutex) +{ + int ret; + + DEBUGASSERT(!nxmutex_is_hold(mutex)); + for (; ; ) + { + /* Take the semaphore (perhaps waiting) */ + + ret = nxsem_wait(&mutex->sem); + if (ret >= 0) + { + mutex->holder = nxsched_gettid(); + break; + } + + if (ret != -EINTR && ret != -ECANCELED) + { + break; + } + } + + return ret; +} + +/**************************************************************************** + * Name: nxrmutex_lock + * + * Description: + * This function attempts to lock the recursive mutex referenced by + * 'rmutex'.The recursive mutex can be locked multiple times in the same + * thread. + * + * Parameters: + * rmutex - Recursive mutex descriptor. + * + * Return Value: + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure. + * Possible returned errors: + * + ****************************************************************************/ + +int nxrmutex_lock(FAR rmutex_t *rmutex) Review Comment: could be done in libc ########## sched/mutex/mutex_breaklock.c: ########## @@ -0,0 +1,105 @@ +/**************************************************************************** + * sched/mutex/mutex_breaklock.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/mutex.h> + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmutex_breaklock + * + * Description: + * This function attempts to break the mutex + * + * Input Parameters: + * mutex - Mutex descriptor. + * + * Output Parameters: + * locked - Is the mutex break success + * + * Return Value: + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure. + * Possible returned errors: + * + ****************************************************************************/ + +int nxmutex_breaklock(FAR mutex_t *mutex, FAR bool *locked) +{ + int ret = OK; + + *locked = false; + if (nxmutex_is_hold(mutex)) + { + ret = nxmutex_unlock(mutex); + if (ret >= 0) + { + *locked = true; + } + } + + return ret; +} + +/**************************************************************************** + * Name: nxrmutex_breaklock + * + * Description: + * This function attempts to break the recursive mutex + * + * Input Parameters: + * rmutex - Recursive mutex descriptor. + * + * Output Parameters: + * count - Return the count value before break. + * + * Return Value: + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure. + * Possible returned errors: + * + ****************************************************************************/ + +int nxrmutex_breaklock(FAR rmutex_t *rmutex, FAR unsigned int *count) Review Comment: could be done in libc -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org