/*! \brief Decreases the current debug indentation level for the current thread by 1. */ void unindent(uint8 tabCount) { #ifdef USER tls_set(get_tls_handle(), (void*)(_get_debug_indent_level()-tabCount)); #endif }
bool MQTT::ConnectIntEx() { m_bDoReconnect = false; _log.Log(LOG_STATUS, "MQTT: Connecting to %s:%d", m_szIPAddress.c_str(), m_usIPPort); int rc; int keepalive = 60; if (!m_CAFilename.empty()){ rc = tls_set(m_CAFilename.c_str()); if ( rc != MOSQ_ERR_SUCCESS) { _log.Log(LOG_ERROR, "MQTT: Failed enabling TLS mode, return code: %d (CA certificate: '%s')", rc, m_CAFilename.c_str()); return false; } else { _log.Log(LOG_STATUS, "MQTT: enabled TLS mode"); } } rc = username_pw_set((!m_UserName.empty()) ? m_UserName.c_str() : NULL, (!m_Password.empty()) ? m_Password.c_str() : NULL); rc = connect(m_szIPAddress.c_str(), m_usIPPort, keepalive); if ( rc != MOSQ_ERR_SUCCESS) { _log.Log(LOG_ERROR, "MQTT: Failed to start, return code: %d (Check IP/Port)", rc); m_bDoReconnect = true; return false; } return true; }
/* this has to be the first function called by a new thread */ TLS_DATA *tls_alloc(CLI *c, TLS_DATA *inherited, char *txt) { TLS_DATA *tls_data; if(inherited) { /* reuse the thread-local storage after fork() */ tls_data=inherited; str_free(tls_data->id); } else { tls_data=calloc(1, sizeof(TLS_DATA)); if(!tls_data) fatal("Out of memory"); if(c) c->tls=tls_data; str_init(tls_data); tls_data->c=c; tls_data->opt=c?c->opt:&service_options; } tls_data->id="unconfigured"; tls_set(tls_data); /* str.c functions can be used below this point */ if(txt) { tls_data->id=str_dup(txt); str_detach(tls_data->id); /* it is deallocated after str_stats() */ } else if(c) { tls_data->id=log_id(c); str_detach(tls_data->id); /* it is deallocated after str_stats() */ } return tls_data; }
/* GetContextSuspended Returns the currently active Context, in a locked state */ ALCcontext *GetContextSuspended(void) { ALCcontext *pContext = NULL; SuspendContext(NULL); pContext = tls_get(LocalContext); if(pContext && !IsContext(pContext)) { tls_set(LocalContext, NULL); pContext = NULL; } if(!pContext) { pContext = g_pContextList; while(pContext && !pContext->InUse) pContext = pContext->next; } if(pContext) SuspendContext(pContext); ProcessContext(NULL); return pContext; }
/* alcMakeContextCurrent Makes the given Context the active Context */ ALCAPI ALCboolean ALCAPIENTRY alcMakeContextCurrent(ALCcontext *context) { ALCcontext *ALContext; ALboolean bReturn = AL_TRUE; SuspendContext(NULL); // context must be a valid Context or NULL if(context == NULL || IsContext(context)) { if((ALContext=GetContextSuspended()) != NULL) { ALContext->InUse=AL_FALSE; ProcessContext(ALContext); } if((ALContext=context) != NULL && ALContext->Device) { SuspendContext(ALContext); ALContext->InUse=AL_TRUE; ProcessContext(ALContext); } tls_set(LocalContext, NULL); } else { alcSetError(ALC_INVALID_CONTEXT); bReturn = AL_FALSE; } ProcessContext(NULL); return bReturn; }
void _glthread_SetTSD(_glthread_TSD *tsd, void *ptr) { if (tsd->initMagic != (int) INIT_MAGIC) { _glthread_InitTSD(tsd); } tls_set(tsd->key, ptr); }
void u_tsd_set(struct u_tsd *tsd, void *ptr) { if (tsd->initMagic != (int) INIT_MAGIC) { u_tsd_init(tsd); } tls_set(tsd->key, ptr); }
void tls<Type_t>::set(const Type_t &value) { Type_t *new_value = new Type_t(value); Type_t *old_value = static_cast<Type_t *>(tls_get(_key.get())); delete old_value; tls_set(_key.get(), new_value); }
const Type_t &tls<Type_t>::get() const { Type_t *value = static_cast<Type_t *>(tls_get(_key.get())); if (value == NULL) { value = new Type_t; tls_set(_key.get(), value); } return *value; }
/* per-thread thread-local storage cleanup */ void tls_cleanup() { TLS_DATA *tls_data; tls_data=tls_get(); if(!tls_data) return; str_cleanup(tls_data); str_free(tls_data->id); /* detached allocation */ tls_set(NULL); free(tls_data); }
void OSLShader::thread_init(KernelGlobals *kg) { OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl*)kg->osl.ss; OSLGlobals::ThreadData *tdata = new OSLGlobals::ThreadData(); memset(&tdata->globals, 0, sizeof(OSL::ShaderGlobals)); tdata->thread_info = ssi->create_thread_info(); tls_set(kg->osl.thread_data, tdata); ((OSLRenderServices*)ssi->renderer())->thread_init(kg); }
static int sys_thread_func(void *arg) { LTRACE_ENTRY; struct sys_thread *st = arg; DEBUG_ASSERT(st); tls_set(0, (uint32_t) st); st->func(st->arg); LTRACE_EXIT; return 0; }
struct pw_tls *get_pw_tls(void) { pw_tls_t *p = (pw_tls_t *)tls_get(pw_tls_id); PRINT(("%s()\n", __FUNCTION__)); if (!p) { p = (pw_tls_t *)malloc(sizeof(pw_tls_t)); if (!p) return NULL; memset(p, 0, sizeof(pw_tls_t)); p->grent_query = NULL; p->pwent_query = NULL; tls_set(pw_tls_id, p); } return p; }
/* alcGetThreadContext Returns the currently active thread-local Context */ ALCcontext * ALCAPIENTRY alcGetThreadContext(void) { ALCcontext *pContext = NULL; SuspendContext(NULL); pContext = tls_get(LocalContext); if(pContext && !IsContext(pContext)) { tls_set(LocalContext, NULL); pContext = NULL; } ProcessContext(NULL); return pContext; }
void _thread_do_exit_work(void) { callback_node *node = tls_get(TLS_ON_EXIT_THREAD_SLOT); callback_node *next; while (node != NULL) { next = node->next; node->function(node->argument); free(node); node = next; } tls_set(TLS_ON_EXIT_THREAD_SLOT, NULL); __pthread_destroy_thread(); }
/* alcMakeCurrent Makes the given Context the active Context for the current thread */ ALCboolean ALCAPIENTRY alcMakeCurrent(ALCcontext *context) { ALboolean bReturn = AL_TRUE; SuspendContext(NULL); // context must be a valid Context or NULL if(context == NULL || IsContext(context)) tls_set(LocalContext, context); else { alcSetError(ALC_INVALID_CONTEXT); bReturn = AL_FALSE; } ProcessContext(NULL); return bReturn; }