struct busyobj * THR_GetBusyobj(void) { return (pthread_getspecific(bo_key)); }
/* get thread connections list */ struct mk_list *mk_patas_conx_get() { return pthread_getspecific(_mkp_data); }
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; }
Thread* Thread::getCurrent() { return (Thread*)pthread_getspecific(ourKey); }
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 */
void* uv_key_get(uv_key_t* key) { return pthread_getspecific(*key); }
static void resetdlerror() { struct dlthread *tss; tss = pthread_getspecific(dlerror_key); tss->errset = 0; }
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; }
/* 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 }
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); }
static lib_log_t* lib_get_log_unit() { return (lib_log_t*) pthread_getspecific(g_log_fd); }
/** * 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; }
co_t co_get_current_co() { sched_t s = (sched_t)pthread_getspecific(co_sched_key); return s->co_current; }
struct req * THR_GetRequest(void) { return (pthread_getspecific(req_key)); }
static uintptr_t NaClFaultInjectionGetValue(void) { return (uintptr_t) pthread_getspecific(gTsd_FaultInjectValueKey); }
int rt_print_init(size_t buffer_size, const char *buffer_name) { struct print_buffer *buffer = pthread_getspecific(buffer_key); size_t size = buffer_size; unsigned long old_bitmap; unsigned j; if (!size) size = default_buffer_size; else if (size < RT_PRINT_LINE_BREAK) return EINVAL; if (buffer) { /* Only set name if buffer size is unchanged or default */ if (size == buffer->size || !buffer_size) { set_buffer_name(buffer, buffer_name); return 0; } cleanup_buffer(buffer); buffer = NULL; } #ifdef CONFIG_XENO_FASTSYNCH /* Find a free buffer in the pool */ do { unsigned long bitmap; unsigned i; for (i = 0; i < pool_bitmap_len; i++) { old_bitmap = xnarch_atomic_get(&pool_bitmap[i]); if (old_bitmap) goto acquire; } goto not_found; acquire: do { bitmap = old_bitmap; j = __builtin_ffsl(bitmap) - 1; old_bitmap = xnarch_atomic_cmpxchg(&pool_bitmap[i], bitmap, bitmap & ~(1UL << j)); } while (old_bitmap != bitmap && old_bitmap); j += i * BITS_PER_LONG; } while (!old_bitmap); buffer = (struct print_buffer *)(pool_start + j * pool_buf_size); not_found: #endif /* CONFIG_XENO_FASTSYNCH */ if (!buffer) { assert_nrt(); buffer = malloc(sizeof(*buffer)); if (!buffer) return ENOMEM; buffer->ring = malloc(size); if (!buffer->ring) { free(buffer); return ENOMEM; } rt_print_init_inner(buffer, size); } set_buffer_name(buffer, buffer_name); pthread_setspecific(buffer_key, buffer); return 0; }
bool RT::OS::isRealtime(void) { if (init_rt && pthread_getspecific(is_rt_key)) return true; return false; }
static int vprint_to_buffer(FILE *stream, int priority, unsigned int mode, const char *format, va_list args) { struct print_buffer *buffer = pthread_getspecific(buffer_key); off_t write_pos, read_pos; struct entry_head *head; int len, str_len; int res = 0; if (!buffer) { res = 0; if (auto_init) res = rt_print_init(0, NULL); else res = EIO; if (res) { errno = res; return -1; } buffer = pthread_getspecific(buffer_key); } /* Take a snapshot of the ring buffer state */ write_pos = buffer->write_pos; read_pos = buffer->read_pos; xnarch_read_memory_barrier(); /* Is our write limit the end of the ring buffer? */ if (write_pos >= read_pos) { /* Keep a safety margin to the end for at least an empty entry */ len = buffer->size - write_pos - sizeof(struct entry_head); /* Special case: We were stuck at the end of the ring buffer with space left there only for one empty entry. Now read_pos was moved forward and we can wrap around. */ if (len == 0 && read_pos > sizeof(struct entry_head)) { /* Write out empty entry */ head = buffer->ring + write_pos; head->seq_no = seq_no; head->priority = 0; head->text[0] = 0; /* Forward to the ring buffer start */ write_pos = 0; len = read_pos - 1; } } else { /* Our limit is the read_pos ahead of our write_pos. One byte margin is required to detect a full ring. */ len = read_pos - write_pos - 1; } /* Account for head length */ len -= sizeof(struct entry_head); if (len < 0) len = 0; head = buffer->ring + write_pos; if (mode == RT_PRINT_MODE_FORMAT) { res = vsnprintf(head->text, len, format, args); if (res < len) { /* Text was written completely, res contains its length */ len = res; } else { /* Text was truncated, remove closing \0 that entry_head already includes */ len--; res = len; } } else if (len >= 2) { str_len = strlen(format); len = (str_len < len - 2) ? str_len : len - 2; strncpy(head->text, format, len); head->text[len++] = '\n'; head->text[len] = 0; } else len = 0; /* If we were able to write some text, finalise the entry */ if (len > 0) { head->seq_no = ++seq_no; head->priority = priority; head->dest = stream; /* Move forward by text and head length */ write_pos += len + sizeof(struct entry_head); } /* Wrap around early if there is more space on the other side */ if (write_pos >= buffer->size - RT_PRINT_LINE_BREAK && read_pos <= write_pos && read_pos > buffer->size - write_pos) { /* An empty entry marks the wrap-around */ head = buffer->ring + write_pos; head->seq_no = seq_no; head->priority = priority; head->text[0] = 0; write_pos = 0; } /* All entry data must be written before we can update write_pos */ xnarch_write_memory_barrier(); buffer->write_pos = write_pos; return res; }
int pcu_thread_rank(void) { /* double cast to assure GCC that I know what I'm doing. */ return (int)(ptrdiff_t)(pthread_getspecific(global_key)); }
inline TYPE* TGetValue() { return (TYPE*)pthread_getspecific(m_key); }
static OSStatus BindReplyMachPortToThread(mach_port_t *replyPortPtr) // Get a reply port for this thread, remembering that we've done this // in per-thread storage. // // On success, *replyPortPtr is the port to use for this thread's reply // port. It will be MACH_PORT_NULL if you call it from the main thread. { OSStatus err; assert( replyPortPtr != NULL); assert(*replyPortPtr == MACH_PORT_NULL); // Initialise ourselves the first time that we're called. err = (OSStatus) pthread_once(&sInited, InitRoutine); // If something went wrong, return the latched error. if ( (err == noErr) && (sPerThreadStorageKeyInitErrNum != noErr) ) { err = sPerThreadStorageKeyInitErrNum; } // Now do the real work. if (err == noErr) { if ( pthread_main_np() ) { // This is the main thread, so do nothing; leave *replyPortPtr set // to MACH_PORT_NULL. assert(*replyPortPtr == MACH_PORT_NULL); } else { PerThreadStorage * storage; // Get the per-thread storage for this thread. storage = (PerThreadStorage *) pthread_getspecific(sPerThreadStorageKey); if (storage == NULL) { // The per-thread storage hasn't been allocated yet for this specific // thread. Let's go allocate it and attach it to this thread. err = AllocatePortFromPool(&storage); if (err == noErr) { err = (OSStatus) pthread_setspecific(sPerThreadStorageKey, (void *) storage); if (err != noErr) { ReturnPortToPool(storage); storage = NULL; } } } assert( (err == noErr) == (storage != NULL) ); // If all went well, copy the port out to our client. if (err == noErr) { assert(storage->magic == kPerThreadStorageMagic); assert(storage->port != MACH_PORT_NULL); *replyPortPtr = storage->port; } } } // no error + MACH_PORT_NULL is a valid response if we're on the main // thread. // // assert( (err == noErr) == (*replyPortPtr != MACH_PORT_NULL) ); assert( (*replyPortPtr == MACH_PORT_NULL) || (err == noErr) ); return err; }
void handlerSIGUSR1 (int sig) { int nbCaseTemp,cont,i; CASE *caseTemp; pthread_mutex_lock(&mutexAnalyse); caseTemp=(CASE*)pthread_getspecific(cle); //Analyse Ligne for(i=0,nbCaseTemp=0;i<10;i++)//verifie si ligne complete { if(tab[caseTemp->ligne][i]==BRIQUE) nbCaseTemp++; } if(nbCaseTemp==i) { for(i=0,cont=1;i<nbLignesCompletes;i++)//verifie si deja pas trouve par un autre thread { if(lignesCompletes[i]==caseTemp->ligne) { cont=0; break; } } if(cont==1) { nbLignesCompletes++; lignesCompletes[i]=caseTemp->ligne; for(i=0;i<10;i++) { DessineSprite(caseTemp->ligne,i,FUSION); } } } //Analyse Colonne for(i=0,nbCaseTemp=0;i<14;i++) { if(tab[i][caseTemp->colonne]==BRIQUE) nbCaseTemp++; } if(nbCaseTemp==i) { for(i=0,cont=1;i<nbColonnesCompletes;i++) { if(colonnesCompletes[i]==caseTemp->colonne) { cont=0; break; } } if(cont==1) { nbColonnesCompletes++; colonnesCompletes[i]=caseTemp->colonne; for(i=0;i<14;i++) { DessineSprite(i,caseTemp->colonne,FUSION); } } } nbAnalyses++; pthread_mutex_unlock(&mutexAnalyse); pthread_cond_signal(&condAnalyse); }
static struct _Unwind_FunctionContext* __Unwind_SjLj_GetTopOfFunctionStack() { pthread_once(&sOnceFlag, __Unwind_SjLj_MakeTopOfFunctionStackKey); return (struct _Unwind_FunctionContext*)pthread_getspecific(sPerThreadTopOfFunctionStack); }
void *virThreadLocalGet(virThreadLocalPtr l) { return pthread_getspecific(l->key); }
void fonction() { int* p; p=pthread_getspecific(key); (*p)++; }
T* operator -> () const { return reinterpret_cast<T*>(pthread_getspecific(key)); }
QThreadInstance *QThreadInstance::current() { pthread_once( &storage_key_once, create_storage_key ); QThreadInstance *ret = (QThreadInstance *) pthread_getspecific( storage_key ); return ret; }
static __inline emutls_address_array* emutls_getspecific() { return (emutls_address_array*) pthread_getspecific(emutls_pthread_key); }
static void sigprof(int sig, siginfo_t *info, void *uc_v) { ucontext_t *uc = (ucontext_t *)uc_v; mcontext_t *mc = &uc->uc_mcontext; struct threadcontext context; int i; ADDR newBp, newIp; memset(&context, 0, sizeof context); assert(pthread_getspecific(tls) == 0); context.bp = mc->gregs[REG_EBP]; context.ip = mc->gregs[REG_EIP]; context.sp = mc->gregs[REG_ESP]; updateObjects(); pthread_setspecific(tls, &context); if (setjmp(context.jb) == 0) { for (context.frameCount = 0; context.frameCount < MAXFRAMES; ++context.frameCount) { struct frame *frame = &context.stack[context.frameCount]; frame->ip = context.ip; // Some sanity checking... if (context.bp < 0x80000) break; // We can't find the current instruction pointer in any object. (Java optimiser tends to do this at a time when we can't use our segv handler to recover) if (elf32FindObject(elf, context.ip, &frame->obj) != 0) break; if (elf32FindFunction(frame->obj, context.ip - frame->obj->baseAddr, &frame->function) != 0) frame->function = 0; newBp = ((ADDR *)context.bp)[0]; if (newBp <= context.bp) break; newIp = ((ADDR *)context.bp)[1]; if (newIp == 0) break; context.ip = newIp; context.bp = newBp; } } pthread_setspecific(tls, 0); struct callsite *calledfrom = bottom; if (context.frameCount == 0) return; for (i = context.frameCount - 1; ; --i) { struct callsite *site, **sitep; struct function *function, **functionp; struct frame *frame; ADDR ip; int j; frame = &context.stack[i]; /* * Find the function for this IP. */ functionp = (struct function **)bsearch((void *)frame->ip, functions, functionCount, sizeof functions[0], cmpFuncIP); if (functionp == 0) { /* New function: add to our table. */ if (functionCount == functionMax) { functionMax *= 2; functionMax += 128; functions = realloc(functions, sizeof functions[0] * functionMax); } if (frame->function) { ADDR start = frame->function->elfSym->st_value + frame->obj->baseAddr; ADDR end = start + frame->function->elfSym->st_size; const char *name = frame->function->elfName; function = newFunction(frame->obj, name, start, end); } else { function = newFunction(frame->obj, "_unknown_", frame->ip, frame->ip + 1); } functions[functionCount++] = function; qsort(functions, functionCount, sizeof functions[0], sortFunctions); } else { function = *functionp; } // Make sure this function is on the list of those called from the call site. for (j = 0;; j++) { if (j == calledfrom->callCount) { // This function hasn't been called from this site before. if (calledfrom->callMax == calledfrom->callCount) { calledfrom->callMax *= 2; calledfrom->calls = realloc(calledfrom->calls, sizeof calledfrom->calls[0] * calledfrom->callMax); } calledfrom->calls[calledfrom->callCount++] = function; break; } if (calledfrom->calls[j] == function) break; } function->toCount++; // Don't create a callsite for the top frame: the jump from here was the asynch jump into the sigprof handler if (i == 0) break; // Find or create a callsite out of this function at this IP. for (sitep = &function->callSites;; sitep = &site->next) { site = *sitep; if (site == 0) { site = *sitep = newSite(ip); break; } else if (site->ip == ip) { break; } } site->fromCount++; calledfrom = site; } }
const char * THR_GetName(void) { return (pthread_getspecific(name_key)); }