InnoDB Plugin  1.0
Public Types | Static Public Attributes
os_once Class Reference

#include <os0once.h>

Public Types

typedef ib_uint32_t state_t

Static Public Attributes

static const state_t NEVER_DONE = 0
static const state_t IN_PROGRESS = 1
static const state_t DONE = 2

Detailed Description

Execute a given function exactly once in a multi-threaded environment

or wait for the function to be executed by another thread.

Example usage: First the user must create a control variable of type os_once::state_t and assign it os_once::NEVER_DONE. Then the user must pass this variable, together with a function to be executed to os_once::do_or_wait_for_done().

Multiple threads can call os_once::do_or_wait_for_done() simultaneously with the same (os_once::state_t) control variable. The provided function will be called exactly once and when os_once::do_or_wait_for_done() returns then this function has completed execution, by this or another thread. In other words os_once::do_or_wait_for_done() will either execute the provided function or will wait for its execution to complete if it is already called by another thread or will do nothing if the function has already completed its execution earlier.

This mimics pthread_once(3), but unfortunatelly pthread_once(3) does not support passing arguments to the init_routine() function. We should use std::call_once() when we start compiling with C++11 enabled.

Member Typedef Documentation

typedef ib_uint32_t os_once::state_t

Control variables' state type

Field Documentation

const state_t os_once::DONE = 2
static

Finished execution.

const state_t os_once::IN_PROGRESS = 1
static

Currently being executed by this or another thread.

const state_t os_once::NEVER_DONE = 0
static

Not yet executed.


The documentation for this class was generated from the following file: