Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions sys/include/xtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,6 @@ static inline bool xtimer_less64(xtimer_ticks64_t a, xtimer_ticks64_t b);
/**
* @brief lock a mutex but with timeout
*
* @note this requires core_thread_flags to be enabled
*
* @param[in] mutex mutex to lock
* @param[in] us timeout in microseconds relative
*
Expand Down
24 changes: 20 additions & 4 deletions sys/xtimer/xtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,32 @@ int _xtimer_msg_receive_timeout(msg_t *msg, uint32_t timeout_ticks)

static void _mutex_timeout(void *arg)
{
/* interupts a disabled because xtimer can spin
* if xtimer_set spins the callback is executed
* in the thread context
*
* If the xtimer spin is fixed in the future
* interups disable/restore can be removed
*/
unsigned irqstate = irq_disable();

mutex_thread_t *mt = (mutex_thread_t *)arg;

mt->timeout = 1;
list_node_t *node = list_remove(&mt->mutex->queue,
(list_node_t *)&mt->thread->rq_entry);
if ((node != NULL) && (mt->mutex->queue.next == NULL)) {
mt->mutex->queue.next = MUTEX_LOCKED;

/* if thread was removed from the list */
if (node != NULL) {
if (mt->mutex->queue.next == NULL) {
mt->mutex->queue.next = MUTEX_LOCKED;
}
sched_set_status(mt->thread, STATUS_PENDING);
irq_restore(irqstate);
sched_switch(mt->thread->priority);
return;
}
sched_set_status(mt->thread, STATUS_PENDING);
thread_yield_higher();
irq_restore(irqstate);
}

int xtimer_mutex_lock_timeout(mutex_t *mutex, uint64_t timeout)
Expand Down