Starboard Module Reference: once.h

Onces represent initializations that should only ever happen once per process, in a thread-safe way.

Macros

SB_ONCE_INITIALIZE_FUNCTION

Defines a function that will initialize the indicated type once and return it. This initialization is thread safe if the type being created is side effect free.
These macros CAN ONLY BE USED IN A CC file, never in a header file.
Example (in cc file): SB_ONCE_INITIALIZE_FUNCTION(MyClass, GetOrCreateMyClass) .. MyClass* instance = GetOrCreateMyClass(); MyClass* instance2 = GetOrCreateMyClass(); DCHECK_EQ(instance, instance2);

Functions

SbOnce

Description

Thread-safely runs init_routine only once.

  • If this once_control has not run a function yet, this function runs init_routine in a thread-safe way and then returns true.
  • If SbOnce() was called with once_control before, the function returns true immediately.
  • If once_control or init_routine is invalid, the function returns false.

Declaration and definitions

SB_EXPORT bool SbOnce(SbOnceControl* once_control,
                      SbOnceInitRoutine init_routine);

#include "starboard/once.h"

bool SbOnce(SbOnceControl* /*once_control*/,
            SbOnceInitRoutine /*init_routine*/) {
  return false;
}

Parameters

Parameters
SbOnceControl*
once_control
SbOnceInitRoutine
init_routine