Exemple #1
0
__LLBC_NS_BEGIN

int __LLBC_CoreStartup()
{
    // Create main bundle.
    if(LLBC_Bundle::CreateMainBundle() != LLBC_RTN_OK)
    {
        return LLBC_RTN_FAILED;
    }

    // Set timezone.
    LLBC_TZSet();

    // WIN32 specific, initialize performance frequency.
#if LLBC_TARGET_PLATFORM_WIN32
    LLBC_CPUTime::InitFrequency();
#endif

    // Set entry thread timer scheduler.
    LLBC_TimerScheduler::CreateEntryThreadScheduler();

    __LLBC_LibTls *tls = __LLBC_GetLibTls();
    tls->coreTls.timerScheduler = LLBC_TimerScheduler::GetEntryThreadScheduler();

    // Set random seed.
    LLBC_Random::Seed(static_cast<uint32>(::time(NULL)));

    // Initialize network library.
    LLBC_StartupNetLibrary();

    return LLBC_RTN_OK;
}
Exemple #2
0
__LLBC_NS_BEGIN

int __LLBC_CommonStartup()
{
    // Create library TLS.
    __LLBC_CreateLibTls();

    // Init errors.
    __LLBC_InitErrors();

    // Fill entry thread TLS info.
    __LLBC_LibTls *tls = __LLBC_GetLibTls();
    tls->coreTls.llbcThread = true;
    tls->coreTls.entryThread = true;
    tls->coreTls.threadHandle = LLBC_INVALID_HANDLE;

#if LLBC_TARGET_PLATFORM_NON_WIN32
    tls->coreTls.nativeThreadHandle = pthread_self();
#else // LLBC_TARGET_PLATFORM_WIN32
    HANDLE pseudoHandle = ::GetCurrentThread();
    ::DuplicateHandle(GetCurrentProcess(),
                      pseudoHandle,
                      GetCurrentProcess(),
                      &tls->coreTls.nativeThreadHandle,
                      0,
                      FALSE,
                      DUPLICATE_SAME_ACCESS);
#endif // LLBC_TARGET_PLATFRM_NON_WIN32

    // Set endian type constant.
    LLBC_MachineEndian = LLBC_GetMachineEndianType();

    return LLBC_RTN_OK;
}
Exemple #3
0
int LLBC_Object::AutoRelease()
{
    if (!_poolStack)
    {
        __LLBC_LibTls *tls = __LLBC_GetLibTls();
        _poolStack = reinterpret_cast<
            LLBC_AutoReleasePoolStack *>(tls->objbaseTls.poolStack);
    }

    return _poolStack->AddObject(this);
}
Exemple #4
0
void __LLBC_CoreCleanup()
{
    // Cleanup network library.
    LLBC_CleanupNetLibrary();

    // Destroy entry thread timer scheduler.
    __LLBC_LibTls *tls = __LLBC_GetLibTls();
    tls->coreTls.timerScheduler = NULL;

    LLBC_TimerScheduler::DestroyEntryThreadScheduler();

    // Destroy main bundle.
    LLBC_Bundle::DestroyMainBundle();
}
Exemple #5
0
static LLBC_NS LLBC_ThreadRtn __LLBC_ThreadMgr_ThreadEntry(LLBC_NS LLBC_ThreadArg arg)
{
    // Get thread arguments.
    __LLBC_ThreadMgr_Thread_Arg *threadArg = 
        reinterpret_cast<__LLBC_ThreadMgr_Thread_Arg *>(arg);
    ASSERT(threadArg && "llbc library internal error, threadArg NULL!");

    LLBC_NS LLBC_ThreadArg realArg = threadArg->realArg;
    LLBC_NS LLBC_ThreadProc realProc = threadArg->realProc;
    LLBC_NS LLBC_Handle threadHandle = threadArg->threadHandle;
    LLBC_NS LLBC_ThreadManager *threadMgr = threadArg->threadMgr;

    // Set TLS.
    LLBC_NS __LLBC_LibTls *tls = LLBC_NS __LLBC_GetLibTls();
    tls->coreTls.llbcThread = true;
    tls->coreTls.threadHandle = threadArg->threadHandle;
#if LLBC_TARGET_PLATFORM_NON_WIN32
    tls->coreTls.nativeThreadHandle = LLBC_NS LLBC_GetCurrentThread();
#else // LLBC_TARGET_PLATFORM_WIN32
    HANDLE pseudoHandle = ::GetCurrentThread();
    ::DuplicateHandle(::GetCurrentProcess(),
                      pseudoHandle,
                      ::GetCurrentProcess(),
                      &tls->coreTls.nativeThreadHandle,
                      0,
                      FALSE,
                      DUPLICATE_SAME_ACCESS);
#endif // LLBC_TARGET_PLATFORM_NON_WIN32

    // Delete arg.
    delete threadArg;

    // Notify thread manager thread startup.
    threadMgr->OnThreadStartup(threadHandle);

    // Call thread proc.
    LLBC_NS LLBC_ThreadRtn rtn = (*realProc)(realArg);

    // Notify thread manager thread terminated.
    threadMgr->OnThreadTerminate(threadHandle);

    // Cleanup tls.
#if LLBC_TARGET_PLATFORM_WIN32
    ::CloseHandle(tls->coreTls.nativeThreadHandle);
#endif // LLBC_TARGET_PLATFORM_WIN32
    LLBC_NS __LLBC_ResetLibTls();

    return rtn;
}
Exemple #6
0
void __LLBC_CommonCleanup()
{
    // Reset entry thread tls info.
#if LLBC_TARGET_PLATFORM_WIN32
    __LLBC_LibTls *tls = __LLBC_GetLibTls();
    ::CloseHandle(tls->coreTls.nativeThreadHandle);
#endif // LLBC_TARGET_PLATFORM_WIN32
    __LLBC_ResetLibTls();

    // Destroy errors.
    __LLBC_DestroyErrors();

    // Destroy library TLS.
    __LLBC_DestroyLibTls();
}
Exemple #7
0
int LLBC_Cleanup()
{
    if(!LLBC_INTERNAL_NS __llbc_inited)
    {
        return LLBC_RTN_FAILED;
    }

    __LLBC_LibTls *tls = __LLBC_GetLibTls();
    if(!tls->coreTls.entryThread)
    {
        LLBC_SetLastError(LLBC_ERROR_ACCESS_DENY);
        return LLBC_RTN_FAILED;
    }

    __LLBC_CommCleanup();

    __LLBC_CoreCleanup();

    __LLBC_CommonCleanup();

    LLBC_INTERNAL_NS __llbc_inited = false;

    return LLBC_RTN_OK;
}
Exemple #8
0
LLBC_TimerScheduler::_This *LLBC_TimerScheduler::GetCurrentThreadScheduler()
{
    __LLBC_LibTls *tls = __LLBC_GetLibTls();
    return reinterpret_cast<_This *>(tls->coreTls.timerScheduler);
}