1 /***************************************************************************** 2 3 Copyright (c) 2006, 2009, Oracle and/or its affiliates. All Rights Reserved. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed with certain software (including 10 but not limited to OpenSSL) that is licensed under separate terms, 11 as designated in a particular file or component or in included license 12 documentation. The authors of MySQL hereby grant you an additional 13 permission to link the program and your derivative works with the 14 separately licensed software that they have included with MySQL. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License, version 2.0, for more details. 20 21 You should have received a copy of the GNU General Public License along with 22 this program; if not, write to the Free Software Foundation, Inc., 23 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA 24 25 *****************************************************************************/ 26 27 /*******************************************************************//** 28 @file include/ut0wqueue.h 29 A work queue 30 31 Created 4/26/2006 Osku Salerma 32 ************************************************************************/ 33 34 /*******************************************************************//** 35 A Work queue. Threads can add work items to the queue and other threads can 36 wait for work items to be available and take them off the queue for 37 processing. 38 ************************************************************************/ 39 40 #ifndef IB_WORK_QUEUE_H 41 #define IB_WORK_QUEUE_H 42 43 #include "ut0list.h" 44 #include "mem0mem.h" 45 #include "os0sync.h" 46 #include "sync0types.h" 47 48 struct ib_wqueue_t; 49 50 /****************************************************************//** 51 Create a new work queue. 52 @return work queue */ 53 UNIV_INTERN 54 ib_wqueue_t* 55 ib_wqueue_create(void); 56 /*===================*/ 57 58 /****************************************************************//** 59 Free a work queue. */ 60 UNIV_INTERN 61 void 62 ib_wqueue_free( 63 /*===========*/ 64 ib_wqueue_t* wq); /*!< in: work queue */ 65 66 /****************************************************************//** 67 Add a work item to the queue. */ 68 UNIV_INTERN 69 void 70 ib_wqueue_add( 71 /*==========*/ 72 ib_wqueue_t* wq, /*!< in: work queue */ 73 void* item, /*!< in: work item */ 74 mem_heap_t* heap); /*!< in: memory heap to use for allocating the 75 list node */ 76 77 /******************************************************************** 78 Check if queue is empty. */ 79 80 ibool 81 ib_wqueue_is_empty( 82 /*===============*/ 83 /* out: TRUE if queue empty 84 else FALSE */ 85 const ib_wqueue_t* wq); /* in: work queue */ 86 87 /****************************************************************//** 88 Wait for a work item to appear in the queue. 89 @return work item */ 90 UNIV_INTERN 91 void* 92 ib_wqueue_wait( 93 /*===========*/ 94 ib_wqueue_t* wq); /*!< in: work queue */ 95 96 /******************************************************************** 97 Wait for a work item to appear in the queue for specified time. */ 98 99 void* 100 ib_wqueue_timedwait( 101 /*================*/ 102 /* out: work item or NULL on timeout*/ 103 ib_wqueue_t* wq, /* in: work queue */ 104 ib_time_t wait_in_usecs); /* in: wait time in micro seconds */ 105 106 /* Work queue. */ 107 struct ib_wqueue_t { 108 ib_mutex_t mutex; /*!< mutex protecting everything */ 109 ib_list_t* items; /*!< work item list */ 110 os_event_t event; /*!< event we use to signal additions to list */ 111 }; 112 113 #endif 114