1 /* Copyright (c) 2010, RWTH Aachen University 2 * All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or 5 * without modification, are permitted provided that the following 6 * conditions are met: 7 * * Redistributions of source code must retain the above 8 * copyright notice, this list of conditions and the following 9 * disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following 12 * disclaimer in the documentation and/or other materials 13 * provided with the distribution. 14 * * Neither the name of the RWTH Aachen University nor the 15 * names of its contributors may be used to endorse or promote 16 * products derived from this software without specific prior 17 * written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RWTH 23 * AACHEN UNIVERSITY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * Coded by Matthias Petschow (petschow@aices.rwth-aachen.de), 33 * August 2010, Version 0.6 34 * 35 * This code was the result of a collaboration between 36 * Matthias Petschow and Paolo Bientinesi. When you use this 37 * code, kindly reference a paper related to this work. 38 * 39 */ 40 41 #ifndef QQUEUE_H 42 #define QQUEUE_H 43 44 #include <pthread.h> 45 #include "global.h" 46 47 typedef struct task_aux task_t; 48 struct task_aux { 49 void *data; /* ptr to data, has to be casted */ 50 int flag; /* flag specifying the task */ 51 task_t *next; /* ptr to next task; NULL if non-existing; */ 52 task_t *prev; /* ptr to prev. task; NULL if non-existing; */ 53 }; 54 55 typedef struct { 56 int num_tasks; 57 task_t *head; 58 task_t *back; 59 #ifdef NOSPINLOCKS 60 pthread_mutex_t lock; 61 #else 62 pthread_spinlock_t lock; 63 #endif 64 } queue_t; 65 66 67 /* functionality of the queue */ 68 queue_t *PMR_create_empty_queue (void); 69 int PMR_insert_task_at_front (queue_t *queue, task_t *task); 70 int PMR_insert_task_at_back (queue_t *queue, task_t *task); 71 task_t *PMR_remove_task_at_front(queue_t *queue); 72 task_t *PMR_remove_task_at_back (queue_t *queue); 73 int PMR_get_num_tasks(queue_t *queue); 74 void PMR_destroy_queue(queue_t *queue); 75 76 #endif 77