Ejemplo n.º 1
0
static void InsertKeyValue( DaoProcess *proc, DaoMap *mulmap, DaoMap *map, DaoValue *vk, DaoValue *vv )
{
    DaoValue *val, *vlist;
    DaoMap_Insert( map, vk, vv );
    if( mulmap ) {
        val = DaoMap_GetValue( mulmap, vk );
        if( val == NULL ) {
            vlist = (DaoValue*) DaoProcess_NewList( proc );
            DaoMap_Insert( mulmap, vk, vlist );
            val = DaoMap_GetValue( mulmap, vk );
        }
        DaoList_PushBack( DaoValue_CastList( val ), vv );
    }
}
Ejemplo n.º 2
0
static void DaoState_WaitFor2( DaoProcess *proc, DaoValue *p[], int N )
{
	DaoState *self = (DaoState*)DaoValue_CastCstruct( p[0], NULL );
	int eq = 0, res = 1;
	DaoValue *state = p[1];
	float timeout;
	DaoCondVar *condvar = NULL;
	DaoMutex_Lock( self->lock );
	if( !DaoValue_Compare( self->state, state ) )
		eq = 1;
	else{
		condvar = (DaoCondVar*)DaoMap_GetValue( self->demands, state );
		if( !condvar ){
			condvar = DaoCondVar_New();
			DaoMap_Insert( self->demands, state, (DaoValue*)condvar );
		}
	}
	DaoMutex_Unlock( self->lock );
	if( !eq ){
		DaoMutex_Lock( self->defmtx );
		timeout = DaoValue_TryGetFloat( p[2] );
		if( timeout > 0 )
			do
				res = !DaoCondVar_TimedWait( condvar, self->defmtx, timeout );
			while( res && DaoValue_Compare( self->state, state ) );
		else if( timeout == 0 )
			res = 0;
		else
			do
				DaoCondVar_Wait( condvar, self->defmtx );
			while( DaoValue_Compare( self->state, state ) );
		DaoMutex_Unlock( self->defmtx );
	}
	DaoProcess_PutInteger( proc, res );
}