[riot-notifications] [RIOT-OS/RIOT] core/mutex: Add mutex_cancel (#15442)
benpicco
notifications at github.com
Wed Nov 18 00:27:56 CET 2020
@benpicco commented on this pull request.
looks good to me.
Please squash, having this separated into logical commits will make the changes clearer - I think we might merge this without splitting, as the changes to `mutex_lock()` are just moving code into a helper function.
> + thread_getpid());
+ irq_restore(irq_state);
+ }
+ else {
+ _block(mutex, irq_state);
+ }
+}
+
+int mutex_lock_cancelable(mutex_cancel_t *mc)
+{
+ unsigned irq_state = irq_disable();
+
+ DEBUG("PID[%" PRIkernel_pid "]: mutex_lock_cancelable()\n",
+ thread_getpid());
+
+ if (mc->cancelled) {
```suggestion
if (mc->cancelled) {
mc->cancelled = 0;
```
so we can re-use the mutex and cancel it again
> + irq_restore(irq_state);
+ return -ECANCELED;
+ }
+
+ mutex_t *mutex = mc->mutex;
+ if (mutex->queue.next == NULL) {
+ /* mutex is unlocked. */
+ mutex->queue.next = MUTEX_LOCKED;
+ DEBUG("PID[%" PRIkernel_pid "]: mutex_lock_cancelable() early out.\n",
+ thread_getpid());
+ irq_restore(irq_state);
+ return 0;
+ }
+ else {
+ _block(mutex, irq_state);
+ if (mc->cancelled) {
same here
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/15442#pullrequestreview-532895525
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20201117/365666dc/attachment.htm>
More information about the notifications
mailing list