Lock acquisition order:
More...
#include "global.h"
#include "threadqueue.h"
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "threads.h"
- When locking a job and its dependency, the dependecy must be locked first and then the job depending on it.
- When locking a job and the thread queue, the thread queue must be locked first and then the job.
- When accessing threadqueue_job_t.next, the thread queue must be locked.
◆ PTHREAD_COND_BROADCAST
#define PTHREAD_COND_BROADCAST |
( |
| c | ) |
|
Value: if (pthread_cond_broadcast((c)) != 0) { \
fprintf(stderr, "pthread_cond_broadcast(%s=%p) failed!\n", #c, c); \
assert(0); \
return 0; \
}
◆ PTHREAD_COND_SIGNAL
#define PTHREAD_COND_SIGNAL |
( |
| c | ) |
|
Value: if (pthread_cond_signal((c)) != 0) { \
fprintf(stderr, "pthread_cond_signal(%s=%p) failed!\n", #c, c); \
assert(0); \
return 0; \
}
◆ PTHREAD_COND_WAIT
#define PTHREAD_COND_WAIT |
( |
| c, |
|
|
| l ) |
Value: if (pthread_cond_wait((c),(l)) != 0) { \
fprintf(stderr, "pthread_cond_wait(%s=%p, %s=%p) failed!\n", #c, c, #l, l); \
assert(0); \
return 0; \
}
◆ PTHREAD_LOCK
#define PTHREAD_LOCK |
( |
| l | ) |
|
Value: if (pthread_mutex_lock((l)) != 0) { \
fprintf(stderr, "pthread_mutex_lock(%s) failed!\n", #l); \
assert(0); \
return 0; \
}
◆ PTHREAD_UNLOCK
#define PTHREAD_UNLOCK |
( |
| l | ) |
|
Value: if (pthread_mutex_unlock((l)) != 0) { \
fprintf(stderr, "pthread_mutex_unlock(%s) failed!\n", #l); \
assert(0); \
return 0; \
}
◆ THREADQUEUE_LIST_REALLOC_SIZE
#define THREADQUEUE_LIST_REALLOC_SIZE 32 |
◆ threadqueue_job_state
Enumerator |
---|
THREADQUEUE_JOB_STATE_PAUSED | Job has been submitted, but is not allowed to run yet.
|
THREADQUEUE_JOB_STATE_WAITING | Job is waiting for dependencies.
|
THREADQUEUE_JOB_STATE_READY | Job is ready to run.
|
THREADQUEUE_JOB_STATE_RUNNING | Job is running.
|
THREADQUEUE_JOB_STATE_DONE | Job is completed.
|
◆ kvz_threadqueue_copy_ref()
Increment reference count and return the job.
◆ kvz_threadqueue_free()
- Returns
- 1 on success, 0 on failure
◆ kvz_threadqueue_free_job()
Decrement reference count of the job. If no references exist any more, deallocate associated memory and destroy mutexes.
Sets the job pointer to NULL.
◆ kvz_threadqueue_init()
- Returns
- 1 on success, 0 on failure
◆ kvz_threadqueue_job_create()
threadqueue_job_t * kvz_threadqueue_job_create |
( |
void(* | fptr )(void *arg), |
|
|
void * | arg ) |
The job is created in a paused state. Function kvz_threadqueue_submit must be called on the job in order to have it run.
- Returns
- pointer to the job, or NULL on failure
◆ kvz_threadqueue_job_dep_add()
- Parameters
-
job | job that should be executed after dependency |
dependency | job that should be executed before job |
- Returns
- 1 on success, 0 on failure
◆ kvz_threadqueue_stop()
Block until all threads have stopped.
- Returns
- 1 on success, 0 on failure
◆ kvz_threadqueue_submit()
◆ kvz_threadqueue_waitfor()
- Returns
- 1 on success, 0 on failure
◆ threadqueue_pop_job()
The caller must have locked the thread queue. The calling function receives the ownership of the job.
◆ threadqueue_push_job()
The caller must have locked the thread queue and the job. This function takes the ownership of the job.
◆ threadqueue_worker()
static void * threadqueue_worker |
( |
void * | threadqueue_opaque | ) |
|
|
static |