u_result u_readerInit( u_reader _this) { u_result result; os_result osResult; os_mutexAttr osMutexAttr; if (_this != NULL) { result = u_dispatcherInit(u_dispatcher(_this)); if (result == U_RESULT_OK) { _this->queries = NULL; osResult = os_mutexAttrInit(&osMutexAttr); if (osResult == os_resultSuccess) { osMutexAttr.scopeAttr = OS_SCOPE_PRIVATE; osResult = os_mutexInit(&_this->mutex, &osMutexAttr); if (osResult != os_resultSuccess) { result = U_RESULT_INTERNAL_ERROR; } } u_entity(_this)->flags |= U_ECREATE_INITIALISED; } } else { result = U_RESULT_ILL_PARAM; } return result; }
/** * Read environment properties. In particular ones that can't be left until * there is a requirement to log. */ void os_reportInit(os_boolean forceReInit) { static os_boolean doneOnce = OS_FALSE; char *envValue; os_mutexAttr attr; os_result osr; if (!doneOnce || forceReInit) { if (!doneOnce) { osr = os_mutexAttrInit(&attr); if(osr == os_resultSuccess) { attr.scopeAttr = OS_SCOPE_PRIVATE; osr = os_mutexInit(&reportMutex, &attr); } if(osr != os_resultSuccess) { OS_REPORT(OS_WARNING, "os_reportInit", 0, "Unable to create report mutex"); } } doneOnce = OS_TRUE; envValue = os_getenv(os_env_verbosity); if (envValue != NULL) { if (os_reportSetVerbosity(envValue) == os_resultFail) { OS_REPORT_3(OS_WARNING, "os_reportInit", 0, "Cannot parse report verbosity %s value \"%s\"," " reporting verbosity remains %s", os_env_verbosity, envValue, os_reportTypeText[os_reportVerbosity]); } } if (os_procIsOpenSpliceDomainDaemon()) { /** @todo dds2881 - Change default to OS_FALSE ? */ doAppend = OS_TRUE; } envValue = os_getenv(os_env_append); if (envValue != NULL) { os_boolean shouldAppend; if (os_configIsTrue(envValue, &shouldAppend) == os_resultFail) { OS_REPORT_2(OS_WARNING, "os_reportInit", 0, "Cannot parse report %s value \"%s\"," " reporting append mode unchanged", os_env_append, envValue); } else { os_reportSetDoAppend(shouldAppend); } } } }
void d_lockInit( d_lock lock, d_kind kind, d_objectDeinitFunc deinit) { os_mutexAttr attr; os_result osr; d_objectInit(d_object(lock), kind, d_lockDeinit); if(lock){ lock->deinit = deinit; osr = os_mutexAttrInit(&attr); if(osr == os_resultSuccess){ attr.scopeAttr = OS_SCOPE_PRIVATE; osr = os_mutexInit(&lock->lock, &attr); if(osr != os_resultSuccess){ d_objectFree(d_object(lock), kind); } } else { d_objectFree(d_object(lock), kind); } } }
_ObjectRegistry _ObjectRegistryNew ( void) { _ObjectRegistry registry; os_result osResult; os_mutexAttr osMutexAttr; int i; registry = (_ObjectRegistry) os_malloc(C_SIZEOF(_ObjectRegistry)); if ( registry != NULL ) { registry->active = NULL; registry->ptr = 0; osResult = os_mutexAttrInit (&osMutexAttr); osMutexAttr.scopeAttr = OS_SCOPE_PRIVATE; osResult = os_mutexInit (®istry->mutex, &osMutexAttr); for (i = 0; i < TRASH_LENGTH; i++) { registry->trash[i] = NULL; } } return registry; }
_Object _ObjectAlloc ( _ObjectKind kind, long size, gapi_boolean (*deallocator)(void *)) { gapi_handle handle = NULL; _Object object = NULL; if ( deallocator != NULL ) { handle = (gapi_handle) gapi__malloc(gapi_handleFree, 0, (C_SIZEOF(gapi_handle))); } else { handle = (gapi_handle) gapi__malloc(NULL, 0, (C_SIZEOF(gapi_handle))); } if ( handle != NULL ) { os_result osResult; os_mutexAttr osMutexAttr; os_condAttr osCondAttr; handle->magic = MAGIC; handle->kind = kind; handle->registry = NULL; handle->userData = NULL; handle->busy = FALSE; handle->deleteActionInfo.action = NULL; handle->deleteActionInfo.argument = NULL; handle->beingDeleted = FALSE; osResult = os_mutexAttrInit (&osMutexAttr); osMutexAttr.scopeAttr = OS_SCOPE_PRIVATE; osResult = os_mutexInit (&handle->mutex, &osMutexAttr); osResult = os_condAttrInit (&osCondAttr); osCondAttr.scopeAttr = OS_SCOPE_PRIVATE; osResult = os_condInit (&handle->cv, &handle->mutex, &osCondAttr); #ifdef _RWLOCK_ osResult = os_mutexInit (&handle->read, &osMutexAttr); handle->count = 0; #endif object = (_Object) os_malloc(size); if ( object != NULL ) { memset(object, 0, size); handle->deallocator = deallocator; os_mutexLock(&handle->mutex); handle->object = object; object->handle = (gapi_object)handle; } else { gapi__free(handle); } } return object; }
os_result os_mutexInit (os_mutex *mutex, const os_mutexAttr *mutexAttr) { os_mutexAttr defAttr; os_result rv; int options; SEM_ID id; assert (mutex != NULL); #ifdef OSPL_STRICT_MEM assert (mutex->signature != OS_MUTEX_MAGIC_SIG); #endif if(!mutexAttr) { os_mutexAttrInit(&defAttr); mutexAttr = &defAttr; } options = (SEM_Q_PRIORITY | SEM_DELETE_SAFE); /* Set option for priority inheritance if feature is enabled */ if (ospl_mtx_prio_inherit) { options = options | SEM_INVERSION_SAFE; } if (mutexAttr->scopeAttr == OS_SCOPE_SHARED) { /* create named mutex using shared address as unique name */ snprintf (mutex->name, sizeof (mutex->name), "/%lu", (os_uint32) mutex); id = semOpen (mutex->name, SEM_TYPE_MUTEX, SEM_EMPTY, options, OM_CREATE|OM_EXCL, NULL); /* As it may exist from a previous run. remove leftover semaphore object */ if (id != NULL) { /* a fresh one, initialise it and cache the SEM_ID */ pa_st32 ((void *) &mutex->info.id, 0); semTake (cache_lock, WAIT_FOREVER); (void) ut_tableInsert ((ut_table) cache, mutex, id); semGive (cache_lock); } else { /* re-using an old one: it should have been destroyed and hence should have a marker in info.id */ id = get_mutex (mutex); if (id != NULL) { semTake (id, WAIT_FOREVER); semGive (id); /*cas_mutex_info_id ((void*)&mutex->info.id, invalid_sem_id, 0);*/ } else { mutex_panic ("init: attempt to reuse semaphore currently in use", 0); } } rv = (id != NULL) ? os_resultSuccess : os_resultFail; } else { int result; mutex->name[0] = '\0'; /* TODO attrs */ result = pthread_mutex_init(&mutex->info.posix_mutex, NULL); rv = (result == 0) ? os_resultSuccess : os_resultFail; } #ifdef OSPL_STRICT_MEM mutex->signature = OS_MUTEX_MAGIC_SIG; #endif return rv; }
/** \brief Initialize the mutex taking the mutex attributes * into account */ os_result os_mutexInit (os_mutex *mutex, const os_mutexAttr *mutexAttr) { Error err; os_mutexAttr defAttr; assert (mutex != NULL); #if !defined NDEBUG && !defined INTEGRITY assert(mutex->signature != OS_MUTEX_MAGIC_SIG); #endif if(!mutexAttr) { os_mutexAttrInit(&defAttr); mutexAttr = &defAttr; } if ( mutexAttr->scopeAttr == OS_SCOPE_SHARED) { Semaphore newsem; mutex->localsem = NULL; #ifndef NDEBUG checkMutexCache(mutex); #endif err = rsNewSemaphore(&newsem, &mutex->index, &mutex->uid); if ( err == Success ) { os_mutexAddToMap(mutex, newsem); } } else { err = CreateBinarySemaphore(&mutex->localsem); } #ifndef NDEBUG if ( err == Success ) { mutex->signature = OS_MUTEX_MAGIC_SIG; } #endif return ( err == Success ? os_resultSuccess : os_resultFail ); }
cms_soapThread cms_soapThreadNew( const c_char* name, cms_client client) { cms_soapThread thread; os_mutexAttr attr; os_condAttr condAttr; os_result osr; thread = NULL; osr = os_resultInvalid; if(client != NULL){ thread = cms_soapThread(os_malloc(C_SIZEOF(cms_soapThread))); if (thread != NULL) { cms_object(thread)->kind = CMS_SOAPTHREAD; cms_threadInit(cms_thread(thread), name, &client->service->configuration->clientScheduling); cms_thread(thread)->uri = os_strdup(cms_thread(client)->uri); thread->client = client; thread->soap = NULL; osr = os_mutexAttrInit(&attr); if(osr == os_resultSuccess){ attr.scopeAttr = OS_SCOPE_PRIVATE; osr = os_mutexInit(&thread->soapMutex, &attr); if(osr == os_resultSuccess){ osr = os_condAttrInit(&condAttr); if(osr == os_resultSuccess){ condAttr.scopeAttr = OS_SCOPE_PRIVATE; osr = os_condInit(&thread->condition, &thread->soapMutex, &condAttr ); } } } } } if (osr != os_resultSuccess) { cms_soapThreadFree(thread); return NULL; } return thread; }
u_result u_dispatcherInit( u_dispatcher _this) { v_observer ko; os_mutexAttr mutexAttr; u_result result = U_RESULT_OK; if (_this != NULL) { result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ko)); if(result == U_RESULT_OK) { assert(ko); os_mutexAttrInit(&mutexAttr); mutexAttr.scopeAttr = OS_SCOPE_PRIVATE; os_mutexInit(&_this->mutex,&mutexAttr); _this->listeners = NULL; _this->threadId = OS_THREAD_ID_NONE; _this->startAction = NULL; _this->stopAction = NULL; _this->actionData = NULL; _this->event = 0; u_entity(_this)->flags |= U_ECREATE_INITIALISED; result = u_entityRelease(u_entity(_this)); if (result != U_RESULT_OK) { OS_REPORT(OS_ERROR, "u_dispatcherInit", 0, "Release observer failed."); } } else { OS_REPORT(OS_WARNING,"u_dispatcherInit",0, "Failed to claim kernel object"); } } else { OS_REPORT(OS_ERROR,"u_dispatcherInit",0, "Illegal parameter."); result = U_RESULT_ILL_PARAM; } return result; }
c_syncResult c_mutexInit ( c_mutex *mtx, const c_mutexAttr attr) { os_result result; os_mutexAttr mutexAttr; os_mutexAttrInit (&mutexAttr); if (attr == PRIVATE_MUTEX) { mutexAttr.scopeAttr = OS_SCOPE_PRIVATE; } #ifdef NDEBUG result = os_mutexInit(mtx, &mutexAttr); #else mtx->owner = OS_THREAD_ID_NONE; result = os_mutexInit(&mtx->mtx, &mutexAttr); #endif if(result != os_resultSuccess) { OS_REPORT(OS_ERROR, "c_mutexInit", 0, "os_mutexInit operation failed."); assert(result == os_resultSuccess); } return result; }
int main( int argc, char* argv[]) { int result = 0; v_participantQos participantQos; u_result uresult; os_boolean success; v_subscriberQos subscriberQos; c_time resolution; c_base base; v_kernel kernel; /* Necessary to initialize the user layer. Do this just once per process.*/ mlv_init (); uresult = u_userInitialise(); mlv_setforreal (1); if(uresult == U_RESULT_OK){ /* Allocate default participant qos*/ participantQos = u_participantQosNew(NULL); { os_mutexAttr mattr; os_mutexAttrInit (&mattr); mattr.scopeAttr = OS_SCOPE_PRIVATE; os_mutexInit (&gluelock, &mattr); } if(participantQos){ if(argc > 1){ SERVICE_NAME = argv[1]; } if(argc > 2){ SERVICE_URI = argv[2]; } /*create participant*/ participant = u_participant(u_serviceNew( SERVICE_URI, 0, SERVICE_NAME, NULL, U_SERVICE_NETWORKING, (v_qos)participantQos)); if(participant){ struct cfgst *cfgst; ddsi2_participant_gid = u_entityGid (u_entity (participant)); /*Notify kernel that I am initializing. */ u_serviceChangeState(u_service(participant),STATE_INITIALISING); /*Start monitoring the splicedaemon state. I need to terminate if he says so*/ u_serviceWatchSpliceDaemon( u_service(participant), in_discoveryWatchSpliced, &terminate); if ((cfgst = config_init (participant, SERVICE_NAME)) != NULL) { unsigned rtps_flags = 0; struct nn_servicelease *servicelease; open_tracing_file (); /* Dependencies between default values is not handled automatically by the config processing (yet) */ if (config.many_sockets_mode) { if (config.max_participants == 0) config.max_participants = 100; } if (NN_STRICT_P) { /* Should not be sending invalid messages when strict */ config.respond_to_rti_init_zero_ack_with_invalid_heartbeat = 0; config.acknack_numbits_emptyset = 1; } config_print_and_free_cfgst (cfgst); servicelease = nn_servicelease_new (participant); nn_servicelease_start_renewing (servicelease); myNetworkId = getNetworkId (); u_entityAction(u_entity(participant), resolveKernelService, NULL); base = c_getBase(service); kernel = v_object(service)->kernel; rtps_init (base, kernel, config.domainId, config.participantIndex, rtps_flags, config.networkAddressString, config.peers); /* Initialize entity administration. */ success = in_entityAdminInit(participant); if(success){ /*Create subscriber to receive client writers' messages.*/ subscriberQos = u_subscriberQosNew(NULL); os_free(subscriberQos->partition); subscriberQos->partition = NULL; clientSubscriber = u_subscriberNew( participant, "clientSubscriber", subscriberQos, TRUE); if(clientSubscriber){ /*Create networkReader to be able to receive client writers' messages.*/ clientReader = u_networkReaderNew( clientSubscriber, "clientReader", NULL, TRUE); if(clientReader){ resolution.seconds = 0; resolution.nanoseconds = 10 * 1000 * 1000; /*10 ms*/ /*Create network queue*/ uresult = u_networkReaderCreateQueue( clientReader, 1000, 0, FALSE, FALSE, resolution, TRUE, &queueId, "DDSi"); if(uresult == U_RESULT_OK){ struct builtin_datareader_set drset; u_entityAction(u_entity(clientReader), resolveKernelReader, NULL); uresult = create_builtin_readers (&drset, participant); if (uresult == U_RESULT_OK) { u_serviceChangeState(u_service(participant),STATE_OPERATIONAL); uresult = attachAndMonitor(participant, &drset); if((uresult != U_RESULT_OK) && (uresult != U_RESULT_DETACHING)) { nn_log (LC_ERROR, "Abnormal termination...\n"); result = -1; } else { nn_log (LC_INFO, "Deleting entities...\n"); } destroy_builtin_readers (&drset); } else { nn_log (LC_FATAL, "Could not create subscription + readers for builtin topics.\n"); result = -1; } terminate = TRUE; v_networkReaderTrigger(vclientReader, queueId); os_threadWaitExit(clientWriterThread, NULL); } else { nn_log (LC_FATAL, "Could not create networkQueue.\n"); result = -1; } /*Clean up networkReader*/ os_mutexLock (&gluelock); u_networkReaderFree(clientReader); clientReader = NULL; vclientReader = NULL; os_mutexUnlock (&gluelock); } else { nn_log (LC_FATAL, "Could not create networkReader.\n"); result = -1; } /*Clean up subscriber*/ u_subscriberFree(clientSubscriber); } else { nn_log (LC_FATAL, "Could not create subscriber.\n"); result = -1; } /*Clean up entity administration*/ in_entityAdminDestroy(); } else { nn_log (LC_FATAL, "Could not initialize entity adminstration.\n"); result = -1; } /* RTPS layer now defines types, cleanup before detaching */ rtps_term(); /*Notify kernel that I've terminated*/ u_serviceChangeState(u_service(participant),STATE_TERMINATED); nn_servicelease_free (servicelease); /*Delete participant*/ uresult = u_serviceFree(u_service(participant)); if(uresult != U_RESULT_OK){ nn_log (LC_FATAL, "Deletion of participant failed.\n"); result = -1; } } else { nn_log (LC_FATAL, "Initialization of configuration failed.\n"); result = -1; } } else { nn_log (LC_FATAL, "Could not create participant.\n"); result = -1; } u_participantQosFree (participantQos); } else { nn_log (LC_FATAL, "Could not allocate participantQos.\n"); result = -1; } os_mutexDestroy (&gluelock); /* Detach user layer */ mlv_setforreal (0); uresult = u_userDetach(); mlv_fini (); if(uresult != U_RESULT_OK){ nn_log (LC_FATAL, "Detachment of user layer failed.\n"); result = -1; } } else { nn_log (LC_FATAL, "Initialization of user layer failed.\n"); result = -1; } nn_log (LC_INFO, "Finis.\n"); /* Must be really late, or nn_log becomes unhappy -- but it should be before os_osExit (which appears to be called from u_userExit(), which is not called by u_userDetach but by an exit handler, it appears.) */ config_fini (); return result; }
static void nw_serviceMain( const char *serviceName, const char *URI) { u_serviceManager serviceManager; os_time sleepTime; os_result waitResult; nw_termination terminate; os_mutexAttr termMtxAttr; os_condAttr termCvAttr; c_bool fatal = FALSE; v_duration leasePeriod; terminate.terminate = FALSE; os_mutexAttrInit( & termMtxAttr ); os_condAttrInit( & termCvAttr ); termMtxAttr.scopeAttr = OS_SCOPE_PRIVATE; termCvAttr.scopeAttr = OS_SCOPE_PRIVATE; os_mutexInit( &terminate.mtx, &termMtxAttr ); os_condInit( &terminate.cv, &terminate.mtx, &termCvAttr ); /* Create networking service with kernel */ service = u_serviceNew(URI, NW_ATTACH_TIMEOUT, serviceName, NULL, U_SERVICE_NETWORKING, NULL); /* Initialize configuration */ nw_configurationInitialize(service, serviceName, URI); /* Ask service manager for splicedaemon state */ serviceManager = u_serviceManagerNew(u_participant(service)); /* Create the controller which starts the updating */ /* and calls the listener on a fatal error */ controller = nw_controllerNew(service,controller_onfatal,&fatal); if (controller) { os_procAtExit(on_exit_handler); /* Start the actual engine */ NW_REPORT_INFO(1, "Networking started"); NW_TRACE(Mainloop, 1, "Networking started"); nw_controllerStart(controller); /* Change state for spliced */ u_serviceChangeState(service, STATE_INITIALISING); u_serviceChangeState(service, STATE_OPERATIONAL); /* Get sleeptime from configuration */ nw_retrieveLeaseSettings(&leasePeriod, &sleepTime); /*sleepTime.tv_sec = 1; */ /* Loop until termination is requested */ u_serviceWatchSpliceDaemon(service, nw_splicedaemonListener, &terminate); os_mutexLock( &terminate.mtx ); while ((!(int)terminate.terminate) && (!(int)fatal) && (!(int)f_exit)) { /* Assert my liveliness and the Splicedaemon's liveliness*/ u_serviceRenewLease(service, leasePeriod); /* Check if anybody is still remotely interested */ nw_controllerUpdateHeartbeats(controller); /* Wait before renewing again */ waitResult = os_condTimedWait( &terminate.cv, &terminate.mtx, &sleepTime ); if (waitResult == os_resultFail) { OS_REPORT(OS_CRITICAL, "nw_serviceMain", 0, "os_condTimedWait failed - thread will terminate"); fatal = TRUE; } /* QAC EXPECT 2467; Control variable, terminate, not modified inside loop. That is correct, it is modified by another thread */ } os_mutexUnlock( &terminate.mtx ); /* keep process here waiting for the exit processing */ while ((int)f_exit){os_nanoSleep(sleepTime);} if (!(int)fatal ) { leasePeriod.seconds = 20; leasePeriod.nanoseconds = 0; u_serviceRenewLease(service, leasePeriod); u_serviceChangeState(service, STATE_TERMINATING); nw_controllerStop(controller); nw_controllerFree(controller); controller = NULL; NW_REPORT_INFO(1, "Networking stopped"); NW_TRACE(Mainloop, 1, "Networking stopped"); } } if (!(int)fatal ) { nw_configurationFinalize(); /* Clean up */ u_serviceChangeState(service, STATE_TERMINATED); u_serviceManagerFree(serviceManager); u_serviceFree(service); } }
u_result u_userInitialise( void) { u_user u; u_result rm = U_RESULT_OK; os_mutexAttr mutexAttr; os_uint32 initCount; void* initUser; os_result osResult; os_signalHandlerExitRequestCallback exitRequestCallback; os_signalHandlerExceptionCallback exceptionCallback; initCount = pa_increment(&_ospl_userInitCount); /* If initCount == 0 then an overflow has occurred. * This can only realistically happen when u_userDetach() * is called more often than u_userInitialize(). */ assert(initCount != 0); os_osInit(); if (initCount == 1) { /* Will start allocating the object, so it should currently be empty. */ assert(user == NULL); /* Use indirection, as user != NULL is a precondition for user-layer * functions, so make sure it only holds true when the user-layer is * initialized. */ initUser = os_malloc(sizeof(C_STRUCT(u_user))); if (initUser == NULL) { /* Initialization failed, so decrement the initialization counter. */ pa_decrement(&_ospl_userInitCount); os_osExit(); OS_REPORT(OS_ERROR, "u_userInitialise", 0, "Allocation of user admin failed: out of memory."); rm = U_RESULT_OUT_OF_MEMORY; } else { u = u_user(initUser); os_mutexAttrInit(&mutexAttr); mutexAttr.scopeAttr = OS_SCOPE_PRIVATE; os_mutexInit(&u->mutex,&mutexAttr); osResult = os_signalHandlerNew(); if(osResult != os_resultSuccess) { /* Initialization did not succeed, undo increment and return error */ initCount = pa_decrement(&_ospl_userInitCount); OS_REPORT(OS_ERROR, "u_userInitialise", 0, "Failed to create the signal handler. No proper signal handling can be performed."); rm = U_RESULT_INTERNAL_ERROR; } else { exitRequestCallback = os_signalHandlerSetExitRequestCallback(u__userExitRequestCallbackWrapper); if(exitRequestCallback && exitRequestCallback != u__userExitRequestCallbackWrapper) { initCount = pa_decrement(&_ospl_userInitCount); OS_REPORT(OS_ERROR, "u_userInitialise", 0, "Replaced an exit request callback on the signal handler while this was not expected."); rm = U_RESULT_INTERNAL_ERROR; } if(rm == U_RESULT_OK){ exceptionCallback = os_signalHandlerSetExceptionCallback(u__userExceptionCallbackWrapper); if(exceptionCallback && exceptionCallback != u__userExceptionCallbackWrapper) { initCount = pa_decrement(&_ospl_userInitCount); OS_REPORT(OS_ERROR, "u_userInitialise", 0, "Replaced an exception callback on the signal handler while this was not expected."); rm = U_RESULT_INTERNAL_ERROR; } } if(rm == U_RESULT_OK) { u->domainCount = 0; u->protectCount = 0; u->detachThreadId = OS_THREAD_ID_NONE; /* This will mark the user-layer initialized */ user = initUser; } } } } else { if(user == NULL){ os_time sleep = {0, 100000}; /* 100ms */ /* Another thread is currently initializing the user-layer. Since * user != NULL is a precondition for calls after u_userInitialise(), * a sleep is performed, to ensure that (if succeeded) successive * user-layer calls will also actually pass.*/ os_nanoSleep(sleep); } if(user == NULL){ /* Initialization did not succeed, undo increment and return error */ initCount = pa_decrement(&_ospl_userInitCount); OS_REPORT_1(OS_ERROR,"u_userInitialise",0, "Internal error: User-layer should be initialized " "(initCount = %d), but user == NULL (waited 100ms).", initCount); rm = U_RESULT_INTERNAL_ERROR; } } return rm; }
/************************************************************** * 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; }
cms_client cms_clientNew( unsigned long ip, cms_service service, const c_char* uri) { cms_client client; os_result osr; os_mutexAttr attr; os_condAttr condAttr; client = cms_client(os_malloc(C_SIZEOF(cms_client))); cms_threadInit(cms_thread(client), "cms_client", &service->configuration->clientScheduling); if(client != NULL){ cms_object(client)->kind = CMS_CLIENT; cms_thread(client)->uri = os_strdup(uri); client->ip = ip; client->initCount = 0; client->service = service; client->internalFree = FALSE; osr = os_mutexAttrInit(&attr); if(osr == os_resultSuccess){ attr.scopeAttr = OS_SCOPE_PRIVATE; osr = os_mutexInit(&client->soapMutex, &attr); client->soapEnvs = c_iterNew(NULL); if(osr == os_resultSuccess){ osr = os_condAttrInit(&condAttr); if(osr == os_resultSuccess){ osr = os_mutexInit(&client->conditionMutex, &attr); if(osr == os_resultSuccess){ condAttr.scopeAttr = OS_SCOPE_PRIVATE; osr = os_condInit(&client->condition, &client->conditionMutex, &condAttr ); if(osr == os_resultSuccess){ osr = os_mutexInit(&client->threadMutex, &attr); if(osr == os_resultSuccess){ client->threads = c_iterNew(NULL); } else { cms_clientFree(client); } } } else { cms_clientFree(client); } } else { cms_clientFree(client); } } else { cms_clientFree(client); } } else { cms_clientFree(client); } } if(client == NULL){ if(service->configuration->verbosity >= 1){ OS_REPORT(OS_ERROR, CMS_CONTEXT, 0, "cms_clientNew: client could not be initialized."); } } return client; }
static c_bool cms_serviceInit( const c_char* name, cms_service cms) { c_bool success; c_char* config; os_mutexAttr attr; os_result osr; success = FALSE; if(cms != NULL) { success = cms_serviceInitConfiguration(name, cms); if(success == TRUE) { if(cms->configuration->verbosity >= 3) { config = cms_configurationFormat(cms->configuration); OS_REPORT(OS_INFO, CMS_CONTEXT, 0, config); os_free(config); } success = cms_serviceInitLease(cms); if(success == TRUE) { if(cms->configuration->verbosity >= 3) { OS_REPORT(OS_INFO, CMS_CONTEXT, 0, "cms_serviceInit: lease updater initialized."); } success = cms_serviceInitSOAP(cms); if(success == TRUE) { if(cms->configuration->verbosity >= 3) { OS_REPORT(OS_INFO, CMS_CONTEXT, 0, "cms_serviceInit: SOAP environment initialized."); } osr = os_mutexAttrInit(&attr); if(osr == os_resultSuccess) { attr.scopeAttr = OS_SCOPE_PRIVATE; osr = os_mutexInit(&cms->clientMutex, &attr); if(osr == os_resultSuccess) { if(cms->configuration->verbosity >= 4) { OS_REPORT(OS_INFO, CMS_CONTEXT, 0, "CMSOAPService initialized."); } success = cms_serviceInitGarbageCollector(cms); if(success == TRUE) { if(cms->configuration->verbosity >= 4) { OS_REPORT(OS_INFO, CMS_CONTEXT, 0, "cms_serviceInit: Garbage collector initialized."); } } } else { if(cms->configuration->verbosity >= 1) { OS_REPORT(OS_INFO, CMS_CONTEXT, 0, "cms_serviceInit: Client mutex could not be initialized."); } } } else { if(cms->configuration->verbosity >= 1) { OS_REPORT(OS_INFO, CMS_CONTEXT, 0, "cms_serviceInit: Client mutex could not be initialized."); } } } } } } return success; }