Hi Kaspar,

Well, that has the drawback of having two mutexes per driver.  But I'll try 
that first instead, as the RIOT mutexes don't seem to keep track of who is 
holding them, only who are waiting on them.

--Pekka

> On 13.9.2018, at 12:00, Kaspar Schleiser <kas...@schleiser.de> wrote:
> 
> 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:
>  mutex_unlock(&isr_mutex);
> }
> 
> user_thread() {
>       // I guess only one user thread should interact with the device
>       mutex_lock(&driver_mutex);
> 
>       // this blocks until ISR unlocks
>       mutex_lock(&isr_mutex);
> 
>       // 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
>       mutex_unlock(&driver_mutex);
> }
>       
> Does this capture your use case?
> 
> Kaspar
>       

_______________________________________________
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel

Reply via email to