本文整理汇总了C++中TlsSetValue函数的典型用法代码示例。如果您正苦于以下问题:C++ TlsSetValue函数的具体用法?C++ TlsSetValue怎么用?C++ TlsSetValue使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TlsSetValue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wrapper_func
/* The main function of a freshly creating thread. It's a wrapper around
the FUNC and ARG arguments passed to glthread_create_func. */
static unsigned int WINAPI
wrapper_func (void *varg)
{
struct gl_thread_struct *thread = (struct gl_thread_struct *)varg;
EnterCriticalSection (&thread->handle_lock);
/* Create a new handle for the thread only if the parent thread did not yet
fill in the handle. */
if (thread->handle == NULL)
thread->handle = get_current_thread_handle ();
LeaveCriticalSection (&thread->handle_lock);
if (self_key == (DWORD)-1)
init_self_key ();
TlsSetValue (self_key, thread);
/* Run the thread. Store the exit value if the thread was not terminated
otherwise. */
thread->result = thread->func (thread->arg);
return 0;
}
示例2: RhSetWakeUpThreadID
EASYHOOK_NT_INTERNAL RhSetWakeUpThreadID(ULONG InThreadID)
{
/*
Description:
Used in conjunction with RhCreateAndInject(). If the given thread
later is resumed in RhWakeUpProcess(), the injection target will
start its usual execution.
*/
NTSTATUS NtStatus;
if(!TlsSetValue(RhTlsIndex, (LPVOID)(size_t)InThreadID))
THROW(STATUS_INTERNAL_ERROR, L"Unable to set TLS value.");
RETURN(STATUS_SUCCESS);
THROW_OUTRO:
FINALLY_OUTRO:
return NtStatus;
}
示例3: _threadstart
static unsigned long WINAPI _threadstart (
void * ptd
)
{
/*
* Stash the pointer to the per-thread data stucture in TLS
*/
if ( !TlsSetValue(__tlsindex, ptd) )
_amsg_exit(_RT_THREAD);
/*
* Call fp initialization, if necessary
*/
if ( _FPmtinit != NULL )
(*_FPmtinit)();
/*
* Guard call to user code with a _try - _except statement to
* implement runtime errors and signal support
*/
__try {
( (void(__cdecl *)(void *))(((_ptiddata)ptd)->_initaddr) )
( ((_ptiddata)ptd)->_initarg );
_endthread();
}
__except ( _XcptFilter(GetExceptionCode(), GetExceptionInformation()) )
{
/*
* Should never reach here
*/
_exit( GetExceptionCode() );
} /* end of _try - _except */
/*
* Never executed!
*/
return(0L);
}
示例4: pthread_self
pthread_t pthread_self(void)
{
pthread_t t;
_pthread_once_raw(&_pthread_tls_once, pthread_tls_init);
t = (pthread_t)TlsGetValue(_pthread_tls);
/* Main thread? */
if (!t)
{
t = (pthread_t)malloc(sizeof(struct _pthread_v));
/* If cannot initialize main thread, then the only thing we can do is abort */
if (!t) abort();
t->ret_arg = NULL;
t->func = NULL;
t->clean = NULL;
t->cancelled = 0;
t->p_state = PTHREAD_DEFAULT_ATTR;
t->keymax = 0;
t->keyval = NULL;
t->h = GetCurrentThread();
/* Save for later */
TlsSetValue(_pthread_tls, t);
if (setjmp(t->jb))
{
/* Make sure we free ourselves if we are detached */
if (!t->h) free(t);
/* Time to die */
_endthreadex(0);
}
}
return t;
}
示例5: _PrintExit
VOID _PrintExit(const CHAR *psz, ...)
{
DWORD dwErr = GetLastError();
LONG nIndent = 0;
LONG nThread = 0;
if (s_nTlsIndent >= 0) {
nIndent = (LONG)TlsGetValue(s_nTlsIndent) - 1;
ASSERT(nIndent >= 0);
TlsSetValue(s_nTlsIndent, (PVOID)nIndent);
}
if (s_nTlsThread >= 0) {
nThread = (LONG)TlsGetValue(s_nTlsThread);
}
if (s_bLog && psz) {
CHAR szBuf[1024];
PCHAR pszBuf = szBuf;
LONG nLen = (nIndent > 0) ? (nIndent < 35 ? nIndent * 2 : 70) : 0;
*pszBuf++ = (CHAR)('0' + ((nThread / 100) % 10));
*pszBuf++ = (CHAR)('0' + ((nThread / 10) % 10));
*pszBuf++ = (CHAR)('0' + ((nThread / 1) % 10));
*pszBuf++ = ' ';
while (nLen-- > 0) {
*pszBuf++ = ' ';
}
va_list args;
va_start(args, psz);
while ((*pszBuf++ = *psz++) != 0) {
// Copy characters.
}
SyelogV(SYELOG_SEVERITY_INFORMATION,
szBuf, args);
va_end(args);
}
SetLastError(dwErr);
}
示例6: hal_initthread
EXPORT TBOOL
hal_initthread(struct THALBase *hal, struct THALObject *thread,
TTASKENTRY void (*function)(struct TTask *task), TAPTR data)
{
struct HALThread *wth = THALNewObject(hal, thread, struct HALThread);
if (wth)
{
wth->hth_SigEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (wth->hth_SigEvent)
{
#ifndef HAL_USE_ATOMICS
InitializeCriticalSection(&wth->hth_SigLock);
#endif
wth->hth_SigState = 0;
wth->hth_HALBase = hal;
wth->hth_Data = data;
wth->hth_Function = function;
THALSetObject(thread, struct HALThread, wth);
if (function)
{
wth->hth_Thread = (TAPTR) _beginthreadex(NULL, 0,
hal_win32thread_entry, wth, 0, (HANDLE) &wth->hth_ThreadID);
if (wth->hth_Thread) return TTRUE;
}
else
{
struct HALSpecific *hws = hal->hmb_Specific;
TlsSetValue(hws->hsp_TLSIndex, wth);
return TTRUE;
}
#ifndef HAL_USE_ATOMICS
DeleteCriticalSection(&wth->hth_SigLock);
#endif
CloseHandle(wth->hth_SigEvent);
}
THALDestroyObject(hal, wth, struct HALThread);
}
TDBPRINTF(20,("could not create thread\n"));
return TFALSE;
}
示例7: _freeptd
void __cdecl _freeptd (
_ptiddata ptd
)
{
/*
* Do nothing unless per-thread data has been allocated for this module!
*/
if ( __flsindex != 0xFFFFFFFF ) {
/*
* if parameter "ptd" is NULL, get the per-thread data pointer
* Must NOT call _getptd because it will allocate one if none exists!
* If FLS_GETVALUE is NULL then ptd could not have been set
*/
if ( ptd == NULL
#ifndef _M_AMD64
&& (FLS_GETVALUE != NULL)
#endif /* _M_AMD64 */
)
ptd = FLS_GETVALUE(__flsindex);
/*
* Zero out the one pointer to the per-thread data block
*/
FLS_SETVALUE(__flsindex, (LPVOID)0);
_freefls(ptd);
}
if ( __getvalueindex != 0xFFFFFFFF ) {
/*
* Zero out the FlsGetValue pointer
*/
TlsSetValue(__getvalueindex, (LPVOID)0);
}
}
示例8: Assert
/* static */
bool JsrtContext::TrySetCurrent(JsrtContext * context)
{
Assert(s_tlsSlot != TLS_OUT_OF_INDEXES);
ThreadContext * threadContext;
//We are not pinning the context after SetCurrentContext, so if the context is not pinned
//it might be reclaimed half way during execution. In jsrtshell the runtime was optimized out
//at time of JsrtContext::Run by the compiler.
//The change is to pin the context at setconcurrentcontext, and unpin the previous one. In
//JsDisposeRuntime we'll reject if current context is active, so that will make sure all
//contexts are unpinned at time of JsDisposeRuntime.
if (context != nullptr)
{
threadContext = context->GetScriptContext()->GetThreadContext();
if (!ThreadContextTLSEntry::TrySetThreadContext(threadContext))
{
return false;
}
threadContext->GetRecycler()->RootAddRef((LPVOID)context);
}
else
{
if (!ThreadContextTLSEntry::ClearThreadContext(true))
{
return false;
}
}
JsrtContext* originalContext = (JsrtContext*) TlsGetValue(s_tlsSlot);
if (originalContext != nullptr)
{
originalContext->GetScriptContext()->GetRecycler()->RootRelease((LPVOID) originalContext);
}
TlsSetValue(s_tlsSlot, context);
return true;
}
示例9: iv_init
void iv_init(void)
{
struct iv_state *st;
if (iv_state_index == -1) {
iv_state_index = TlsAlloc();
if (iv_state_index == TLS_OUT_OF_INDEXES)
iv_fatal("iv_init: failed to allocate TLS key");
}
st = calloc(1, iv_tls_total_state_size());
TlsSetValue(iv_state_index, st);
iv_handle_init(st);
iv_task_init(st);
iv_time_init(st);
iv_timer_init(st);
iv_event_init(st);
iv_tls_thread_init(st);
}
示例10: virThreadLocalInit
int virThreadLocalInit(virThreadLocalPtr l,
virThreadLocalCleanup c)
{
if ((l->key = TlsAlloc()) == TLS_OUT_OF_INDEXES) {
errno = ESRCH;
return -1;
}
TlsSetValue(l->key, NULL);
if (c) {
virMutexLock(&virThreadLocalLock);
if (VIR_REALLOC_N(virThreadLocalList,
virThreadLocalCount + 1) < 0)
return -1;
virThreadLocalList[virThreadLocalCount].key = l->key;
virThreadLocalList[virThreadLocalCount].cleanup = c;
virThreadLocalCount++;
virMutexUnlock(&virThreadLocalLock);
}
return 0;
}
示例11: initializeCustomHeap
static TheCustomHeapType * initializeCustomHeap (void)
{
#if !defined(_WIN32)
createKey();
assert (pthread_getspecific (theHeapKey) == NULL);
#endif
// Allocate a per-thread heap.
TheCustomHeapType * heap;
size_t sz = sizeof(TheCustomHeapType) + sizeof(double);
void * mh = getMainHoardHeap()->malloc(sz);
heap = new ((char *) mh) TheCustomHeapType (getMainHoardHeap());
// Store it in the appropriate thread-local area.
#if defined(_WIN32)
TlsSetValue (LocalTLABIndex, heap);
#else
int r = pthread_setspecific (theHeapKey, (void *) heap);
assert (!r);
#endif
return heap;
}
示例12: GetManager
// Obtains a manager for the thread, with refcounting
CMenuFocusManager * CMenuFocusManager::AcquireManager()
{
CMenuFocusManager * obj = NULL;
if (!TlsIndex)
{
if ((TlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES)
return NULL;
}
obj = GetManager();
if (!obj)
{
obj = new CComObject<CMenuFocusManager>();
TlsSetValue(TlsIndex, obj);
}
obj->AddRef();
return obj;
}
示例13: async_fibre_init_dispatcher
int async_fibre_init_dispatcher(async_fibre *fibre)
{
LPVOID dispatcher;
dispatcher = (LPVOID)TlsGetValue(asyncwindispatch);
if (dispatcher == NULL) {
fibre->fibre = ConvertThreadToFiber(NULL);
if (fibre->fibre == NULL) {
fibre->converted = 0;
fibre->fibre = GetCurrentFiber();
if (fibre->fibre == NULL)
return 0;
} else {
fibre->converted = 1;
}
if (TlsSetValue(asyncwindispatch, (LPVOID)fibre->fibre) == 0)
return 0;
} else {
fibre->fibre = dispatcher;
}
return 1;
}
示例14: stresscpu_thread_setspecific
int
stresscpu_thread_setspecific(stresscpu_thread_key_t key,
const void * value)
{
int ret;
if(key!=NULL && value != NULL)
{
EnterCriticalSection(&key->cs);
ret = TlsSetValue(key->tls_index,(void *)value);
LeaveCriticalSection(&key->cs);
}
if (ret == 0)
{
ret = EAGAIN;
}
else
{
ret = 0;
}
return ret;
}
示例15: Initialize_Thread_Errno
/*
* Initialize a thread's errno
*/
static void Initialize_Thread_Errno(int *Errno_Pointer)
{
/*
* Make sure we have a slot
*/
if (TLS_Errno_Slot == 0xffffffff) {
/*
* No: Get one
*/
TLS_Errno_Slot = (int)TlsAlloc();
if (TLS_Errno_Slot == 0xffffffff) ExitProcess(3);
}
/*
* We can safely check for 0 threads, because
* only the main thread will be initializing
* at this point. Make sure the critical
* section that protects the number of threads
* is initialized
*/
if (Number_Of_Threads == 0)
InitializeCriticalSection(&Number_Of_Threads_Critical_Section);
/*
* Store the errno pointer
*/
if (TlsSetValue(TLS_Errno_Slot, (LPVOID)Errno_Pointer) == 0) ExitProcess(3);
/*
* Bump the number of threads
*/
EnterCriticalSection(&Number_Of_Threads_Critical_Section);
Number_Of_Threads++;
if (Number_Of_Threads > 1) {
/*
* We have threads other than the main thread:
* Use thread-local storage
*/
__WinCE_Errno_Pointer_Function = Get_Thread_Errno;
}
LeaveCriticalSection(&Number_Of_Threads_Critical_Section);
}