😄
This commit is contained in:
@@ -31,6 +31,7 @@ int job_queue_destroy(struct job_queue *job_queue) {
|
||||
pthread_mutex_lock(&queue_operation);
|
||||
|
||||
free(job_queue->jobs);
|
||||
job_queue->jobs = NULL;
|
||||
|
||||
pthread_mutex_unlock(&queue_push);
|
||||
pthread_mutex_unlock(&queue_pop);
|
||||
@@ -42,6 +43,7 @@ int job_queue_destroy(struct job_queue *job_queue) {
|
||||
int job_queue_push(struct job_queue *job_queue, void *data) {
|
||||
pthread_mutex_lock(&queue_push);
|
||||
pthread_mutex_lock(&queue_operation);
|
||||
//printf("push start\n");
|
||||
|
||||
job_queue->jobs[job_queue->size] = data;
|
||||
job_queue->size = job_queue->size + 1;
|
||||
@@ -52,9 +54,10 @@ int job_queue_push(struct job_queue *job_queue, void *data) {
|
||||
|
||||
if (job_queue->size == 1) {
|
||||
pthread_mutex_unlock(&queue_pop);
|
||||
pthread_mutex_lock(&queue_destroy);
|
||||
pthread_mutex_trylock(&queue_destroy);
|
||||
}
|
||||
|
||||
//printf("push end\n");
|
||||
pthread_mutex_unlock(&queue_operation);
|
||||
return 0;
|
||||
}
|
||||
@@ -62,12 +65,15 @@ int job_queue_push(struct job_queue *job_queue, void *data) {
|
||||
int job_queue_pop(struct job_queue *job_queue, void **data) {
|
||||
pthread_mutex_lock(&queue_pop);
|
||||
pthread_mutex_lock(&queue_operation);
|
||||
//printf("pop start\n");
|
||||
|
||||
if (job_queue == NULL) {
|
||||
if (job_queue->jobs == NULL) {
|
||||
//printf("no more job queue\n");
|
||||
pthread_mutex_unlock(&queue_pop);
|
||||
pthread_mutex_unlock(&queue_operation);
|
||||
return -1;
|
||||
}
|
||||
//printf("job queue\n");
|
||||
|
||||
job_queue->size = job_queue->size - 1;
|
||||
*data = job_queue->jobs[job_queue->size];
|
||||
@@ -84,6 +90,7 @@ int job_queue_pop(struct job_queue *job_queue, void **data) {
|
||||
pthread_mutex_unlock(&queue_pop);
|
||||
}
|
||||
|
||||
//printf("pop end\n");
|
||||
pthread_mutex_unlock(&queue_operation);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user