sys: add mutex lock with timeout function#6158
Conversation
baaaf55 to
94c15e1
Compare
core/include/thread.h
Outdated
| * @brief Remove thread from list (internal) | ||
| * | ||
| * This will remove @p thread from @p list. It reuses the thread's rq_entry | ||
| * field. Used internally timeout mutex implementation. |
There was a problem hiding this comment.
Can you directly reference the function here?
Used internally by @ref xtimer_mutex_lock_timeout() "timeout mutex implementation".
core/include/thread.h
Outdated
| void thread_add_to_list(list_node_t *list, thread_t *thread); | ||
|
|
||
| /** | ||
| * @brief Remove thread from list (internal) |
There was a problem hiding this comment.
thread_add_to_list is not @internal. Should I update both?
|
@BytesGalore, didn't we have a discussion about this feature some years before? |
|
What was the outcome of the discussion @OlegHahm ? :-) |
|
I see... I don't have such a deep overview of the Also, I've to see if I've to rebase to accommodate the latest changes in the xtimer. |
No, @BytesGalore, can you elaborate? |
|
What is holding this back? I'd be nice to have this and #6155 merged for the next release |
core/thread.c
Outdated
| list->next = new_node; | ||
| } | ||
|
|
||
| void thread_remove_from_list(list_node_t *list, thread_t *thread) |
There was a problem hiding this comment.
Why not use clist_remove()?
There was a problem hiding this comment.
I didn't consider it because: the list is not a circular list and because when added is using a thread_add_to_list which is in the thread module (I assume that this is done this way to lower inter-dependencies).
There was a problem hiding this comment.
Alternatively: why not add a list_remove() implementation? Seems a lot cleaner.
There was a problem hiding this comment.
thread_add_to_list() is taking the thread's priority into account and adds the thread so afterwards the list is sorted by priority.
+1 for adding "list_remove()" to list.h! and using that!
There was a problem hiding this comment.
adding "list_remove()" to list.h
It's probably best to do that in a seperate PR.
There was a problem hiding this comment.
Agree! Will do :-) now we'll have a PR which depends in this PR which depends in another PR, yeeey 🎉
There was a problem hiding this comment.
Agree! Will do :-) now we'll have a PR which depends in this PR which depends in another PR, yeeey 🎉
Welcome to RIOT ;-P
sys/xtimer/xtimer.c
Outdated
|
|
||
| static void _mutex_timeout(void *arg) | ||
| { | ||
| unsigned irqstate = irq_disable(); |
There was a problem hiding this comment.
This is run in ISR context, so no need for disabling IRQs.
There was a problem hiding this comment.
You do need, otherwise you might run in a race condition in case an interrupt occurs while serving this interrupt. Imagine: an that the other interrupt occurs while removing the mutex from the queue and that interrupt does the same operation (i.e. by calling mutex_unlock).
There was a problem hiding this comment.
@lebrush RIOT currently doesn't allow nested interrupts, so while one ISR is running, no other will interrupt.
There was a problem hiding this comment.
Again what learnt ;-) Will fix
sys/xtimer/xtimer.c
Outdated
| { | ||
| msg_t tmsg; | ||
| xtimer_t t; | ||
|
|
| typedef struct { | ||
| mutex_t *mutex; | ||
| thread_t *thread; | ||
| int timeout; |
There was a problem hiding this comment.
When the mutex times out, this flag is set in order to indicate whether it timed out or not (see L257).
There was a problem hiding this comment.
(after rebase, is line 255)
561de3f to
f6b9cb1
Compare
|
@kaspar030 rebased onto latest master and squashed changes |
bc5cfd0 to
6e33b59
Compare
|
@kaspar030 ping? |
6e33b59 to
17d6d2a
Compare
|
#6211 got merged |
|
Rebased. @kaspar030 any other change requested? |
|
ACK. |
|
Can anyone trigger Murdock again, please? |
This implements mutex locking with a timeout, which is required for the semaphore implementation without IPC (#6155).
It's been split into a separate PR as suggested by @miri64
Depends on: #6211
Required by: #6155