static void mtx5_execute(void) { bool_t b; tprio_t prio; prio = chThdGetPriority(); b = chMtxTryLock(&m1); test_assert(1, b, "already locked"); b = chMtxTryLock(&m1); test_assert(2, !b, "not locked"); chSysLock(); chMtxUnlockS(); chSysUnlock(); test_assert(3, isempty(&m1.m_queue), "queue not empty"); test_assert(4, m1.m_owner == NULL, "still owned"); test_assert(5, chThdGetPriority() == prio, "wrong priority level"); chMtxLock(&m1); chMtxUnlockAll(); test_assert(6, isempty(&m1.m_queue), "queue not empty"); test_assert(7, m1.m_owner == NULL, "still owned"); }
static void mtx5_execute(void) { #if !CH_CFG_USE_MUTEXES_RECURSIVE bool b; tprio_t prio = chThdGetPriorityX(); b = chMtxTryLock(&m1); test_assert(1, b, "already locked"); b = chMtxTryLock(&m1); test_assert(2, !b, "not locked"); chSysLock(); chMtxUnlockS(&m1); chSysUnlock(); test_assert(3, queue_isempty(&m1.m_queue), "queue not empty"); test_assert(4, m1.m_owner == NULL, "still owned"); test_assert(5, chThdGetPriorityX() == prio, "wrong priority level"); #endif /* !CH_CFG_USE_MUTEXES_RECURSIVE */ chMtxLock(&m1); chMtxUnlockAll(); test_assert(6, queue_isempty(&m1.m_queue), "queue not empty"); test_assert(7, m1.m_owner == NULL, "still owned"); }
static void test_005_005_execute(void) { bool b; tprio_t prio; /* [5.5.1] Getting current thread priority for later checks.*/ test_set_step(1); { prio = chThdGetPriorityX(); } /* [5.5.2] Locking the mutex first time, it must be possible because it is not owned.*/ test_set_step(2); { b = chMtxTryLock(&m1); test_assert(b, "already locked"); } /* [5.5.3] Locking the mutex second time, it must fail because it is already owned.*/ test_set_step(3); { b = chMtxTryLock(&m1); test_assert(!b, "not locked"); } /* [5.5.4] Unlocking the mutex then it must not be owned anymore and the queue must be empty.*/ test_set_step(4); { chMtxUnlock(&m1); test_assert(m1.owner == NULL, "still owned"); test_assert(queue_isempty(&m1.queue), "queue not empty"); } /* [5.5.5] Testing that priority has not changed after operations.*/ test_set_step(5); { test_assert(chThdGetPriorityX() == prio, "wrong priority level"); } /* [5.5.6] Testing chMtxUnlockAll() behavior.*/ test_set_step(6); { b = chMtxTryLock(&m1); test_assert(b, "already locked"); b = chMtxTryLock(&m1); test_assert(!b, "not locked"); chMtxUnlockAll(); test_assert(m1.owner == NULL, "still owned"); test_assert(queue_isempty(&m1.queue), "queue not empty"); } /* [5.5.7] Testing that priority has not changed after operations.*/ test_set_step(7); { test_assert(chThdGetPriorityX() == prio, "wrong priority level"); } }
static msg_t clarityMgmtResponseMonitoringThd(void *arg) { uint32_t attempts = 0; (void)arg; #if CH_USE_REGISTRY == TRUE chRegSetThreadName(__FUNCTION__); #endif while (chThdShouldTerminate() == FALSE) { if (chMtxTryLock(cc3000Mtx) == TRUE) { chMtxUnlock(); attempts = 0; } else { attempts++; if (attempts == CC3000_MUTEX_POLL_COUNT) { unresponsiveCb(); } } chThdSleep(MS2ST(CC3000_MUTEX_POLL_TIME_MS)); } return CLARITY_SUCCESS; }
/** * @brief Send a 'FrameStruct' type pointer via serial * @details If a sync happens the serial sending blocked by a mutex variable * and the frame which need to be sent will lost. * * @param[in] driver DataLinkLayer driver structure * @param[in] frame The frame which need to be sent * */ bool DLLSendSingleFrameSerial(DLLDriver *driver, FrameStruct *Frame){ bool IsLocked = chMtxTryLock(&driver->DLLSerialSendMutex); if(IsLocked){ sdWrite(driver->config->SDriver, Frame, FRAME_SIZE_BYTE); palTogglePad(GPIOB, GPIOB_LED1); chMtxUnlock(&driver->DLLSerialSendMutex); } return IsLocked; }
bool Mutex::tryLock(void) { return chMtxTryLock(&mutex); }
static void test_005_006_execute(void) { bool b; tprio_t prio; /* [5.6.1] Getting current thread priority for later checks.*/ test_set_step(1); { prio = chThdGetPriorityX(); } /* [5.6.2] Locking the mutex first time, it must be possible because it is not owned.*/ test_set_step(2); { b = chMtxTryLock(&m1); test_assert(b, "already locked"); } /* [5.6.3] Locking the mutex second time, it must be possible because it is recursive.*/ test_set_step(3); { b = chMtxTryLock(&m1); test_assert(b, "already locked"); } /* [5.6.4] Unlocking the mutex then it must be still owned because recursivity.*/ test_set_step(4); { chMtxUnlock(&m1); test_assert(m1.owner != NULL, "not owned"); } /* [5.6.5] Unlocking the mutex then it must not be owned anymore and the queue must be empty.*/ test_set_step(5); { chMtxUnlock(&m1); test_assert(m1.owner == NULL, "still owned"); test_assert(queue_isempty(&m1.queue), "queue not empty"); } /* [5.6.6] Testing that priority has not changed after operations.*/ test_set_step(6); { test_assert(chThdGetPriorityX() == prio, "wrong priority level"); } /* [5.6.7] Testing consecutive chMtxTryLock()/chMtxTryLockS() calls and a final chMtxUnlockAllS().*/ test_set_step(7); { b = chMtxTryLock(&m1); test_assert(b, "already locked"); chSysLock(); b = chMtxTryLockS(&m1); chSysUnlock(); test_assert(b, "already locked"); test_assert(m1.cnt == 2, "invalid recursion counter"); chSysLock(); chMtxUnlockAllS(); chSysUnlock(); test_assert(m1.owner == NULL, "still owned"); test_assert(queue_isempty(&m1.queue), "queue not empty"); test_assert(m1.cnt == 0, "invalid recursion counter"); } /* [5.6.8] Testing consecutive chMtxLock()/chMtxLockS() calls and a final chMtxUnlockAll().*/ test_set_step(8); { chMtxLock(&m1); test_assert(m1.owner != NULL, "not owned"); chSysLock(); chMtxLockS(&m1); chSysUnlock(); test_assert(m1.owner != NULL, "not owned"); test_assert(m1.cnt == 2, "invalid recursion counter"); chMtxUnlockAll(); test_assert(m1.owner == NULL, "still owned"); test_assert(queue_isempty(&m1.queue), "queue not empty"); test_assert(m1.cnt == 0, "invalid recursion counter"); } /* [5.6.9] Testing that priority has not changed after operations.*/ test_set_step(9); { test_assert(chThdGetPriorityX() == prio, "wrong priority level"); } }