static void os__signalHandlerCallbackDeinit( os_signalHandlerCallbackInfo *_this) { os_signalHandlerExceptionCallbackInfo *ecb; os_signalHandlerExitRequestCallbackInfo *ercb; assert(_this); os_mutexLock(&_this->exceptionMtx); while((ecb = _this->exceptionCallbackInfo) != NULL){ _this->exceptionCallbackInfo = _this->exceptionCallbackInfo->next; os_signalHandlerExceptionRequestCallbackInfoDeinit(ecb); os_free(ecb); } os_mutexUnlock(&_this->exceptionMtx); os_mutexDestroy(&_this->exceptionMtx); os_mutexLock(&_this->exitRequestMtx); while((ercb = _this->exitRequestCallbackInfo) != NULL){ _this->exitRequestCallbackInfo = _this->exitRequestCallbackInfo->next; os_signalHandlerExitRequestCallbackInfoDeinit(ercb); os_free(ercb); } os_mutexUnlock(&_this->exitRequestMtx); os_mutexDestroy(&_this->exitRequestMtx); }
u_result u_readerDeinit( u_reader _this) { u_result result; u_query query; if (_this != NULL) { result = u_dispatcherDeinit(u_dispatcher(_this)); if (result == U_RESULT_OK) { os_mutexLock(&_this->mutex); if (_this->queries) { query = c_iterObject(_this->queries,0); while (query) { os_mutexUnlock(&_this->mutex); result = u_queryFree(query); os_mutexLock(&_this->mutex); query = c_iterObject(_this->queries,0); } c_iterFree(_this->queries); _this->queries = NULL; } os_mutexUnlock(&_this->mutex); os_mutexDestroy(&_this->mutex); } } else { result = U_RESULT_ILL_PARAM; } return result; }
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 void * dispatch( void *o) { u_dispatcher _this; v_observer claim; struct listenerExecArg arg; u_result result; _this = u_dispatcher(o); if (_this != NULL) { if (_this->startAction) { _this->startAction(_this, _this->actionData); } os_mutexLock(&_this->mutex); result = u_entityReadClaim(u_entity(_this), (v_entity*)(&claim)); if(result == U_RESULT_OK) { assert(claim); while ((!(_this->event & V_EVENT_OBJECT_DESTROYED)) && (_this->listeners != NULL) && (c_iterLength(_this->listeners) > 0)) { os_mutexUnlock(&_this->mutex); _this->event = v_observerWait(claim); os_mutexLock(&_this->mutex); if (!(_this->event & V_EVENT_OBJECT_DESTROYED)) { /* do not call listeners when object is destroyed! */ arg.mask = 0; arg.o = _this; c_iterWalk(_this->listeners, (c_iterWalkAction)listenerExecute, &arg); } } _this->threadId = OS_THREAD_ID_NONE; result = u_entityRelease(u_entity(_this)); if (result != U_RESULT_OK) { OS_REPORT(OS_ERROR, "u_dispatcher::dispatch", 0, "Release observer failed."); } } else { OS_REPORT(OS_WARNING, "u_dispatcher::dispatch", 0, "Failed to claim Dispatcher."); } os_mutexUnlock(&_this->mutex); if (_this->stopAction) { _this->stopAction(_this, _this->actionData); } } else { OS_REPORT(OS_ERROR, "u_dispatcher::dispatch", 0, "No dispatcher specified."); } return NULL; }
static void gapi_handleReadRelease ( gapi_handle handle) { os_mutexLock(&handle->read); handle->count--; if (handle->count == 0) { os_mutexUnlock(&handle->mutex); } os_mutexUnlock(&handle->read); }
u_result u_dispatcherDeinit( u_dispatcher _this) { v_observer ko; u_listener listener; os_threadId tid; u_result result = U_RESULT_OK; if (_this != NULL) { os_mutexLock(&_this->mutex); listener = u_listener(c_iterTakeFirst(_this->listeners)); while (listener != NULL) { u_listenerFree(listener); listener = u_listener(c_iterTakeFirst(_this->listeners)); } c_iterFree(_this->listeners); _this->listeners = NULL; /* Flags the dispatch thread to stop */ if (os_threadIdToInteger(_this->threadId) != 0U) { tid = _this->threadId; result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ko)); if(result != U_RESULT_OK) { /* This is a valid situation when a participant has been * freed prior to the freeing of a dispatcher within the * participant. */ os_mutexUnlock(&_this->mutex); os_threadWaitExit(tid, NULL); os_mutexDestroy(&_this->mutex); /*return U_RESULT_INTERNAL_ERROR;*/ } else { /* Wakeup the dispatch thread */ v_observerLock(ko); v_observerNotify(ko, NULL, NULL); v_observerUnlock(ko); u_entityRelease(u_entity(_this)); os_mutexUnlock(&_this->mutex); os_threadWaitExit(tid, NULL); os_mutexDestroy(&_this->mutex); } } else { os_mutexUnlock(&_this->mutex); os_mutexDestroy(&_this->mutex); } result = u_entityDeinit(u_entity(_this)); } else { OS_REPORT(OS_ERROR,"u_dispatcherDeinit",0, "Illegal parameter."); result = U_RESULT_ILL_PARAM; } return result; }
static void* cms_serviceCollectGarbage( void* arg) { cms_service cms; os_time update; cms_thread client; c_bool garbagePresent; cms = cms_service(arg); update.tv_sec = 2; update.tv_nsec = 0; garbagePresent = FALSE; /* * Keep going until service terminates AND all garbage has been collected. */ while((cms->terminate == FALSE) || (c_iterLength(cms->clientGarbage) != 0)) { os_mutexLock(&cms->clientMutex); client = cms_thread(c_iterTakeFirst(cms->clientGarbage)); os_mutexUnlock(&cms->clientMutex); while(client != NULL) { /* * Call threadFree and NOT clientFree on purpose. */ cms_threadFree(client); os_mutexLock(&cms->clientMutex); client = cms_thread(c_iterTakeFirst(cms->clientGarbage)); os_mutexUnlock(&cms->clientMutex); garbagePresent = TRUE; } if((c_iterLength(cms->clients) == 0) && (garbagePresent == TRUE)) { if(cms->configuration->verbosity >= 3) { OS_REPORT(OS_INFO, CMS_CONTEXT, 0, "No clients connected. Performing some garbage collecting..."); } cmx_deregisterAllEntities(); garbagePresent = FALSE; } if(cms->terminate == FALSE) { os_nanoSleep(update); } } c_iterFree(cms->clientGarbage); return NULL; }
static os_uint32 os__signalHandlerExitRequestCallbackInvoke( os_signalHandlerCallbackInfo *_this, os_callbackArg arg) { os_result osr; os_signalHandlerExitRequestCallbackInfo *cbExit; os_uint32 nrCallbacks = 0; assert(_this); os_mutexLock(&_this->exitRequestMtx); cbExit = _this->exitRequestCallbackInfo; /* Don't process handlers that have just been added, since we did not obtain * the proper context. */ while(cbExit){ os_signalHandlerThreadContextBuffer *contextBuffer = &(cbExit->contextBuffer[_this->exitRequestConsumptionIndex]); if (!cbExit->deregistered && cbExit->callbackExitRequest && (contextBuffer->contextAssigned || !cbExit->callbackGetThreadContext)) { osr = cbExit->callbackExitRequest(arg, contextBuffer->threadContext, cbExit->arg); nrCallbacks++; if(osr != os_resultSuccess) { OS_REPORT(OS_ERROR, "os_signalHandlerThread", 0, "Exit request-callback returned: %s", os_resultImage(osr)); } } contextBuffer->contextAssigned = FALSE; cbExit = cbExit->next; } _this->exitRequestConsumptionIndex++; os_mutexUnlock(&_this->exitRequestMtx); return nrCallbacks; }
c_char* cmx_readerSnapshotNew( const c_char* reader) { cmx_entity ce; c_char* result; struct cmx_readerSnapshotArg arg; os_mutex m; arg.success = FALSE; result = NULL; ce = cmx_entityClaim(reader); if(ce != NULL){ if (u_observableAction(u_observable(ce->uentity), cmx_readerSnapshotNewAction, &arg) == U_RESULT_OK) { if(arg.success == TRUE){ m = cmx_getReaderSnapshotMutex(); os_mutexLock(&m); readerSnapshots = c_iterInsert(readerSnapshots, arg.snapshot); os_mutexUnlock(&m); result = (c_char*)(os_malloc(60)); os_sprintf(result, "<readerSnapshot><id>"PA_ADDRFMT"</id></readerSnapshot>", (c_address)(arg.snapshot)); } } cmx_entityRelease(ce); } return result; }
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; }
void _ObjectRegistryFree ( _ObjectRegistry registry) { gapi_handle handle; int ptr; assert(registry); os_mutexLock(®istry->mutex); ptr = 0; while ( registry->trash[ptr] != NULL ) { gapi__free(registry->trash[ptr]); registry->trash[ptr] = NULL; ptr = (ptr + 1)%TRASH_LENGTH; } handle = c_iterTakeFirst(registry->active); while ( handle != NULL ) { handle->registry = NULL; gapi__free(handle); handle = c_iterTakeFirst(registry->active); } c_iterFree(registry->active); os_mutexUnlock(®istry->mutex); os_mutexDestroy(®istry->mutex); os_free(registry); }
static void* cms_soapThreadRun( void *thr) { cms_soapThread thread; struct soap* soap; c_char* result; thread = cms_soapThread(thr); os_mutexLock(&thread->soapMutex); while(cms_thread(thread)->terminate == FALSE){ if(thread->soap != NULL){ soap = thread->soap; thread->soap = NULL; cms_thread(thread)->results = NULL; soap->user = thr; soap_serve(soap); soap_destroy(soap); soap_end(soap); soap_done(soap); free(soap); u_entityAction( u_entity(thread->client->service->uservice), cms_soapThreadStatisticsRequestHandledAdd, thread->client->service); if(cms_thread(thread)->results != NULL){ result = (c_char*)(c_iterTakeFirst(cms_thread(thread)->results)); while(result){ os_free(result); result = (c_char*)(c_iterTakeFirst(cms_thread(thread)->results)); } c_iterFree(cms_thread(thread)->results); cms_thread(thread)->results = NULL; } } if(cms_thread(thread)->terminate == FALSE){ cms_thread(thread)->ready = TRUE; if(thread->client->service->configuration->verbosity >= 7){ OS_REPORT_1(OS_INFO, CMS_CONTEXT, 0, "soapThread '%s' ready.", cms_thread(thread)->name); } os_condWait(&thread->condition, &thread->soapMutex); if(thread->client->service->configuration->verbosity >= 7){ OS_REPORT_1(OS_INFO, CMS_CONTEXT, 0, "soapThread '%s' condition triggered.", cms_thread(thread)->name); } } } os_mutexUnlock(&thread->soapMutex); if(thread->client->service->configuration->verbosity >= 6){ OS_REPORT_1(OS_INFO, CMS_CONTEXT, 0, "soapThread '%s' ends.", cms_thread(thread)->name); } return NULL; }
/* This method will lock the user-layer and return the reference to the user-layer object if successful. * If this method returns NULL then the user-layer is either not initialized or * the process is detaching (process termination). */ static u_user u__userLock(void) { u_user u; os_result r = os_resultFail; u = u_user(user); if (u) { r = os_mutexLock(&u->mutex); if (r != os_resultSuccess) { /* The mutex is not valid so apparently the user-layer is either * destroyed or in process of destruction. */ u = NULL; } else if ((os_threadIdToInteger(u->detachThreadId) != 0) && (os_threadIdToInteger(u->detachThreadId) != os_threadIdToInteger(os_threadIdSelf()))) { /* Another thread is busy destroying the user-layer or the user- * layer is already destroyed. No access is allowed (anymore). * The user-layer object will be unlocked and will return null. */ os_mutexUnlock(&u->mutex); u = NULL; } } else { /* The user-layer is not created or destroyed i.e. non existent, therefore return null. */ OS_REPORT(OS_ERROR, "User Layer", 0, "User layer not initialized"); } return u; }
os_signalHandlerExceptionHandle os_signalHandlerRegisterExceptionCallback( os_signalHandlerExceptionCallback cbException, os_signalHandlerAllocThreadContextCallback cbAllocThreadContext, os_signalHandlerGetThreadContextCallback cbGetThreadContext, os_signalHandlerFreeThreadContextCallback cbFreeThreadContext, void * arg) { os_signalHandlerExceptionHandle ret; os_signalHandlerExceptionCallbackInfo *cb; os_signalHandlerCallbackInfo *_this = os__signalHandlerGetCallbackInfo(); ret.handle = cb = os_malloc(sizeof *cb); cb->callbackException = cbException; cb->callbackGetThreadContext = cbGetThreadContext; cb->callbackFreeThreadContext = cbFreeThreadContext; cb->threadContext = cbAllocThreadContext ? cbAllocThreadContext() : NULL; cb->arg = arg; os_mutexLock(&_this->exceptionMtx); cb->next = _this->exceptionCallbackInfo; _this->exceptionCallbackInfo = cb; os_mutexUnlock(&_this->exceptionMtx); return ret; }
os_signalHandlerExitRequestHandle os_signalHandlerRegisterExitRequestCallback( os_signalHandlerExitRequestCallback callback, os_signalHandlerAllocThreadContextCallback cbAllocThreadContext, os_signalHandlerGetThreadContextCallback cbGetThreadContext, os_signalHandlerFreeThreadContextCallback cbFreeThreadContext, void * arg) { os_signalHandlerExitRequestHandle ret; os_signalHandlerExitRequestCallbackInfo *cb; os_signalHandlerCallbackInfo *_this = os__signalHandlerGetCallbackInfo(); int i; ret.handle = cb = os_malloc(sizeof *cb); cb->callbackExitRequest = callback; cb->callbackGetThreadContext = cbGetThreadContext; cb->callbackFreeThreadContext = cbFreeThreadContext; for (i = 0; i < EXIT_REQUEST_BUFFER_SIZE; i++) { cb->contextBuffer[i].contextAssigned = FALSE; cb->contextBuffer[i].threadContext = cbAllocThreadContext ? cbAllocThreadContext() : NULL; } cb->arg = arg; cb->deregistered = OS_FALSE; os_mutexLock(&_this->exitRequestMtx); cb->next = _this->exitRequestCallbackInfo; _this->exitRequestCallbackInfo = cb; _this->nrExitRequestHandlers++; os_mutexUnlock(&_this->exitRequestMtx); return ret; }
u_result u_readerAddQuery( u_reader _this, u_query query) { os_result r; u_result result = U_RESULT_PRECONDITION_NOT_MET; if (_this && query) { if(u_entityOwner(u_entity(_this))) { r = os_mutexLock(&_this->mutex); if (r == os_resultSuccess) { _this->queries = c_iterInsert(_this->queries, query); os_mutexUnlock(&_this->mutex); result = U_RESULT_OK; } else { OS_REPORT(OS_WARNING, "u_readerAddQuery",0, "Failed to lock Reader."); result = U_RESULT_ILL_PARAM; } } else { result = U_RESULT_OK; } } else { OS_REPORT(OS_WARNING, "u_readerAddQuery",0, "Illegal parameter."); result = U_RESULT_ILL_PARAM; } return result; }
void os_signalHandlerUnregisterExceptionCallback( os_signalHandlerExceptionHandle eh) { os_signalHandlerExceptionCallbackInfo *cb, **cbPrev; os_signalHandlerCallbackInfo *_this; if(!eh.handle){ return; } _this = os__signalHandlerGetCallbackInfo(); os_mutexLock(&_this->exceptionMtx); cbPrev = &_this->exceptionCallbackInfo; cb = _this->exceptionCallbackInfo; while(cb != eh.handle){ cbPrev = &cb->next; cb = cb->next; } if(cb == eh.handle){ *cbPrev = cb->next; os_signalHandlerExceptionRequestCallbackInfoDeinit(cb); os_free(cb); } os_mutexUnlock(&_this->exceptionMtx); }
c_char* cmx_readerSnapshotNew( const c_char* reader) { u_entity e; c_char* result; struct cmx_readerSnapshotArg arg; os_mutex m; arg.success = FALSE; result = NULL; e = cmx_entityUserEntity(reader); if(e != NULL){ u_entityAction(e, cmx_readerSnapshotNewAction, &arg); if(arg.success == TRUE){ m = cmx_getReaderSnapshotMutex(); os_mutexLock(&m); readerSnapshots = c_iterInsert(readerSnapshots, arg.snapshot); os_mutexUnlock(&m); result = (c_char*)(os_malloc(60)); os_sprintf(result, "<readerSnapshot><id>"PA_ADDRFMT"</id></readerSnapshot>", (c_address)(arg.snapshot)); } } return result; }
cmx_readerSnapshot cmx_readerSnapshotLookup( const c_char* snapshot) { c_char* copy; c_char* temp; cmx_readerSnapshot s; os_mutex m; s = NULL; if(snapshot != NULL){ copy = (c_char*)(os_malloc(strlen(snapshot) + 1)); os_strcpy(copy, snapshot); temp = strtok((c_char*)copy, "</>"); /*<readerSnapshot>*/ temp = strtok(NULL, "</>"); /*<id>*/ temp = strtok(NULL, "</>"); /*... the pointer*/ if(temp != NULL){ sscanf(temp, PA_ADDRFMT, (c_address *)(&s)); m = cmx_getReaderSnapshotMutex(); os_mutexLock(&m); if(c_iterContains(readerSnapshots, s) == FALSE){ s = NULL; } os_mutexUnlock(&m); } os_free(copy); } return s; }
static void _ObjectRegistryDeregister ( _ObjectRegistry registry, gapi_handle handle) { assert(registry); assert(handle); os_mutexLock(®istry->mutex); c_iterTake(registry->active, handle); if (handle->kind != OBJECT_KIND_WAITSET) { if (registry->trash[registry->ptr]) { UT_TRACE("_ObjectRegistryDeregister(%x,%x) %d freed\n", (unsigned int)registry, (unsigned int)registry->trash[registry->ptr], ((gapi_handle)registry->trash[registry->ptr])->kind); gapi__free(registry->trash[registry->ptr]); } UT_TRACE("_ObjectRegistryDeregister(%x,%x) %d added to trash\n", (unsigned int)registry, (unsigned int)handle, handle->kind); registry->trash[registry->ptr] = handle; registry->ptr = (registry->ptr+1)%TRASH_LENGTH; } os_mutexUnlock(®istry->mutex); }
void cmx_readerSnapshotFree( c_char* snapshot) { cmx_readerSnapshot s; c_char* sample; os_mutex m; s = cmx_readerSnapshotLookup(snapshot); if(s != NULL){ m = cmx_getReaderSnapshotMutex(); os_mutexLock(&m); c_iterTake(readerSnapshots, s); os_mutexUnlock(&m); if(s->samples != NULL){ sample = (c_char*)(c_iterTakeFirst(s->samples)); while(sample != NULL){ os_free(sample); sample = (c_char*)(c_iterTakeFirst(s->samples)); } c_iterFree(s->samples); } os_free(s); os_free(snapshot); } }
void cmx_readerSnapshotFreeAll() { cmx_readerSnapshot s; c_char* sample; os_mutex m; m = cmx_getReaderSnapshotMutex(); os_mutexLock(&m); s = cmx_readerSnapshot(c_iterTakeFirst(readerSnapshots)); while(s != NULL){ if(s->samples != NULL){ sample = (c_char*)(c_iterTakeFirst(s->samples)); while(sample != NULL){ os_free(sample); sample = (c_char*)(c_iterTakeFirst(s->samples)); } c_iterFree(s->samples); } os_free(s); s = cmx_readerSnapshot(c_iterTakeFirst(readerSnapshots)); } os_mutexUnlock(&m); }
c_bool u_readerWalkQueries( u_reader _this, u_readerAction action, c_voidp actionArg) { c_bool result = U_RESULT_OK; os_result r; if (_this) { if(u_entityOwner(u_entity(_this))) { r = os_mutexLock(&_this->mutex); if (r == os_resultSuccess) { c_iterWalkUntil(_this->queries, (c_iterAction)action, actionArg); os_mutexUnlock(&_this->mutex); } else { OS_REPORT(OS_WARNING, "u_readerWalkQueries",0, "Failed to lock Reader."); result = U_RESULT_ILL_PARAM; } } } else { OS_REPORT(OS_WARNING, "u_readerWalkQueries",0, "No Reader specified."); result = U_RESULT_ILL_PARAM; } return result; }
c_long u_readerQueryCount( u_reader _this) { c_long length = -1; os_result r; if (_this) { if(u_entityOwner(u_entity(_this))) { r = os_mutexLock(&_this->mutex); if (r == os_resultSuccess) { length = c_iterLength(_this->queries); os_mutexUnlock(&_this->mutex); } else { OS_REPORT(OS_WARNING, "u_readerRemoveQuerie",0, "Failed to lock Reader."); } } } else { OS_REPORT(OS_WARNING, "u_readerQueryCount",0, "No Reader specified."); } return length; }
c_iter u_readerLookupQueries( u_reader _this) { c_iter queries = NULL; os_result r; if (_this) { if(u_entityOwner(u_entity(_this))) { r = os_mutexLock(&_this->mutex); if (r == os_resultSuccess) { c_iterWalk(_this->queries, collect_queries, &queries); os_mutexUnlock(&_this->mutex); } else { OS_REPORT(OS_WARNING, "u_readerLookupQueries",0, "Failed to lock Reader."); } } } else { OS_REPORT(OS_WARNING, "u_readerLookupQueries",0, "No Reader specified."); } return queries; }
c_bool u_readerContainsQuery( u_reader _this, u_query query) { c_bool found = FALSE; os_result r; if (_this && query) { if(u_entityOwner(u_entity(_this))) { r = os_mutexLock(&_this->mutex); if (r == os_resultSuccess) { found = c_iterContains(_this->queries,query); os_mutexUnlock(&_this->mutex); } else { OS_REPORT(OS_WARNING, "u_readerContainsQuery",0, "Failed to lock Reader."); } } } else { OS_REPORT(OS_WARNING, "u_readerRemoveQuery",0, "Illegal parameter."); } return found; }
void d_lockUnlock( d_lock lock) { if(lock){ os_mutexUnlock(&lock->lock); } }
/** * Sets the terminate-flag in the parallel demarshalling context and signals workers. * @param[in] pdc the parallel demarshalling context to signal * @pre dr_mutex locked */ static void pdc_terminateWorkers( DDS::ccpp_parDemContext *pdc) { if(pdc){ if(os_mutexLock(&pdc->superMtx) != os_resultSuccess) goto err_mutex_lock; if(os_mutexLock(&pdc->mtx) != os_resultSuccess) goto err_mutex_lock; pdc->terminate = 1U; os_condBroadcast(&pdc->startCnd); os_mutexUnlock(&pdc->mtx); os_mutexUnlock(&pdc->superMtx); } return; err_mutex_lock: OS_REPORT(OS_FATAL, "CCPP", 0, "Failed to claim mutex"); return; }
static u_result handlePublication( u_dataReader dataReader, c_long dataOffset, u_dataReader pDataReader, c_long pDataOffset) { v_dataReaderSample sample; u_result result; v_state state; v_message msg; struct v_publicationInfo *data; in_writer writer; in_participant participant; sample = NULL; result = u_dataReaderTake(dataReader, takeOne, &sample); while(sample && (result == U_RESULT_OK)){ state = v_readerSample(sample)->sampleState; msg = v_dataReaderSampleMessage(sample); data = (struct v_publicationInfo *)(C_DISPLACE(msg, dataOffset)); os_mutexLock (&gluelock); if(v_stateTest(state, L_DISPOSED)){ writer = in_writerLookup(&data->key); if(writer){ in_writerFree(writer, NULL); } else { nn_log (LC_WARNING, "handlePublication: disposed writer not found\n"); /*abort();*/ } } else { participant = in_participantLookup(&(data->participant_key)); if(!participant){ result = handleParticipant(pDataReader, pDataOffset, 1); if(result == U_RESULT_OK){ participant = in_participantLookup(&(data->participant_key)); } } if(participant){ in_writerNew(participant, data); } else { nn_log (LC_ERROR, "handlePublication: participant not found\n"); result = U_RESULT_INTERNAL_ERROR; /*abort();*/ } } os_mutexUnlock (&gluelock); c_free(sample); sample = NULL; result = u_dataReaderTake(dataReader, takeOne, &sample); } return result; }
static void* in_discoveryClientWriterMonitor( void* arg) { c_bool result, sendTo, more; v_message message; c_ulong sequenceNumber, priority; v_gid sender, receiver; c_time sendBefore; v_networkReaderEntry entry; os_time sleepTime; in_writer writer; os_boolean proceed = TRUE; v_networkReaderWaitResult nrwr; if(vclientQueue){ sleepTime.tv_sec = 0; sleepTime.tv_nsec = 50 * 1000 * 1000; while(!terminate && proceed){ nrwr = v_networkReaderWait(vclientReader, queueId, &vclientQueue); if((nrwr & V_WAITRESULT_MSGWAITING) == V_WAITRESULT_MSGWAITING){ more = TRUE; while(more){ result = v_networkQueueTakeFirst( vclientQueue, &message, &entry, &sequenceNumber, &sender, &sendTo, &receiver, &sendBefore, &priority, &more); if(result){ os_mutexLock (&gluelock); writer = in_writerLookup(&sender); if(writer){ if(v_nodeState(message) == L_WRITE){ proceed = in_writerWrite(writer, message); } else if(v_nodeState(message) == L_DISPOSED){ proceed = in_writerDispose(writer, message); } else if(v_nodeState(message) == L_UNREGISTER){ proceed = in_writerUnregister(writer, message); } } os_mutexUnlock (&gluelock); } } } else if((nrwr & V_WAITRESULT_TRIGGERED) == V_WAITRESULT_TRIGGERED){ in_printf(IN_LEVEL_FINER, "clientReader triggered...\n"); proceed = FALSE; } } } return NULL; }