static os_result os__signalHandlerCallbackInit( os_signalHandlerCallbackInfo *_this) { os_result osr; assert(_this); osr = os_mutexInit(&_this->exitRequestMtx, NULL); if(osr != os_resultSuccess){ goto err_exitRequestMtxInit; } _this->exitRequestCallbackInfo = NULL; _this->nrExitRequestHandlers = 0; pa_st32(&_this->exitRequestInsertionIndex, 0xffffffff); _this->exitRequestConsumptionIndex = 0; osr = os_mutexInit(&_this->exceptionMtx, NULL); if(osr != os_resultSuccess){ goto err_exceptionMtxInit; } _this->exceptionCallbackInfo = NULL; return os_resultSuccess; /* Error handling */ err_exceptionMtxInit: os_mutexDestroy(&_this->exitRequestMtx); err_exitRequestMtxInit: return os_resultFail; }
_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; }
cms_client cms_clientNew( unsigned long ip, cms_service service) { cms_client client; os_result osr; client = os_malloc(sizeof *client); if(client != NULL){ if (cms_threadInit(cms_thread(client), "cms_client", &service->configuration->clientScheduling)) { cms_object(client)->kind = CMS_CLIENT; cms_thread(client)->did = service->did; cms_thread(client)->uri = os_strdup(service->uri); client->ip = ip; client->initCount = 0; client->service = service; client->internalFree = FALSE; osr = os_mutexInit(&client->soapMutex, NULL); client->soapEnvs = c_iterNew(NULL); if(osr == os_resultSuccess){ osr = os_mutexInit(&client->conditionMutex, NULL); if(osr == os_resultSuccess){ osr = os_condInit(&client->condition, &client->conditionMutex, NULL ); if(osr == os_resultSuccess){ osr = os_mutexInit(&client->threadMutex, NULL); 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); client = NULL; } } if(client == NULL){ if(service->configuration->verbosity >= 1){ OS_REPORT(OS_ERROR, CMS_CONTEXT, 0, "cms_clientNew: client could not be initialized."); } } return client; }
/** * 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; }
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; }
struct nn_servicelease *nn_servicelease_new (void (*renew_cb) (void *arg), void *renew_arg) { struct nn_servicelease *sl; sl = os_malloc (sizeof (*sl)); nn_retrieve_lease_settings (&sl->sleepTime); sl->keepgoing = -1; sl->renew_cb = renew_cb ? renew_cb : dummy_renew_cb; sl->renew_arg = renew_arg; sl->ts = NULL; if ((sl->av_ary = os_malloc (thread_states.nthreads * sizeof (*sl->av_ary))) == NULL) goto fail_vtimes; /* service lease update thread initializes av_ary */ if (os_mutexInit (&sl->lock, NULL) != os_resultSuccess) goto fail_lock; if (os_condInit (&sl->cond, &sl->lock, NULL) != os_resultSuccess) goto fail_cond; return sl; fail_cond: os_mutexDestroy (&sl->lock); fail_lock: os_free (sl->av_ary); fail_vtimes: os_free (sl); return NULL; }
u_waitset u_waitsetNew(void) { u_waitset _this = NULL; u_result result; result = u_userInitialise(); if (result == U_RESULT_OK) { _this = u_objectAlloc(sizeof(*_this), U_WAITSET, u__waitsetDeinitW, u__waitsetFreeW); _this->entries = NULL; _this->eventMask = V_EVENTMASK_ALL; _this->alive = TRUE; _this->waitBusy = FALSE; _this->detachCnt = 0; _this->multi_mode = OS_TRUE; _this->eventsEnabled = OS_TRUE; _this->notifyDetached = OS_FALSE; pa_st32(&_this->useCount, 0); os_mutexInit(&_this->mutex, NULL); os_condInit(&_this->cv, &_this->mutex, NULL); os_condInit(&_this->waitCv, &_this->mutex, NULL); } else { OS_REPORT(OS_ERROR, "u_waitsetNew", result, "Initialization failed. "); } return _this; }
DDS::Subscriber_impl::Subscriber_impl(gapi_subscriber handle) : DDS::Entity_impl(handle) { os_mutexAttr mutexAttr = { OS_SCOPE_PRIVATE }; if (os_mutexInit(&s_mutex, &mutexAttr) != os_resultSuccess) { OS_REPORT(OS_ERROR, "CCPP", 0, "Unable to create mutex"); } }
DDS::DomainParticipant_impl::DomainParticipant_impl(gapi_domainParticipant handle) : DDS::Entity_impl(handle) { os_mutexAttr mutexAttr = { OS_SCOPE_PRIVATE }; if (os_mutexInit(&dp_mutex, &mutexAttr) != os_resultSuccess) { OS_REPORT(OS_ERROR, "CCPP", 0, "Unable to create mutex"); } }
DDS::DataReaderView_impl::DataReaderView_impl(gapi_dataReaderView handle) : DDS::Entity_impl(handle) { os_mutexAttr mutexAttr = { OS_SCOPE_PRIVATE }; if (os_mutexInit(&drv_mutex, &mutexAttr) != os_resultSuccess) { OS_REPORT(OS_ERROR, "CCPP", 0, "Unable to create mutex"); } }
struct addrset *new_addrset (void) { struct addrset *as = os_malloc (sizeof (*as)); as->refc = 1; os_mutexInit (&as->lock, &gv.mattr); ut_avlCInit (&addrset_treedef, &as->ucaddrs); ut_avlCInit (&addrset_treedef, &as->mcaddrs); return as; }
DDS::Entity_impl::Entity_impl( gapi_entity handle ) : _gapi_self(handle) { os_mutexAttr mutexAttr = { OS_SCOPE_PRIVATE }; if (os_mutexInit(&e_mutex, &mutexAttr) != os_resultSuccess) { OS_REPORT(OS_ERROR, "CCPP", 0, "Unable to create mutex"); } }
DDS::Publisher_impl::Publisher_impl(gapi_publisher handle) : DDS::Entity_impl(handle) { os_mutexAttr mutexAttr = { OS_SCOPE_PRIVATE }; if (os_mutexInit(&p_mutex, &mutexAttr) != os_resultSuccess) { OS_REPORT(OS_ERROR, "DDS::Publisher_impl::Publisher_impl", 0, "Unable to create mutex"); } }
/** \brief Initialize the rwlock taking the rwlock attributes into account * * \b os_rwlockInit intializes the mutex which implements the rwlock */ os_result os_rwlockInit ( os_rwlock *rwlock, const os_rwlockAttr *rwlockAttr) { os_mutexAttr mutexAttr; mutexAttr.scopeAttr = rwlockAttr->scopeAttr; return os_mutexInit (rwlock, &mutexAttr); }
DDS::StatusCondition_impl::StatusCondition_impl( gapi_condition _gapi_handle ) : DDS::Condition_impl(_gapi_handle) { os_mutexAttr mutexAttr = { OS_SCOPE_PRIVATE }; if (os_mutexInit(&sc_mutex, &mutexAttr) != os_resultSuccess) { OS_REPORT(OS_ERROR, "CCPP", 0, "Unable to create mutex"); } }
DDS::ContentFilteredTopic_impl::ContentFilteredTopic_impl( gapi_contentFilteredTopic handle ) : DDS::TopicDescription_impl(handle) { os_mutexAttr mutexAttr = { OS_SCOPE_PRIVATE }; if (os_mutexInit(&cft_mutex, &mutexAttr) != os_resultSuccess) { OS_REPORT(OS_ERROR, "CCPP", 0, "Unable to create mutex"); } }
DDS::DataReader_impl::DataReader_impl( gapi_dataReader handle, void * (*pdcMainFnc)(void *) ) : DDS::Entity_impl(handle), pdc(NULL), workers(NULL), nrofWorkers(0) { os_mutexAttr mutexAttr = { OS_SCOPE_PRIVATE }; if (os_mutexInit(&dr_mutex, &mutexAttr) != os_resultSuccess) { OS_REPORT(OS_ERROR, "CCPP", 0, "Unable to create mutex"); } assert(pdcMainFnc); this->pdcMainFnc = pdcMainFnc; }
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; }
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; }
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; }
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; }
/************************************************************** * 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; }
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; }
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; }
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); } }
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; }
/** \brief Initialize cond module */ void os_condModuleInit (void) { os_mutexInit(&semCacheMutex, NULL); semCache = ut_tableNew (address_cmp, NULL, NULL, NULL, close_cached_item, NULL); }