void v_dataReaderSampleFree( v_dataReaderSample sample) { v_dataReaderInstance instance; v_index index; v_dataReader dataReader; v_message message; if (sample) { assert(C_TYPECHECK(sample, v_dataReaderSample)); if (c_refCount(sample) == 1) { /* Free the slave-samples as well */ instance = v_readerSample(sample)->instance; index = v_index(instance->index); dataReader = v_dataReader(index->reader); if (!v_readerSampleTestState(sample,L_READ)) { dataReader->notReadCount--; } #ifdef _SL_ if (dataReader->cachedSampleCount < 1000) { message = v_dataReaderSampleMessage(sample); c_free(message); v_dataReaderSampleTemplate(sample)->message = NULL; sample->prev = dataReader->cachedSample; dataReader->cachedSample = sample; dataReader->cachedSampleCount++; #else if (dataReader->cachedSample == NULL) { dataReader->cachedSample = sample; message = v_dataReaderSampleMessage(sample); c_free(message); v_dataReaderSampleTemplate(sample)->message = NULL; #endif } else { c_free(sample); } } else { c_free(sample); } } } void v_dataReaderSampleRemoveFromLifespanAdmin( v_dataReaderSample sample) { v_dataReaderInstance instance; v_index index; if (sample) { assert(C_TYPECHECK(sample, v_dataReaderSample)); instance = v_readerSample(sample)->instance; index = v_index(instance->index); v_lifespanAdminRemove(v_dataReaderEntry(index->entry)->lifespanAdmin, v_lifespanSample(sample)); } }
v_actionResult nb_topicObjectReaderAction( c_object o, c_voidp copyArg, /* c_iter<nb_topicObject> * */ nb_topicObjectAllocFunc allocFunc) { nb_topicObject to; v_actionResult result = 0; assert(allocFunc); if(o != NULL){ c_iter *iter; v_dataReaderSample s = v_dataReaderSample(o); v_message message = v_dataReaderSampleMessage(s); const void * from = C_DISPLACE (message, C_MAXALIGNSIZE(sizeof(*message))); iter = (c_iter*)copyArg; assert(iter); v_actionResultSet(result, V_PROCEED); to = allocFunc(); to->state = v_nodeState(message); to->writeTime = message->writeTime; nb_topicObjectCopyOut(to, from); *iter = c_iterAppend(*iter, to); } return result; }
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 u_result handleParticipant( u_dataReader dataReader, c_long dataOffset, int gluelockAlreadyHeld) { v_dataReaderSample sample; u_result result; v_state state; v_message msg; struct v_participantInfo *data; 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_participantInfo *)(C_DISPLACE(msg, dataOffset)); if (!gluelockAlreadyHeld) os_mutexLock (&gluelock); if(v_stateTest(state, L_DISPOSED)){ participant = in_participantLookup(&(data->key)); if(participant){ in_participantFree(participant, NULL); } } else { in_participantNew(data); } if (!gluelockAlreadyHeld) os_mutexUnlock (&gluelock); c_free(sample); sample = NULL; result = u_dataReaderTake(dataReader, takeOne, &sample); } return result; }
v_actionResult v_dataViewSampleReadTake( v_dataViewSample sample, v_readerSampleAction action, c_voidp arg, c_bool consume) { v_dataViewInstance instance; v_state state; v_state mask; v_actionResult result = 0; instance = v_dataViewSampleInstance(sample); state = v_instanceState(instance); mask = L_NEW | L_DISPOSED | L_NOWRITERS; /* Copy the value of instance state bits specified by the mask * to the sample state bits without affecting other bits. */ v_readerSampleSetState(sample,(state & mask)); v_readerSampleClearState(sample,(~state & mask)); /* If the status of the sample is READ by the previous read * operation and the flag is not yet set (specified by the * LAZYREAD flag) then correct the state before executing the * read action. */ if (v_readerSampleTestState(sample,L_LAZYREAD)) { v_readerSampleSetState(sample,L_READ); v_readerSampleClearState(sample,L_LAZYREAD); } /* An action routine is provided in case the sample needs to be returned * to the user. If an action routine is not provided, it means the sample * needs to be removed from the administration, so the reader should be * modified accordingly. That means the 'proceed' flag should be set in * that case. */ V_MESSAGE_STAMP(v_dataReaderSampleMessage(sample),readerReadTime); if (action) { /* Invoke the action routine with the typed sample. */ result = action(v_readerSample(sample), arg); } else { v_actionResultSet(result, V_PROCEED); } /* A sample is considered 'skipped' if the action routine invoked above * does not want to keep track of the sample (for example because it * didn't match its readerMasks). In that case, it sets the 'skip' flag * to true, which indicates that those samples should be considered * 'untouched' and therefore their instance and sample states should * not be modified. */ if (v_actionResultTestNot(result, V_SKIP)) { V_MESSAGE_STAMP(v_dataReaderSampleMessage(sample),readerCopyTime); V_MESSAGE_REPORT(v_dataReaderSampleMessage(sample), v_dataReaderInstanceDataReader(instance)); v_stateClear(v_instanceState(instance),L_NEW); if (!v_stateTest(v_readerSample(sample)->sampleState,L_READ)) { v_stateSet(v_readerSample(sample)->sampleState,L_LAZYREAD); } if (consume) { v_dataViewSampleListRemove(v_dataViewSampleList(sample)); v_dataViewSampleRemove(sample); } } return result; }