本文整理汇总了C++中pthread_getspecific函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_getspecific函数的具体用法?C++ pthread_getspecific怎么用?C++ pthread_getspecific使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_getspecific函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: THR_GetBusyobj
struct busyobj *
THR_GetBusyobj(void)
{
return (pthread_getspecific(bo_key));
}
示例2: pthread_getspecific
/* get thread connections list */
struct mk_list *mk_patas_conx_get()
{
return pthread_getspecific(_mkp_data);
}
示例3: _res_thread_get
static _res_thread*
_res_thread_get(void)
{
_res_thread* rt;
pthread_once( &_res_once, _res_init_key );
rt = pthread_getspecific( _res_key );
if (rt != NULL) {
/* We already have one thread-specific DNS state object.
* Check the serial value for any changes to net.* properties */
D("%s: Called for tid=%d rt=%p rt->pi=%p rt->serial=%d",
__FUNCTION__, gettid(), rt, rt->_pi, rt->_serial);
if (rt->_pi == NULL) {
/* The property wasn't created when _res_thread_get() was
* called the last time. This should only happen very
* early during the boot sequence. First, let's try to see if it
* is here now. */
rt->_pi = (struct prop_info*) __system_property_find("net.change");
if (rt->_pi == NULL) {
/* Still nothing, return current state */
D("%s: exiting for tid=%d rt=%d since system property not found",
__FUNCTION__, gettid(), rt);
return rt;
}
}
if (rt->_serial == __system_property_serial(rt->_pi)) {
/* Nothing changed, so return the current state */
D("%s: tid=%d rt=%p nothing changed, returning",
__FUNCTION__, gettid(), rt);
return rt;
}
/* Update the recorded serial number, and go reset the state */
rt->_serial = __system_property_serial(rt->_pi);
goto RESET_STATE;
}
/* It is the first time this function is called in this thread,
* we need to create a new thread-specific DNS resolver state. */
rt = _res_thread_alloc();
if (rt == NULL) {
return NULL;
}
pthread_setspecific( _res_key, rt );
D("%s: tid=%d Created new DNS state rt=%p",
__FUNCTION__, gettid(), rt);
RESET_STATE:
/* Reset the state, note that res_ninit() can now properly reset
* an existing state without leaking memory.
*/
D("%s: tid=%d, rt=%p, resetting DNS state (options RES_INIT=%d)",
__FUNCTION__, gettid(), rt, (rt->_nres->options & RES_INIT) != 0);
if ( res_ninit( rt->_nres ) < 0 ) {
/* This should not happen */
D("%s: tid=%d rt=%p, woot, res_ninit() returned < 0",
__FUNCTION__, gettid(), rt);
_res_thread_free(rt);
pthread_setspecific( _res_key, NULL );
return NULL;
}
return rt;
}
示例4: return
Thread* Thread::getCurrent()
{
return (Thread*)pthread_getspecific(ourKey);
}
示例5: pthread_self
pthread_t
pthread_self (void)
/*
* ------------------------------------------------------
* DOCPUBLIC
* This function returns a reference to the current running
* thread.
*
* PARAMETERS
* N/A
*
*
* DESCRIPTION
* This function returns a reference to the current running
* thread.
*
* RESULTS
* pthread_t reference to the current thread
*
* ------------------------------------------------------
*/
{
pthread_t self;
#ifdef _UWIN
if (!ptw32_selfThreadKey)
return (NULL);
#endif
self = (pthread_t) pthread_getspecific (ptw32_selfThreadKey);
if (self == NULL)
{
/*
* Need to create an implicit 'self' for the currently
* executing thread.
*/
self = ptw32_new ();
if (self != NULL)
{
/*
* This is a non-POSIX thread which has chosen to call
* a POSIX threads function for some reason. We assume that
* it isn't joinable, but we do assume that it's
* (deferred) cancelable.
*/
self->implicit = 1;
self->detachState = PTHREAD_CREATE_DETACHED;
self->thread = GetCurrentThreadId ();
#ifdef NEED_DUPLICATEHANDLE
/*
* DuplicateHandle does not exist on WinCE.
*
* NOTE:
* GetCurrentThread only returns a pseudo-handle
* which is only valid in the current thread context.
* Therefore, you should not pass the handle to
* other threads for whatever purpose.
*/
self->threadH = GetCurrentThread ();
#else
if (!DuplicateHandle (GetCurrentProcess (),
GetCurrentThread (),
GetCurrentProcess (),
&self->threadH,
0, FALSE, DUPLICATE_SAME_ACCESS))
{
/* Thread structs are never freed. */
ptw32_threadReusePush (self);
return (NULL);
}
#endif
/*
* No need to explicitly serialise access to sched_priority
* because the new handle is not yet public.
*/
self->sched_priority = GetThreadPriority (self->threadH);
}
pthread_setspecific (ptw32_selfThreadKey, self);
}
return (self);
} /* pthread_self */
示例6: uv_key_get
void* uv_key_get(uv_key_t* key) {
return pthread_getspecific(*key);
}
示例7: resetdlerror
static void resetdlerror()
{
struct dlthread *tss;
tss = pthread_getspecific(dlerror_key);
tss->errset = 0;
}
示例8: CmiGetState
CmiState CmiGetState() {
CmiState ret;
if (Cmi_state_key == (pthread_key_t)(-1)) return &Cmi_default_state;
ret=(CmiState)pthread_getspecific(Cmi_state_key);
return (ret==NULL)? &Cmi_default_state : ret;
}
示例9: macosx_init_exception_handler
/* this initializes the subsystem (sets the exception port, starts the
exception handling thread, etc) */
static void macosx_init_exception_handler(int isMASTERGC)
{
kern_return_t retval;
if (!isMASTERGC) {
GC_attach_current_thread_exceptions_to_handler();
return;
}
if(!task_self) task_self = mach_task_self();
/* allocate the port we're going to get exceptions on */
retval = mach_port_allocate(task_self, MACH_PORT_RIGHT_RECEIVE, &exc_port);
if(retval != KERN_SUCCESS) {
GCPRINT(GCOUTF, "Couldn't allocate exception port: %s\n",
mach_error_string(retval));
abort();
}
GC_attach_current_thread_exceptions_to_handler();
#ifdef PPC_HAND_ROLLED_THREAD
/* Old hand-rolled thread creation. */
{
/* set up the subthread */
mach_port_t exc_thread;
ARCH_thread_state_t *exc_thread_state;
void *subthread_stack;
retval = thread_create(task_self, &exc_thread);
if(retval != KERN_SUCCESS) {
GCPRINT(GCOUTF, "Couldn't create exception thread: %s\n", mach_error_string(retval));
abort();
}
subthread_stack = (void*)malloc(page_size);
subthread_stack += (page_size - C_ARGSAVE_LEN - C_RED_ZONE);
exc_thread_state = (ARCH_thread_state_t*)malloc(sizeof(ARCH_thread_state_t));
exc_thread_state->srr0 = (unsigned int)exception_thread;
exc_thread_state->r1 = (unsigned int)subthread_stack;
retval = thread_set_state(exc_thread, ARCH_THREAD_STATE,
(thread_state_t)exc_thread_state,
ARCH_THREAD_STATE_COUNT);
if(retval != KERN_SUCCESS) {
GCPRINT(GCOUTF, "Couldn't set subthread state: %s\n", mach_error_string(retval));
abort();
}
retval = thread_resume(exc_thread);
if(retval != KERN_SUCCESS) {
GCPRINT(GCOUTF, "Couldn't resume subthread: %s\n", mach_error_string(retval));
abort();
}
}
#else
{
pthread_t th;
void *data = NULL;
#ifdef USE_THREAD_LOCAL
data = pthread_getspecific(scheme_thread_local_key);
#endif
pthread_create(&th, NULL, (void *(*)(void *))exception_thread, data);
}
#endif
}
示例10: get_current_thread_data
boost::detail::thread_data_base* get_current_thread_data()
{
boost::call_once(current_thread_tls_init_flag,create_current_thread_tls_key);
return (boost::detail::thread_data_base*)pthread_getspecific(current_thread_tls_key);
}
示例11: lib_get_log_unit
static lib_log_t* lib_get_log_unit()
{
return (lib_log_t*) pthread_getspecific(g_log_fd);
}
示例12: fsal_increment_nbcall
/**
* fsal_increment_nbcall:
* Updates fonction call statistics.
*
* \param function_index (input):
* Index of the function whom number of call is to be incremented.
* \param status (input):
* Status the function returned.
*
* \return Nothing.
*/
void fsal_increment_nbcall(int function_index, fsal_status_t status)
{
fsal_statistics_t *bythread_stat = NULL;
/* verify index */
if(function_index >= FSAL_NB_FUNC)
return;
/* first, we init the keys if this is the first time */
if(pthread_once(&once_key, init_keys) != 0)
{
LogError(COMPONENT_FSAL, ERR_SYS, ERR_PTHREAD_ONCE, errno);
return;
}
/* we get the specific value */
bythread_stat = (fsal_statistics_t *) pthread_getspecific(key_stats);
/* we allocate stats if this is the first time */
if(bythread_stat == NULL)
{
int i;
bythread_stat = (fsal_statistics_t *) Mem_Alloc(sizeof(fsal_statistics_t));
if(bythread_stat == NULL)
{
LogError(COMPONENT_FSAL, ERR_SYS, ERR_MALLOC, Mem_Errno);
return;
}
/* inits the struct */
for(i = 0; i < FSAL_NB_FUNC; i++)
{
bythread_stat->func_stats.nb_call[i] = 0;
bythread_stat->func_stats.nb_success[i] = 0;
bythread_stat->func_stats.nb_err_retryable[i] = 0;
bythread_stat->func_stats.nb_err_unrecover[i] = 0;
}
/* set the specific value */
pthread_setspecific(key_stats, (void *)bythread_stat);
}
/* we increment the values */
if(bythread_stat)
{
bythread_stat->func_stats.nb_call[function_index]++;
if(!FSAL_IS_ERROR(status))
bythread_stat->func_stats.nb_success[function_index]++;
else if(fsal_is_retryable(status))
bythread_stat->func_stats.nb_err_retryable[function_index]++;
else
bythread_stat->func_stats.nb_err_unrecover[function_index]++;
}
return;
}
示例13: co_get_current_co
co_t co_get_current_co()
{
sched_t s = (sched_t)pthread_getspecific(co_sched_key);
return s->co_current;
}
示例14: THR_GetRequest
struct req *
THR_GetRequest(void)
{
return (pthread_getspecific(req_key));
}
示例15: NaClFaultInjectionGetValue
static uintptr_t NaClFaultInjectionGetValue(void) {
return (uintptr_t) pthread_getspecific(gTsd_FaultInjectValueKey);
}