| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2006, 2026, Oracle and/or its affiliates. |
| 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, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work 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 either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
/** @file include/ut0wqueue.h |
| 29 |
A work queue |
| 30 |
|
| 31 |
Created 4/26/2006 Osku Salerma |
| 32 |
************************************************************************/ |
| 33 |
|
| 34 |
/** A Work queue. Threads can add work items to the queue and other threads can |
| 35 |
wait for work items to be available and take them off the queue for |
| 36 |
processing. |
| 37 |
************************************************************************/ |
| 38 |
|
| 39 |
#ifndef IB_WORK_QUEUE_H |
| 40 |
#define IB_WORK_QUEUE_H |
| 41 |
|
| 42 |
#include "mem0mem.h" |
| 43 |
#include "sync0sync.h" |
| 44 |
#include "ut0list.h" |
| 45 |
|
| 46 |
// Forward declaration |
| 47 |
struct ib_list_t; |
| 48 |
struct ib_wqueue_t; |
| 49 |
|
| 50 |
/** Create a new work queue. |
| 51 |
@return work queue */ |
| 52 |
ib_wqueue_t *ib_wqueue_create(); |
| 53 |
|
| 54 |
/** Free a work queue. */ |
| 55 |
void ib_wqueue_free(ib_wqueue_t *wq); /*!< in: work queue */ |
| 56 |
|
| 57 |
/** Add a work item to the queue. |
| 58 |
@param[in] wq Work queue |
| 59 |
@param[in] item Work item |
| 60 |
@param[in] heap Memory heap to use for allocating the list node */ |
| 61 |
void ib_wqueue_add(ib_wqueue_t *wq, void *item, mem_heap_t *heap); |
| 62 |
|
| 63 |
/** read total number of work item to the queue. |
| 64 |
@param[in] wq Work queue |
| 65 |
@return total count of work item in the queue */ |
| 66 |
uint64_t ib_wqueue_get_count(ib_wqueue_t *wq); |
| 67 |
|
| 68 |
/******************************************************************** |
| 69 |
Check if queue is empty. */ |
| 70 |
bool ib_wqueue_is_empty( |
| 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 for specified time. */ |
| 77 |
void *ib_wqueue_timedwait( |
| 78 |
/* out: work item or NULL on timeout*/ |
| 79 |
ib_wqueue_t *wq, /* in: work queue */ |
| 80 |
std::chrono::microseconds wait); /* in: wait time */ |
| 81 |
|
| 82 |
#endif /* IB_WORK_QUEUE_H */ |