diff options
Diffstat (limited to 'nuttx/lib')
-rw-r--r-- | nuttx/lib/lib_init.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/nuttx/lib/lib_init.c b/nuttx/lib/lib_init.c index d6eb5f0a4..0527f921b 100644 --- a/nuttx/lib/lib_init.c +++ b/nuttx/lib/lib_init.c @@ -145,11 +145,17 @@ void lib_addreflist(FAR struct streamlist *list) { if (list) { - /* Increment the reference count on the list */ + /* Increment the reference count on the list. + * NOTE: that we disable interrupts to do this + * (vs. taking the list semaphore). We do this + * because file cleanup operations often must be + * done from the IDLE task which cannot wait + * on semaphores. + */ - _lib_semtake(list); + register irqstate_t flags = irqsave(); list->sl_crefs++; - _lib_semgive(list); + irqrestore(flags); } } @@ -163,14 +169,22 @@ void lib_releaselist(FAR struct streamlist *list) int crefs; if (list) { - /* Decrement the reference count */ + /* Decrement the reference count on the list. + * NOTE: that we disable interrupts to do this + * (vs. taking the list semaphore). We do this + * because file cleanup operations often must be + * done from the IDLE task which cannot wait + * on semaphores. + */ - _lib_semtake(list); + register irqstate_t flags = irqsave(); crefs = --(list->sl_crefs); - _lib_semgive(list); + irqrestore(flags); /* If the count decrements to zero, then there is no reference - * to the structure and it should be deallocated. + * to the structure and it should be deallocated. Since there + * are references, it would be an error if any task still held + * a reference to the list's semaphore. */ if (crefs <= 0) |