DaoState* DaoState_New( DaoType *type, DaoValue *state )
{
	DaoState *res = dao_malloc( sizeof(DaoState) );
	DaoCstruct_Init( (DaoCstruct*)res, type );
	DaoValue_Copy( state, &res->state );
	res->lock = DaoMutex_New();
	res->defmtx = DaoMutex_New();
	res->demands = DaoMap_New( 0 );
	DaoGC_IncRC( (DaoValue*)res->lock );
	DaoGC_IncRC( (DaoValue*)res->defmtx );
	DaoGC_IncRC( (DaoValue*)res->demands );
	return res;
}
DaoQueue* DaoQueue_New( DaoType *type, int capacity )
{
	DaoQueue *res = (DaoQueue*)dao_malloc( sizeof(DaoQueue) );
	DaoCstruct_Init( (DaoCstruct*)res, type );
	res->head = res->tail = NULL;
	res->size = 0;
	res->capacity = ( ( capacity < 0 )? 0 : capacity );
	res->mtx = DaoMutex_New();
	res->pushvar = DaoCondVar_New();
	res->popvar = DaoCondVar_New();
	DaoGC_IncRC( (DaoValue*)res->mtx );
	DaoGC_IncRC( (DaoValue*)res->pushvar );
	DaoGC_IncRC( (DaoValue*)res->popvar );
	return res;
}
Exemple #3
0
static void DaoMutex_Lib_Mutex( DaoProcess *proc, DaoValue *par[], int N )
{
	DaoMutex *mutex = DaoMutex_New();
	DaoProcess_PutValue( proc, (DaoValue*) mutex );
}