MySQL 9.0.0
Source Code Documentation
ut0todo_counter.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2024, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27#pragma once
28
29#include <cstddef>
30#include "os0event.h"
31#include "ut0dbg.h"
32
33namespace ut {
34/** A counter which tracks number of things left to do, which can be
35incremented or decremented, and lets one await the value drop to zero.
36Enforcing a total order on calls to increment(), decrement() and value() is
37a responsibility of a user of this class.
38With above assumption the await_zero() can be called safely at any moment,
39as increment() and decrement() take care of resetting and setting the awaited
40event object properly. */
42 public:
43 /** Initializes the counter to 0. */
45
46 /** Increments the value of the counter */
47 void increment() {
48 if (!m_todos++) {
50 }
51 }
52
53 /** Decrements the value of the counter */
54 void decrement() {
55 ut_a(0 < m_todos);
56 if (!--m_todos) {
58 }
59 }
60
61 /** Returns when the value is zero */
63
64 /** Returns current value of the counter */
65 size_t value() { return m_todos; }
66
67 private:
68 size_t m_todos{0};
70};
71} // namespace ut
A RAII wrapper for os_event_t.
Definition: os0event.h:139
A counter which tracks number of things left to do, which can be incremented or decremented,...
Definition: ut0todo_counter.h:41
Os_event_t m_is_zero
Definition: ut0todo_counter.h:69
Todo_counter()
Initializes the counter to 0.
Definition: ut0todo_counter.h:44
void increment()
Increments the value of the counter.
Definition: ut0todo_counter.h:47
void await_zero()
Returns when the value is zero.
Definition: ut0todo_counter.h:62
void decrement()
Decrements the value of the counter.
Definition: ut0todo_counter.h:54
size_t value()
Returns current value of the counter.
Definition: ut0todo_counter.h:65
size_t m_todos
Definition: ut0todo_counter.h:68
This file contains a set of libraries providing overloads for regular dynamic allocation routines whi...
Definition: aligned_alloc.h:48
The interface to the operating system condition variables.
void os_event_set(os_event_t event)
Sets an event semaphore to the signaled state: lets waiting threads proceed.
Definition: os0event.cc:553
static void os_event_wait(os_event_t e)
Blocking infinite wait on an event, until signalled.
Definition: os0event.h:104
int64_t os_event_reset(os_event_t event)
Resets an event semaphore to the non-signaled state.
Definition: os0event.cc:568
Debug utilities for Innobase.
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93