| 1 | /* Copyright (C) 2007 L. Donnie Smith <cwiid@abstrakraft.org> |
|---|
| 2 | * |
|---|
| 3 | * This program is free software; you can redistribute it and/or modify |
|---|
| 4 | * it under the terms of the GNU General Public License as published by |
|---|
| 5 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 6 | * (at your option) any later version. |
|---|
| 7 | * |
|---|
| 8 | * This program is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * GNU General Public License for more details. |
|---|
| 12 | * |
|---|
| 13 | * You should have received a copy of the GNU General Public License |
|---|
| 14 | * along with this program; if not, write to the Free Software |
|---|
| 15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 16 | * |
|---|
| 17 | * ChangeLog: |
|---|
| 18 | * 2007-04-04 L. Donnie Smith >cwiid@abstrakraft.org> |
|---|
| 19 | * * Added queue_flush prototype |
|---|
| 20 | * |
|---|
| 21 | * 2007-03-03 L. Donnie Smith <cwiid@abstrakraft.org> |
|---|
| 22 | * * Initial ChangeLog |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | #ifndef QUEUE_H |
|---|
| 26 | #define QUEUE_H |
|---|
| 27 | |
|---|
| 28 | #include <pthread.h> |
|---|
| 29 | |
|---|
| 30 | typedef void free_func_t(void *); |
|---|
| 31 | |
|---|
| 32 | struct queue_node { |
|---|
| 33 | void *data; |
|---|
| 34 | struct queue_node *next; |
|---|
| 35 | }; |
|---|
| 36 | |
|---|
| 37 | struct queue { |
|---|
| 38 | pthread_mutex_t mutex; |
|---|
| 39 | pthread_cond_t cond; |
|---|
| 40 | pthread_mutex_t cond_mutex; |
|---|
| 41 | struct queue_node *head; |
|---|
| 42 | struct queue_node **p_tail; |
|---|
| 43 | }; |
|---|
| 44 | |
|---|
| 45 | struct queue *queue_new(); |
|---|
| 46 | int queue_flush(struct queue *queue, free_func_t free_func); |
|---|
| 47 | int queue_free(struct queue *queue, free_func_t free_func); |
|---|
| 48 | int queue_queue(struct queue *queue, void *data); |
|---|
| 49 | int queue_dequeue(struct queue *queue, void **data); |
|---|
| 50 | int queue_wait(struct queue *queue); |
|---|
| 51 | |
|---|
| 52 | #endif |
|---|