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 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; }