Beispiel #1
0
ScarabDatum *scarab_destroy_lock(ScarabDatum *datum){
	#ifdef THREAD_SAFE_SCARAB_DATUM
		if(datum != NULL && datum->mutex != NULL){
			pthread_mutex_destroy(datum->mutex);
			scarab_mem_free(datum->mutex);
		}
	#endif
}
Beispiel #2
0
DataFileIndexer::DataFileIndexer(const boost::filesystem::path &data_file) :
    number_of_events(0),
    events_per_block(0)
{
    const std::string uri("ldobinary:file_readonly://" + data_file.string());
    session = scarab_session_connect(uri.c_str());
    if ((session == NULL) || (scarab_session_geterr(session) != 0)) {
        scarab_mem_free(session);
		throw DataFileIndexerError(boost::format("Cannot open file \"%s\"") % data_file.string());
    }
}
Beispiel #3
0
void scarab_free_datum(ScarabDatum *d){
	
	int i;
	
	if(d == NULL) return;
	
	// Unnecessary checking?  Actually accounts for 16% of the time in this
	// call, and this call is made frequently...
	//if(d->mutex != NULL){
	pthread_mutex_lock(d->mutex); // lock just THIS mutex
	//} else {
		//???
	//}
	//scarab_lock_datum(d);

	// One fewer reference to this object
	d->ref_count--;
	
	// If the thing is no longer referenced, kill it
	if((d->ref_count) == 0){
	
		switch (d->type) 
		{
			case SCARAB_DICT: 
				// free sub-data
				for(i = 0; i < d->data.dict->tablesize; i++){
					scarab_free_datum(d->data.dict->keys[i]);
					scarab_free_datum(d->data.dict->values[i]);
				}
				
				// Free the parts
				scarab_mem_free(d->data.dict->keys);
				scarab_mem_free(d->data.dict->values);
				
				scarab_mem_free(d->data.dict);
					
				break;
			case SCARAB_LIST:
				// free sub-data
				for(i = 0; i < d->data.list->size; i++){
					scarab_free_datum(d->data.list->values[i]);
				}

				// free parts
				scarab_mem_free(d->data.list->values);
				scarab_mem_free(d->data.list);

				break;
			case SCARAB_FLOAT_OPAQUE:
			case SCARAB_OPAQUE:
				
				// free opaque data
				if(d->data.opaque.data != NULL){
					scarab_mem_free(d->data.opaque.data );
				}
				break;
			default:
				
				break;
		}
		
		//scarab_unlock_datum(d);
		//scarab_destroy_lock(d);
		
		// Take the lock out of the ScarabDatum, we want to hang onto it
		// until we're done
		pthread_mutex_t *lock = d->mutex;
		scarab_mem_free(d);
		
		// now, release the lock and destroy it
		pthread_mutex_unlock(lock);
		pthread_mutex_destroy(lock);
		free(lock);
		
		return;
	}	
	
// Unnecessary checking?
//	if(d->mutex != NULL){
		pthread_mutex_unlock(d->mutex);
//	} else {
		//???
//	}
	//scarab_unlock_datum(d);
	
		
}
Beispiel #4
0
void scarab_free_datum(ScarabDatum *d){
	
	int i;
	
	if(d == NULL) return;
	
#ifdef THREAD_SAFE_SCARAB_DATUM
	pthread_mutex_lock(d->mutex);
#endif

	// One fewer reference to this object
	d->ref_count--;
	
	// If the thing is no longer referenced, kill it
	if((d->ref_count) == 0){
	
		switch (d->type) 
		{
			case SCARAB_DICT: 
				// free sub-data
				for(i = 0; i < d->data.dict->tablesize; i++){
					scarab_free_datum(d->data.dict->keys[i]);
					scarab_free_datum(d->data.dict->values[i]);
				}
				
				// Free the parts
				scarab_mem_free(d->data.dict->keys);
				scarab_mem_free(d->data.dict->values);
				
				scarab_mem_free(d->data.dict);
					
				break;
			case SCARAB_LIST:
				// free sub-data
				for(i = 0; i < d->data.list->size; i++){
					scarab_free_datum(d->data.list->values[i]);
				}

				// free parts
				scarab_mem_free(d->data.list->values);
				scarab_mem_free(d->data.list);

				break;
			case SCARAB_OPAQUE:
				
				// free opaque data
				if(d->data.opaque.data != NULL){
					scarab_mem_free(d->data.opaque.data );
				}
				break;
			default:
				
				break;
		}
		
#ifdef THREAD_SAFE_SCARAB_DATUM
		// Take the lock out of the ScarabDatum, we want to hang onto it
		// until we're done
		pthread_mutex_t *lock = d->mutex;
#endif
        
		scarab_mem_free(d);
		
#ifdef THREAD_SAFE_SCARAB_DATUM
		// now, release the lock and destroy it
		pthread_mutex_unlock(lock);
		pthread_mutex_destroy(lock);
		scarab_mem_free(lock);
#endif
		
		return;
	}	
	
#ifdef THREAD_SAFE_SCARAB_DATUM
	pthread_mutex_unlock(d->mutex);
#endif
}