コード例 #1
0
static void DaoxGraph_HandleGC( DaoValue *p, DList *values, DList *arrays, DList *maps, int remove )
{
	daoint i, n;
	DaoxGraph *self = (DaoxGraph*) p;
	DList_Append( arrays, self->nodes );
	DList_Append( arrays, self->edges );
	if( self->nodeType ) DList_Append( values, self->nodeType );
	if( self->edgeType ) DList_Append( values, self->edgeType );
	if( remove ){
		self->nodeType = NULL;
		self->edgeType = NULL;
		for(i=0,n=self->nodes->size; i<n; i++){
			DaoxNode *node = self->nodes->items.pgNode[i];
			if( node->ins ) DList_Clear( node->ins );
			DList_Clear( node->outs );
			node->graph = NULL;
		}
		for(i=0,n=self->edges->size; i<n; i++){
			DaoxEdge *edge = self->edges->items.pgEdge[i];
			edge->graph = NULL;
			edge->first = NULL;
			edge->second = NULL;
		}
	}
}
コード例 #2
0
ファイル: daoInterface.c プロジェクト: carriercomm/dao
static void DMap_SortMethods( DMap *hash, DList *methods )
{
	DMap *map = DMap_New( DAO_DATA_STRING, 0 );
	DString *name = DString_New();
	DNode *it;
	daoint i, n;
	for(it=DMap_First(hash); it; it=DMap_Next(hash,it)){
		if( it->value.pRoutine->overloads ){
			DRoutines *one = it->value.pRoutine->overloads;
			for(i=0,n=one->routines->size; i<n; i++){
				DaoRoutine *rout = one->routines->items.pRoutine[i];
				DString_Assign( name, rout->routName );
				DString_AppendChars( name, " " );
				DString_Append( name, rout->routType->name );
				DMap_Insert( map, name, (void*)rout );
			}
		}else{
			DaoRoutine *rout = it->value.pRoutine;
			DString_Assign( name, rout->routName );
			DString_AppendChars( name, " " );
			DString_Append( name, rout->routType->name );
			DMap_Insert( map, name, (void*)rout );
		}
	}
	DList_Clear( methods );
	for(it=DMap_First(map); it; it=DMap_Next(map,it))
		DList_Append( methods, it->value.pVoid );
	DMap_Delete( map );
	DString_Delete( name );
}
コード例 #3
0
ファイル: dao_test_base.c プロジェクト: daokoder/dao-modules
static void TEST_AssertError( DaoProcess *proc, DaoValue* p[], int N )
{
	DString *expected = p[0]->xString.value;
	DString *actual = NULL;
	DList *errors = proc->exceptions;
	DaoVmCode *sect = DaoProcess_InitCodeSection( proc, 0 );
	int catched = 0;
	int size = errors->size;
	if( sect == NULL ) return;
	DaoProcess_Execute( proc );
	if ( proc->status == DAO_PROCESS_ABORTED && errors->size > size ){
		DaoException *e = (DaoException*)&errors->items.pValue[errors->size - 1]->xCdata;
		if ( DString_Compare( expected, e->ctype->name ) != 0 )
			actual = DString_Copy( e->ctype->name );
		else
			catched = 1;
		DList_Clear( errors );
	}
	DaoProcess_PopFrame( proc );
	if ( !catched ){
		char buf[512];
		if ( actual ){
			snprintf( buf, sizeof(buf), "expected %s error, intercepted %s", expected->chars, actual->chars );
			DString_Delete( actual );
		}
		else
			snprintf( buf, sizeof(buf), "expected %s error, intercepted nothing", expected->chars );
		DaoProcess_RaiseError( proc, "Test::AssertError", buf );
	}
}
コード例 #4
0
ファイル: daoList.c プロジェクト: cgbystrom/scriptorium
void DList_Delete( DList *self )
{
#ifdef DAO_USE_GC_LOGGER
	daoCountArray --;
#endif
	DList_Clear( self );
	dao_free( self );
}
コード例 #5
0
ファイル: daoList.c プロジェクト: cgbystrom/scriptorium
void DList_Assign( DList *left, DList *right )
{
	daoint i;
	assert( left->type == right->type || (left->type == DAO_DATA_VALUE && right->type == 0) );

	if( left == right ) return;
	if( right->size == 0 ){
		DList_Clear( left );
		return;
	}
	if( left->type ){
		DList_Clear( left);
		for( i=0; i<right->size; i++ ) DList_Append( left, right->items.pVoid[i] );
	}else{
		DList_Resize( left, right->size, NULL );
		if( left->type == DAO_DATA_VALUE ) DaoGC_LockData();
		for( i=0; i<right->size; i++ ) left->items.pVoid[i] = right->items.pVoid[i];
		if( left->type == DAO_DATA_VALUE ) DaoGC_UnlockData();
	}
}
コード例 #6
0
ファイル: daoThread.c プロジェクト: carriercomm/dao
void DCondVar_BroadCast( DCondVar *self )
{
	DThread *thread;
	int i;
	DMutex_Lock( & self->thdMutex );
	for( i=0; i<self->thdWaiting->size; i++ ){
		thread = (DThread*) self->thdWaiting->items.pVoid[i];
		SetEvent( thread->condv.myCondVar );
	}
	DList_Clear( self->thdWaiting );
	DMutex_Unlock( & self->thdMutex );
}
コード例 #7
0
void DaoxNode_BreadthFirstSearch( DaoxNode *self, DList *nodes )
{
	daoint i, j;
	DList_Clear( nodes );
	DList_PushBack( nodes, self );
	self->state = 1;
	for(i=0; i<nodes->size; i++){
		DaoxNode *node = (DaoxNode*) nodes->items.pVoid[i];
		for(j=0; j<node->outs->size; j++){
			DaoxEdge *edge = (DaoxEdge*) node->outs->items.pVoid[j];
			DaoxNode *node2 = node == edge->first ? edge->second : edge->first;
			if( node2->state ) continue;
			node2->state = 1;
			DList_PushBack( nodes, node2 );
		}
	}
}
コード例 #8
0
void DaoxNode_DepthFirstSearch( DaoxNode *self, DList *nodes )
{
	DList *stack = DList_New(0);
	daoint j;
	DList_Clear( nodes );
	DList_PushBack( stack, self );
	while( stack->size ){
		DaoxNode *node = (DaoxNode*) DList_Back( stack );
		DList_PopBack( stack );
		if( node->state ) continue;
		node->state = 1;
		DList_PushBack( nodes, node );
		for(j=0; j<node->outs->size; j++){
			DaoxEdge *edge = (DaoxEdge*) node->outs->items.pVoid[j];
			DaoxNode *node2 = node == edge->first ? edge->second : edge->first;
			DList_PushBack( stack, node2 );
		}
	}
	DList_Delete( stack );
}
コード例 #9
0
ファイル: daoThread.c プロジェクト: carriercomm/dao
static void DaoMT_Functional( DaoProcess *proc, DaoValue *P[], int N, int F )
{
	DMutex mutex;
	DCondVar condv;
	DaoTaskData *tasks;
	DaoValue *param = P[0];
	DaoValue *result = NULL;
	DaoList *list = NULL;
	DaoArray *array = NULL;
	DaoVmCode *sect = NULL;
	DaoStackFrame *frame = DaoProcess_FindSectionFrame( proc );
	int i, entry, threads = P[1]->xInteger.value;
	daoint index = -1, status = 0, joined = 0;
	DNode *node = NULL;

	switch( F ){
	case DVM_FUNCT_MAP :
		if( param->type == DAO_ARRAY ){
			array = DaoProcess_PutArray( proc );
			result = (DaoValue*) array;
		}else{
			list = DaoProcess_PutList( proc );
			result = (DaoValue*) list;
		}
		break;
	case DVM_FUNCT_FIND : DaoProcess_PutValue( proc, dao_none_value ); break;
	}
	if( threads <= 0 ) threads = 2;
	if( frame != proc->topFrame->prev ){
		DaoProcess_RaiseError( proc, NULL, "Invalid code section from non-immediate caller" );
		return;
	}
	sect = DaoProcess_InitCodeSection( proc, 0 );
	if( sect == NULL ) return;
	if( list ){
		DList_Clear( list->value );
		if( param->type == DAO_LIST ) DList_Resize( list->value, param->xList.value->size, NULL );
		if( param->type == DAO_MAP ) DList_Resize( list->value, param->xMap.value->size, NULL );
#ifdef DAO_WITH_NUMARRAY
	}else if( array && F == DVM_FUNCT_MAP ){
		DaoArray_GetSliceShape( (DaoArray*) param, & array->dims, & array->ndim );
		DaoArray_ResizeArray( array, array->dims, array->ndim );
#endif
	}

	DMutex_Init( & mutex );
	DCondVar_Init( & condv );
	entry = proc->topFrame->entry;
	tasks = (DaoTaskData*) dao_calloc( threads, sizeof(DaoTaskData) );
	DaoProcess_PopFrame( proc );
	for(i=0; i<threads; i++){
		DaoTaskData *task = tasks + i;
		task->param = param;
		task->result = result;
		task->proto = proc;
		task->sect = sect;
		task->funct = F;
		task->entry = entry;
		task->first = i;
		task->step = threads;
		task->index = & index;
		task->node = & node;
		task->joined = & joined;
		task->condv = & condv;
		task->mutex = & mutex;
		task->clone = DaoVmSpace_AcquireProcess( proc->vmSpace );
		if( i ) DaoCallServer_AddTask( DaoMT_RunFunctional, task, task->clone );
	}
	DaoMT_RunFunctional( tasks );

	DMutex_Lock( & mutex );
	while( joined < threads ) DCondVar_TimedWait( & condv, & mutex, 0.01 );
	DMutex_Unlock( & mutex );

	for(i=0; i<threads; i++){
		DaoTaskData *task = tasks + i;
		DaoVmSpace_ReleaseProcess( proc->vmSpace, task->clone );
		status |= task->status;
	}
	if( F == DVM_FUNCT_FIND ){
		DaoTuple *tuple = DaoProcess_PutTuple( proc, 2 );
		if( param->type == DAO_LIST && index != -1 ){
			DaoValue **items = param->xList.value->items.pValue;
			GC_Assign( & tuple->values[1], items[index] );
			tuple->values[0]->xInteger.value = index;
		}else if( param->type == DAO_MAP && node ){
			GC_Assign( & tuple->values[0], node->key.pValue );
			GC_Assign( & tuple->values[1], node->value.pValue );
		}
	}
	if( status ) DaoProcess_RaiseError( proc, NULL, "code section execution failed!" );
	DMutex_Destroy( & mutex );
	DCondVar_Destroy( & condv );
	dao_free( tasks );
}