void bqueue_dequeue_wait(bounded_queue_t q, void **data, sched_task_t stask) { for (int i = 0; i < 32; i++) { if(queue_impl_dequeue(q->impl, data)) { task_mutex_lock(q->not_full_mutex, stask); task_condition_signal_all(q->not_full, stask); task_mutex_unlock(q->not_full_mutex, stask); return; } } if (!queue_impl_dequeue(q->impl, data)) { task_mutex_lock(q->not_empty_mutex, stask); while (!queue_impl_dequeue(q->impl, data)) { DEBUG_LOG(2, "%p waiting to dequeue in %p\n", stask, q); task_condition_wait(q->not_empty, q->not_empty_mutex, stask); } /* task_condition_signal(q->not_empty); */ task_mutex_unlock(q->not_empty_mutex, stask); } DEBUG_LOG(2, "%p bounded queue notifying not full %p\n", stask, q); task_mutex_lock(q->not_full_mutex, stask); task_condition_signal_all(q->not_full, stask); task_mutex_unlock(q->not_full_mutex, stask); }
void unlock_pool(void) { #ifdef ZEPHYR_MICRO_OS_ABSTRACTION_USE_SINGLE_POOL_LOCK #ifdef CONFIG_NANOKERNEL _PoolUnlock(); #else task_mutex_unlock(MTX_POOL_GENERIC); #endif #else #ifdef CONFIG_NANOKERNEL nano_fiber_sem_give (&QueuePoolLockSem) ; #else task_mutex_unlock(MTX_POOL_QUEUE); #endif #endif }
void proc_wait_for_available(processor_t proc, processor_t client) { task_mutex_lock(proc->mutex, &client->stask); proc->last_waiter = client; while (proc->last_waiter == client) { task_condition_wait(proc->cv, proc->mutex, &client->stask); } task_mutex_unlock(proc->mutex, &client->stask); }
void mutex_task(void* data) { sched_task_t stask = (sched_task_t) data; for (int i = 0; i < NUM_ITERS; i++) { task_mutex_lock(mutex, stask); finished++; task_mutex_unlock(mutex, stask); } }
void worker_task(sched_task_t stask, int flag) { for (int i = 0; i < NUM_ITERS; i++) { task_mutex_lock(mutex, stask); while (finished % 2 == flag) { task_condition_wait(cv, mutex, stask); } finished++; task_condition_signal_all(cv, stask); task_mutex_unlock(mutex, stask); } }
void Task50(void) { int rv; /* Wait for private mutex to be released */ rv = task_mutex_lock(private_mutex, TICKS_UNLIMITED); if (rv != RC_OK) { tcRC = TC_FAIL; TC_ERROR("Failed to obtain private mutex\n"); return; } /* Wait a bit, then release the mutex */ task_sleep(HALF_SECOND); task_mutex_unlock(private_mutex); } /* Task50 */
static void notify_available(processor_t proc) { // If we're processing a wait condition, then we don't want to // notify any other threads that this processor is available, // because here availability means: // // This processor might have undergone a state change so // check your wait-condition again. // // This is designed to prevent wait conditions from waking up other // wait conditions. /* if (!proc->processing_wait) */ /* { */ task_mutex_lock(proc->mutex, &proc->stask); proc->last_waiter = NULL; task_condition_signal_all(proc->cv, &proc->stask); task_mutex_unlock(proc->mutex, &proc->stask); /* } */ /* proc->processing_wait = false; */ }