Starboard Module Reference: once.h
Stay organized with collections
Save and categorize content based on your preferences.
Onces represent initializations that should only ever happen once per process,
in a thread-safe way.
Macros
SB_ONCE_MAX_SIZE
Max size of the SbOnceControl type.
Typedefs
SbOnceControl
An opaque handle to a once control type with reserved memory buffer of size
SB_ONCE_MAX_SIZE and aligned at void pointer type.
Definition
typedef union SbOnceControl SbOnceControl
SbOnceInitRoutine
Function pointer type for methods that can be called via the SbOnce() system.
Definition
typedef void(* SbOnceInitRoutine) (void)
Functions
SbOnce
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
bool SbOnce(SbOnceControl *once_control, SbOnceInitRoutine init_routine)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-09-03 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-03 UTC."],[[["\u003cp\u003e\u003ccode\u003eSbOnce\u003c/code\u003e ensures a specific initialization routine (\u003ccode\u003einit_routine\u003c/code\u003e) is executed only once per process in a thread-safe manner.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eSbOnceControl\u003c/code\u003e is an opaque handle used by \u003ccode\u003eSbOnce\u003c/code\u003e to track whether the initialization has already occurred.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eSbOnceInitRoutine\u003c/code\u003e is a function pointer type that defines the signature of the initialization function.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eSbOnce\u003c/code\u003e function returns \u003ccode\u003etrue\u003c/code\u003e if the \u003ccode\u003einit_routine\u003c/code\u003e was executed or had already been executed, and it returns \u003ccode\u003efalse\u003c/code\u003e if the parameters provided were invalid.\u003c/p\u003e\n"]]],["The core content defines thread-safe, one-time initialization mechanisms. `SbOnceControl` is an opaque handle with a maximum size defined by `SB_ONCE_MAX_SIZE`. `SbOnceInitRoutine` is a function pointer type for initialization methods. The `SbOnce` function executes the provided `init_routine` once, ensuring thread safety. It returns `true` if the `init_routine` either ran or had already run. It returns `false` for invalid inputs.\n"],null,["Onces represent initializations that should only ever happen once per process,\nin a thread-safe way.\n\nMacros\n\nSB_ONCE_MAX_SIZE\n\nMax size of the SbOnceControl type.\n\nTypedefs\n\nSbOnceControl\n\nAn opaque handle to a once control type with reserved memory buffer of size\nSB_ONCE_MAX_SIZE and aligned at void pointer type.\n\nDefinition \n\n typedef union SbOnceControl SbOnceControl\n\nSbOnceInitRoutine\n\nFunction pointer type for methods that can be called via the SbOnce() system.\n\nDefinition \n\n typedef void(* SbOnceInitRoutine) (void)\n\nFunctions\n\nSbOnce\n\nThread-safely runs `init_routine` only once.\n\n- If this `once_control` has not run a function yet, this function runs\n `init_routine` in a thread-safe way and then returns `true`.\n\n- If SbOnce() was called with `once_control` before, the function returns\n `true` immediately.\n\n- If `once_control` or `init_routine` is invalid, the function returns\n `false`.\n\nDeclaration \n\n bool SbOnce(SbOnceControl *once_control, SbOnceInitRoutine init_routine)"]]