[riot-devel] Current best practice for sleeping in a device driver?

Kaspar Schleiser kaspar at schleiser.de
Thu Sep 13 11:00:22 CEST 2018

Hi Pekka,

On 9/13/18 10:33 AM, Nikander Pekka wrote:
> It turns out that locking the mutex twice sometimes blocks the thread.  Or at least it does that in my implementation, when running with multiple other threads.

If I understand correctly, you'd like to block a user thread until an
ISR arrives, and there might be multiple user threads, right?

// initialize mutex locked
mutex_t isr_lock = MUTEX_INITIALIZE_LOCKED;

isr() {
  // to wake thread:

user_thread() {
	// I guess only one user thread should interact with the device

	// this blocks until ISR unlocks

	// possibly disable ISR here

	... // handle ISR

	if (mutex_trylock(&isr_mutex)) {
		// mutex was unlocked since last lock
		// handle if necessary
	// posibly restore ISR here
	// release driver
Does this capture your use case?


More information about the devel mailing list