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