|
|
|
@ -76,77 +76,4 @@ void Semaphore::assert_owner(void)
@@ -76,77 +76,4 @@ void Semaphore::assert_owner(void)
|
|
|
|
|
osalDbgAssert(check_owner(), "owner"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// constructor
|
|
|
|
|
Semaphore_Recursive::Semaphore_Recursive() |
|
|
|
|
: Semaphore(), count(0) |
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Semaphore_Recursive::give() |
|
|
|
|
{ |
|
|
|
|
chSysLock(); |
|
|
|
|
mutex_t *mtx = (mutex_t *)_lock; |
|
|
|
|
osalDbgAssert(count>0, "recursive semaphore"); |
|
|
|
|
if (count != 0) { |
|
|
|
|
count--; |
|
|
|
|
if (count == 0) { |
|
|
|
|
// this thread is giving it up
|
|
|
|
|
chMtxUnlockS(mtx); |
|
|
|
|
// we may need to re-schedule if our priority was increased due to
|
|
|
|
|
// priority inheritance
|
|
|
|
|
chSchRescheduleS(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
chSysUnlock(); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Semaphore_Recursive::take(uint32_t timeout_ms) |
|
|
|
|
{ |
|
|
|
|
// most common case is we can get the lock immediately
|
|
|
|
|
if (Semaphore::take_nonblocking()) { |
|
|
|
|
count=1; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// check for case where we hold it already
|
|
|
|
|
chSysLock(); |
|
|
|
|
mutex_t *mtx = (mutex_t *)_lock; |
|
|
|
|
if (mtx->owner == chThdGetSelfX()) { |
|
|
|
|
count++; |
|
|
|
|
chSysUnlock(); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
chSysUnlock(); |
|
|
|
|
if (Semaphore::take(timeout_ms)) { |
|
|
|
|
count = 1; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Semaphore_Recursive::take_nonblocking(void) |
|
|
|
|
{ |
|
|
|
|
// most common case is we can get the lock immediately
|
|
|
|
|
if (Semaphore::take_nonblocking()) { |
|
|
|
|
count=1; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// check for case where we hold it already
|
|
|
|
|
chSysLock(); |
|
|
|
|
mutex_t *mtx = (mutex_t *)_lock; |
|
|
|
|
if (mtx->owner == chThdGetSelfX()) { |
|
|
|
|
count++; |
|
|
|
|
chSysUnlock(); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
chSysUnlock(); |
|
|
|
|
if (Semaphore::take_nonblocking()) { |
|
|
|
|
count = 1; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endif // CH_CFG_USE_MUTEXES
|
|
|
|
|