Beispiel #1
0
int os_init(int (*init_once)(void)) {
    int err;
#if defined(GENESIS_OS_WINDOWS)
    PVOID lpContext;
    BOOL pending;

    if (!InitOnceBeginInitialize(&win32_init_once, INIT_ONCE_ASYNC, &pending, &lpContext))
        return GenesisErrorSystemResources;

    if (!pending)
        return 0;

    if ((err = internal_init(init_once)))
        return err;

    if (!InitOnceComplete(&win32_init_once, INIT_ONCE_ASYNC, nullptr))
        return GenesisErrorSystemResources;
#else
    assert_no_err(pthread_mutex_lock(&init_mutex));
    if (initialized) {
        assert_no_err(pthread_mutex_unlock(&init_mutex));
        return 0;
    }
    initialized = true;
    if ((err = internal_init(init_once)))
        return err;
    assert_no_err(pthread_mutex_unlock(&init_mutex));
#endif

    return 0;
}
Beispiel #2
0
int soundio_os_init(void) {
    int err;
#if defined(SOUNDIO_OS_WINDOWS)
    PVOID lpContext;
    BOOL pending;

    if (!InitOnceBeginInitialize(&win32_init_once, INIT_ONCE_ASYNC, &pending, &lpContext))
        return SoundIoErrorSystemResources;

    if (!pending)
        return 0;

    if ((err = internal_init()))
        return err;

    if (!InitOnceComplete(&win32_init_once, INIT_ONCE_ASYNC, NULL))
        return SoundIoErrorSystemResources;
#else
    assert_no_err(pthread_mutex_lock(&init_mutex));
    if (initialized) {
        assert_no_err(pthread_mutex_unlock(&init_mutex));
        return 0;
    }
    initialized = true;
    if ((err = internal_init()))
        return err;
    assert_no_err(pthread_mutex_unlock(&init_mutex));
#endif

    return 0;
}
Beispiel #3
0
int pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
{
    BOOL pending;
    if (!InitOnceBeginInitialize(once_control, 0, &pending, NULL))
        abort();
    if (pending) {
        init_routine();
        InitOnceComplete(once_control, 0, NULL);
    }
    return 0;
}
void ExecuteOnce(KDThreadOnce *onceControl, void (*initRoutine)(void))
{
    const auto lpInitOnce = reinterpret_cast<PINIT_ONCE>(onceControl);
    const auto dwFlags = 0;
    const auto lpContext = nullptr;
    
    BOOL pending;
    InitOnceBeginInitialize(lpInitOnce, dwFlags, &pending, lpContext);
    if (pending)
    {
        initRoutine();
        InitOnceComplete(lpInitOnce, dwFlags, lpContext);
    }
}