os_boolean s_shmMonitorFree( s_shmMonitor _this) { os_boolean result = OS_TRUE; s_configuration config; os_result osr; if (_this != NULL) { config = splicedGetConfiguration(_this->spliceDaemon); os_mutexLock(&_this->mutex); _this->terminate = OS_TRUE; os_mutexUnlock(&_this->mutex); if (_this->thr != NULL) { osr = ut_threadTimedWaitExit(_this->thr, config->serviceTerminatePeriod, NULL); if (osr != os_resultSuccess) { OS_REPORT(OS_ERROR, OS_FUNCTION, osr, "Failed to join thread \"%s\":0x%" PA_PRIxADDR " (%s)", ut_threadGetName(_this->thr), (os_address)os_threadIdToInteger(ut_threadGetId(_this->thr)), os_resultImage(osr)); result = OS_FALSE; } } if (result) { os_mutexDestroy(&_this->mutex); os_condDestroy(&_this->cleanCondition); os_free(_this); } } return result; }
static void u__waitsetFreeW( void *_this) { u_waitset w; w = u_waitset(_this); while (pa_ld32(&w->useCount) > 0) { os_duration t = OS_DURATION_INIT(0, 100000000); ospl_os_sleep(t); } (void) os_condDestroy(&w->waitCv); (void) os_condDestroy(&w->cv); (void) os_mutexDestroy(&w->mutex); u__objectFreeW(_this); }
void cms_clientFree( cms_client client) { struct soap* soap; cms_soapThread soapThread; cms_thread(client)->terminate = TRUE; os_mutexLock(&client->conditionMutex); os_condSignal(&client->condition); os_mutexUnlock(&client->conditionMutex); cms_threadDeinit(cms_thread(client)); if(client->soapEnvs){ os_mutexLock(&client->soapMutex); soap = (struct soap*)(c_iterTakeFirst(client->soapEnvs)); while(soap){ soap->error = soap_receiver_fault(soap, "Service is terminating.", NULL); soap_send_fault(soap); soap_destroy(soap); soap_end(soap); soap_done(soap); os_free(soap); soap = (struct soap*)(c_iterTakeFirst(client->soapEnvs)); } c_iterFree(client->soapEnvs); client->soapEnvs = NULL; os_mutexUnlock(&client->soapMutex); } if(client->threads){ soapThread = cms_soapThread(c_iterTakeFirst(client->threads)); while(soapThread){ cms_soapThreadFree(soapThread); (void)u_observableAction(u_observable(client->service->uservice), cms_clientStatisticsThreadRemove, client->service); soapThread = cms_soapThread(c_iterTakeFirst(client->threads)); } c_iterFree(client->threads); client->threads = NULL; } os_mutexDestroy(&client->soapMutex); os_mutexDestroy(&client->threadMutex); os_mutexDestroy(&client->conditionMutex); os_condDestroy(&client->condition); client->initCount = 0; if(client->service->configuration->verbosity >= 5){ OS_REPORT(OS_INFO, CMS_CONTEXT, 0, "Client thread stopped for IP: %d.%d.%d.%d", (int)(client->ip>>24)&0xFF, (int)(client->ip>>16)&0xFF, (int)(client->ip>>8)&0xFF, (int)(client->ip&0xFF)); }
static gapi_boolean gapi_handleFree ( void *o) { gapi_handle handle = (gapi_handle) o; gapi_deleteEntityAction action = NULL; gapi_boolean result = TRUE; void *userData; void *actionData; UT_TRACE("gapi_handleFree(%x) %d\n",(unsigned int)handle, handle->kind); if (gapi_handleClaim(handle) == GAPI_RETCODE_OK) { assert(handle->deallocator); if ( handle->userData && handle->deleteActionInfo.action ) { action = handle->deleteActionInfo.action; userData = handle->userData; actionData = handle->deleteActionInfo.argument; } handle->beingDeleted = TRUE; if ( handle->object != NULL ) { result = handle->deallocator(handle->object); if ((handle->kind == OBJECT_KIND_WAITSET) && (handle->registry != NULL)) { _ObjectRegistryDeregister(handle->registry, handle); handle->registry = NULL; handle->object = NULL; } /* Only release _Object when deallocator returned successfully. */ if (result) { os_free(handle->object); handle->object = NULL; } } if ( result && action ) { action(userData, actionData); } /* Only release handle when deallocator returned successfully. */ if (result == TRUE) { assert(handle->registry == NULL); handle->magic = 0; gapi_handleRelease(handle); os_condDestroy(&handle->cv); os_mutexDestroy(&handle->mutex); #ifdef _RWLOCK_ os_mutexDestroy(&handle->read); #endif } else { gapi_handleRelease(handle); } } return result; }
c_syncResult c_condDestroy ( c_cond *cnd) { os_result result; result = os_condDestroy(cnd); if(result != os_resultSuccess){ OS_REPORT_1(OS_ERROR, "c_condDestroy", 0, "os_condDestroy failed; os_result = %d.", result); assert(result == os_resultSuccess); } return result; }
void nn_servicelease_free (struct nn_servicelease *sl) { if (sl->keepgoing != -1) { os_mutexLock (&sl->lock); sl->keepgoing = 0; os_condSignal (&sl->cond); os_mutexUnlock (&sl->lock); join_thread (sl->ts, (void **) 0); } os_condDestroy (&sl->cond); os_mutexDestroy (&sl->lock); os_free (sl->av_ary); os_free (sl); }
void _ObjectDelete ( _Object object) { gapi_handle handle; gapi_deleteEntityAction action = NULL; void *userData; void *actionData; assert(object); handle = (gapi_handle) object->handle; assert(handle); handle->object = NULL; object->handle = NULL; os_free(object); handle->object = NULL; action = handle->deleteActionInfo.action; if ( handle->userData && action ) { userData = handle->userData; actionData = handle->deleteActionInfo.argument; action(userData, actionData); } handle->userData = NULL; handle->magic = MAGIC_DELETED; if ( handle->registry != NULL ) { _ObjectRegistryDeregister(handle->registry, handle); } gapi_handleRelease(handle); os_condDestroy( &handle->cv ); os_mutexDestroy( &handle->mutex ); #ifdef _RWLOCK_ os_mutexDestroy(&handle->read); #endif if ( handle->registry == NULL ) { gapi__free(handle); } }
s_shmMonitor s_shmMonitorNew( spliced splicedaemon) { s_shmMonitor _this; os_result result; s_configuration config; assert(splicedaemon); config = splicedGetConfiguration(splicedaemon); assert(config); _this = os_malloc(sizeof *_this); _this->spliceDaemon = splicedaemon; _this->terminate = OS_FALSE; _this->thr = NULL; _this->shmState = SHM_STATE_CLEAN; result = os_mutexInit(&_this->mutex, NULL); if(result != os_resultSuccess){ OS_REPORT(OS_ERROR, OSRPT_CNTXT_SPLICED, 0, "Failed to init shm monitor mutex"); goto err_shmMonitor_mtx; } result = os_condInit(&_this->cleanCondition, &_this->mutex, NULL); if(result != os_resultSuccess){ OS_REPORT(OS_ERROR, OSRPT_CNTXT_SPLICED, 0, "Failed to init shm monitor cleanCondition"); goto err_shmMonitor_clean_cnd; } ut_threadCreate(splicedGetThreads(splicedaemon), &(_this->thr), "shmMonitor", &config->leaseRenewAttribute, shmMonitorMain, _this); if (_this->thr == NULL) { OS_REPORT(OS_ERROR, OSRPT_CNTXT_SPLICED, 0, "Failed to start shared memory monitor"); goto err_shmMonitor_thr; } return _this; /* Error handling */ err_shmMonitor_thr: os_condDestroy(&_this->cleanCondition); err_shmMonitor_clean_cnd: os_mutexDestroy(&_this->mutex); err_shmMonitor_mtx: os_free(_this); return NULL; }
void s_kernelManagerFree( s_kernelManager km) { u_result r; v_spliced s; if (km) { /* km might be NULL, when spliced has detected other spliced */ os_threadWaitExit(km->id, NULL); os_threadWaitExit(km->resendManager, NULL); u_splicedCAndMCommandDispatcherQuit(km->spliced); os_threadWaitExit(km->cAndMCommandManager, NULL); os_condDestroy(&km->cv); os_mutexDestroy(&km->mtx); os_free(km); } }
/** \brief Initialize the condition variable taking the condition * attributes into account * * \b os_condInit calls \b pthread_cond_init to intialize the posix condition * variable. * * In case the scope attribute is \b OS_SCOPE_SHARED, the posix * condition variable "pshared" attribute is set to \b PTHREAD_PROCESS_SHARED * otherwise it is set to \b PTHREAD_PROCESS_PRIVATE. */ os_result os_condInit ( os_cond *cond, os_mutex *dummymtx, const os_condAttr *condAttr) { pthread_condattr_t mattr; int result = 0; os_result rv; assert (cond != NULL); assert (condAttr != NULL); #ifdef OSPL_STRICT_MEM assert(cond->signature != OS_COND_MAGIC_SIG); #endif pthread_condattr_init (&mattr); if (condAttr->scopeAttr == OS_SCOPE_SHARED) { result = pthread_condattr_setpshared (&mattr, PTHREAD_PROCESS_SHARED); } else { result = pthread_condattr_setpshared (&mattr, PTHREAD_PROCESS_PRIVATE); } if (result == 0) { #ifdef OSPL_STRICT_MEM result = pthread_cond_init (&cond->cond, &mattr); #else result = pthread_cond_init (cond, &mattr); if (result == EBUSY) { os_condDestroy (cond); result = pthread_cond_init (cond, &mattr); } #endif } pthread_condattr_destroy (&mattr); if (result == 0) { #ifdef OSPL_STRICT_MEM cond->signature = OS_COND_MAGIC_SIG; #endif rv = os_resultSuccess; } else { rv = os_resultFail; } return rv; }
void cms_soapThreadFree( cms_soapThread thread) { if(thread->client->service->configuration->verbosity >= 6){ OS_REPORT_1(OS_INFO, CMS_CONTEXT, 0, "Stopping soapThread '%s'...", cms_thread(thread)->name); } os_mutexLock(&thread->soapMutex); cms_thread(thread)->terminate = TRUE; os_condSignal(&thread->condition); os_mutexUnlock(&thread->soapMutex); cms_threadDeinit(cms_thread(thread)); if(thread->client->service->configuration->verbosity >= 6){ OS_REPORT_1(OS_INFO, CMS_CONTEXT, 0, "soapThread '%s' stopped.", cms_thread(thread)->name); } os_condDestroy(&thread->condition); os_mutexDestroy(&thread->soapMutex); os_free(cms_thread(thread)->uri); os_free(thread); }
/************************************************************** * Protected functions **************************************************************/ s_kernelManager s_kernelManagerNew( spliced daemon) { s_kernelManager km; s_configuration config; os_mutexAttr mtxAttr; os_condAttr cvAttr; int status; os_result osr; status = 0; km = os_malloc((os_uint32)C_SIZEOF(s_kernelManager)); if (km) { km->spliced = splicedGetService(daemon); km->active = 0; osr = os_mutexAttrInit(&mtxAttr); if (osr == os_resultSuccess) { mtxAttr.scopeAttr = OS_SCOPE_PRIVATE; osr = os_mutexInit(&km->mtx, &mtxAttr); } else { status++; } if (osr == os_resultSuccess) { osr = os_condAttrInit(&cvAttr); if (osr == os_resultSuccess) { cvAttr.scopeAttr = OS_SCOPE_PRIVATE; osr = os_condInit(&km->cv, &km->mtx, &cvAttr); } else { os_mutexDestroy(&km->mtx); /* don't care if this succeeds, already in error situation */ status++; } if (osr == os_resultSuccess) { config = splicedGetConfiguration(daemon); osr = os_threadCreate(&km->id, S_THREAD_KERNELMANAGER, &config->kernelManagerScheduling, kernelManager, km); if (osr != os_resultSuccess) { /* don't care if the following statements succeeds, already in error situation */ os_mutexDestroy(&km->mtx); os_condDestroy(&km->cv); status++; } } if (osr == os_resultSuccess) { config = splicedGetConfiguration(daemon); osr = os_threadCreate(&km->resendManager, S_THREAD_RESENDMANAGER, &config->resendManagerScheduling, resendManager, km); if (osr != os_resultSuccess) { /* don't care if the following statements succeeds, already in error situation */ os_mutexDestroy(&km->mtx); os_condDestroy(&km->cv); status++; } } if (osr == os_resultSuccess ) { config = splicedGetConfiguration(daemon); if (config->enableCandMCommandThread ) { osr = os_threadCreate(&km->cAndMCommandManager, S_THREAD_C_AND_M_COMMANDMANAGER, &config->cAndMCommandScheduling, cAndMCommandManager, km); if (osr != os_resultSuccess) { /* don't care if the following statements succeeds, already in error situation */ os_mutexDestroy(&km->mtx); os_condDestroy(&km->cv); status++; } } } } else { status++; } } if (status && km) { os_free(km); km = NULL; } return km; }