コード例 #1
0
bool ThreadContextTLSEntry::TrySetThreadContext(ThreadContext * threadContext)
{
    Assert(threadContext != NULL);
    ASSERT_ENTRY_INITIALIZED();

    DWORD threadContextThreadId = threadContext->GetCurrentThreadId();

    // If a thread context is current on another thread, then you cannot set it to current on this one.
    if (threadContextThreadId != ThreadContext::NoThread && threadContextThreadId != ::GetCurrentThreadId())
    {
        // the thread doesn't support rental thread and try to set on a different thread???
        Assert(!threadContext->IsThreadBound());
        return false;
    }

    ThreadContextTLSEntry * entry = ENTRY_FOR_CURRENT_THREAD();

    if (entry == NULL)
    {
        Assert(!threadContext->IsThreadBound());
        entry = CreateEntryForCurrentThread();
#ifndef _WIN32
        ENTRY_FOR_CURRENT_THREAD() = entry;
#endif
    }
    else if (entry->threadContext != NULL && entry->threadContext != threadContext)
    {
        // If the thread has an active thread context and either that thread context is thread
        // bound (in which case it cannot be moved off this thread), or if the thread context
        // is running script, you cannot move it off this thread.
        if (entry->threadContext->IsThreadBound() || entry->threadContext->IsInScript())
        {
            return false;
        }

        ClearThreadContext(entry, true);
    }

    SetThreadContext(entry, threadContext);

    return true;
}
コード例 #2
0
bool ThreadContextTLSEntry::TrySetThreadContext(ThreadContext * threadContext)
{
    Assert(threadContext != NULL);
    Assert(s_tlsSlot != TLS_OUT_OF_INDEXES);

    DWORD threadContextThreadId = threadContext->GetCurrentThreadId();

    // If a thread context is current on another thread, then you cannot set it to current on this one.
    if (threadContextThreadId != ThreadContext::NoThread && threadContextThreadId != ::GetCurrentThreadId())
    {
        // the thread doesn't support rental thread and try to set on a different thread???
        Assert(!threadContext->GetIsThreadBound());
        return false;
    }

    ThreadContextTLSEntry * entry = GetEntryForCurrentThread();

    if (entry == NULL)
    {
        Assert(!threadContext->GetIsThreadBound());
        entry = CreateEntryForCurrentThread();
    }
    else if (entry->threadContext != NULL && entry->threadContext != threadContext)
    {
        // If the thread has an active thread context and either that thread context is thread
        // bound (in which case it cannot be moved off this thread), or if the thread context
        // is running script, you cannot move it off this thread.
        if (entry->threadContext->GetIsThreadBound() || entry->threadContext->IsInScript())
        {
            return false;
        }

        ClearThreadContext(entry, true);
    }

    SetThreadContext(entry, threadContext);

    return true;
}
コード例 #3
0
bool ThreadContextTLSEntry::ClearThreadContext(bool isValid)
{
    return ClearThreadContext(GetEntryForCurrentThread(), isValid, false);
}
コード例 #4
0
bool ThreadContextTLSEntry::ClearThreadContext(bool isValid)
{
    return ClearThreadContext(ENTRY_FOR_CURRENT_THREAD(), isValid, false);
}