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; }
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_printEvent( spliced s, s_reportlevel level, const char *format, ...) { va_list args; s_configuration config; config = splicedGetConfiguration(s); if (config) { if (((c_ulong)level) >= ((c_ulong)config->tracingVerbosityLevel)) { va_start(args, format); s_doPrint(config, format, args); va_end(args); } } }
/************************************************************** * 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; }