mdcore
0.1.5
|
00001 /******************************************************************************* 00002 * This file is part of mdcore. 00003 * Coypright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk) 00004 * 00005 * This program is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as published 00007 * by the Free Software Foundation, either version 3 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 * 00018 ******************************************************************************/ 00019 00020 /* fifo error codes */ 00021 #define fifo_err_ok 0 00022 #define fifo_err_null -1 00023 #define fifo_err_malloc -2 00024 #define fifo_err_pthread -3 00025 #define fifo_err_fifo_full -4 00026 #define fifo_err_fifo_empty -5 00027 00028 00029 /* the last error */ 00030 extern int fifo_err; 00031 00032 00033 /* The fifo-queue for dispatching. */ 00034 struct fifo { 00035 00036 /* Access mutex and condition signal for blocking use. */ 00037 pthread_mutex_t mutex; 00038 pthread_cond_t cond; 00039 00040 /* Counters. */ 00041 int first, last, size, count; 00042 00043 /* The FIFO data. */ 00044 int *data; 00045 00046 }; 00047 00048 00049 /* associated functions */ 00050 int fifo_init ( struct fifo *f , int size ); 00051 int fifo_pop_nb ( struct fifo *f , int *e ); 00052 int fifo_pop ( struct fifo *f , int *e ); 00053 int fifo_push_nb ( struct fifo *f , int e ); 00054 int fifo_push ( struct fifo *f , int e );