コード例 #1
0
ファイル: workq.c プロジェクト: calvinwylie/lecture
/*
 * Add work to the queue
 * TODO: This needs synchronization!
 */
void workq_put(workq_t* workq, void* data)
{
    task_t* task = (task_t*) malloc(sizeof(task_t));
    task->data = data;
    workq_lock(workq);
    task->next = workq->tasks;
    workq->tasks = task;
    workq_signal(workq);
    workq_unlock(workq);
}
コード例 #2
0
ファイル: workq.c プロジェクト: yalcinozhabes/lecture
/*
 * Get a data item from the queue.  We assume NULL data can be used
 * to signal that the queue is empty.
 * TODO: This needs synchronization!
 */
void* workq_get(workq_t* workq)
{
    void* result = NULL;
    workq_lock(workq);
    workq_wait(workq);
    if (workq->tasks) {
        task_t* task = workq->tasks;
        result = task->data;
        workq->tasks = task->next;
        free(task);
    }
    workq_signal(workq);
    workq_unlock(workq);
    return result;
}