本文整理汇总了C++中DCondVar_Signal函数的典型用法代码示例。如果您正苦于以下问题:C++ DCondVar_Signal函数的具体用法?C++ DCondVar_Signal怎么用?C++ DCondVar_Signal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DCondVar_Signal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DaoCallServer_AddTimedWait
void DaoCallServer_AddTimedWait( DaoProcess *wait, DaoTaskEvent *event, double timeout )
{
DaoCallServer *server = daoCallServer;
/*
// The "wait" process may not be running in the thread pool,
// so it may have not been added to active process list.
// It is necessary to add it to the active list now,
// to avoid it being activated immediately after it is blocked.
// Activating it immediately may cause a race condition,
// because it may have not been blocked completely
// (namely, it may be still running).
*/
DaoCallServer_MarkActiveProcess( wait, 1 );
DMutex_Lock( & server->mutex );
if( timeout >= 1E-27 ){
server->timestamp.real = timeout + Dao_GetCurrentTime();
server->timestamp.imag += 1;
event->expiring = server->timestamp.real;
DMap_Insert( server->waitings, & server->timestamp, event );
DMap_Insert( server->pending, event, NULL );
DCondVar_Signal( & server->condv2 );
}else{
event->expiring = -1.0;
DaoCallServer_AddEvent( event );
DCondVar_Signal( & server->condv );
}
DMutex_Unlock( & server->mutex );
}
示例2: DaoCallServer_AddTimedWait
void DaoCallServer_AddTimedWait( DaoProcess *wait, DaoTaskEvent *event, double timeout )
{
DaoCallServer *server;
if( daoCallServer == NULL ) DaoCallServer_Init( mainVmSpace );
server = daoCallServer;
DMutex_Lock( & server->mutex );
if( timeout >= 1E-27 ){
server->timestamp.value.real = timeout + Dao_GetCurrentTime();
server->timestamp.value.imag += 1;
event->expiring = server->timestamp.value.real;
DMap_Insert( server->waitings, & server->timestamp, event );
DMap_Insert( server->pending, event, NULL );
DCondVar_Signal( & server->condv2 );
}else{
event->expiring = -1.0;
DaoCallServer_AddEvent( event );
DCondVar_Signal( & server->condv );
}
if( wait->condv ){
/*
// Need to suspend the native thread, for suspending inside code sections
// for functional methods such as std.iterate(), mt.iterate() etc:
*/
wait->pauseType = DAO_PAUSE_NATIVE_THREAD;
if( timeout > 0 ){
DCondVar_TimedWait( wait->condv, & server->mutex, timeout );
}else{
DCondVar_Wait( wait->condv, & server->mutex );
}
wait->status = DAO_PROCESS_RUNNING;
}
DMutex_Unlock( & server->mutex );
}
示例3: DaoCallServer_CheckEvent
static int DaoCallServer_CheckEvent( DaoTaskEvent *event, DaoFuture *fut, DaoChannel *chan )
{
DaoTaskEvent event2 = *event;
daoint i, move = 0, closed = 0;
switch( event->type ){
case DAO_EVENT_WAIT_TASKLET :
move = event->future->precond == fut;
if( event->future->process->condv ) DCondVar_Signal( event->future->process->condv );
break;
case DAO_EVENT_WAIT_RECEIVING :
if( event->channel == chan ){
move = chan->buffer->size > 0;
move |= chan->cap <= 0 && chan->buffer->size == 0;
}
break;
case DAO_EVENT_WAIT_SENDING :
move = event->channel == chan && chan->buffer->size < chan->cap;
break;
case DAO_EVENT_WAIT_SELECT :
if( event->channels == NULL ) return 0;
for(i=0; i<event->channels->size; ++i){
DaoChannel *chan = (DaoChannel*) event->channels->items.pValue[i];
if( chan->buffer->size ){
return 1;
}else if( chan->cap <= 0 ){
closed += 1;
}
}
move = closed == event->channels->size;
break;
default: break;
}
return move;
}
示例4: CHANNEL_Send
static void CHANNEL_Send( DaoProcess *proc, DaoValue *par[], int N )
{
DaoValue *data;
DaoFuture *future = DaoProcess_GetInitFuture( proc );
DaoChannel *self = (DaoChannel*) par[0];
float timeout = par[2]->xFloat.value;
if( DaoProcess_CheckCB( proc, "cannot send/block inside code section method" ) ) return;
if( self->cap <= 0 ){
DaoProcess_RaiseException( proc, DAO_ERROR_PARAM, "channel is closed" );
return;
}
data = DaoValue_DeepCopy( par[1] );
if( data == NULL ){
DaoProcess_RaiseException( proc, DAO_ERROR_PARAM, "invalid data for the channel" );
return;
}
//printf( "CHANNEL_Send: %p\n", event );
DMutex_Lock( & daoCallServer->mutex );
DArray_Append( self->buffer, data );
DaoChannel_ActivateEvent( self, DAO_EVENT_WAIT_RECEIVING );
DaoChannel_ActivateEvent( self, DAO_EVENT_WAIT_SELECT );
DCondVar_Signal( & daoCallServer->condv );
DMutex_Unlock( & daoCallServer->mutex );
if( self->buffer->size >= self->cap ){
DaoTaskEvent *event = DaoCallServer_MakeEvent();
DaoTaskEvent_Init( event, DAO_EVENT_WAIT_SENDING, DAO_EVENT_WAIT, future, self );
proc->status = DAO_PROCESS_SUSPENDED;
proc->pauseType = DAO_PAUSE_CHANNEL_SEND;
DaoCallServer_AddTimedWait( proc, event, timeout );
}
}
示例5: DThread_ResumeVM
void DThread_ResumeVM( DThread *another )
{
another->vmpause = 0;
DMutex_Lock( & another->mutex );
DCondVar_Signal( & another->condv );
DMutex_Unlock( & another->mutex );
}
示例6: CHANNEL_Select
void CHANNEL_Select( DaoProcess *proc, DaoValue *par[], int n )
{
DaoTaskEvent *event = NULL;
DaoFuture *future = DaoProcess_GetInitFuture( proc );
DaoList *channels = (DaoList*) par[0];
float timeout = par[1]->xFloat.value;
daoint i, size = DaoList_Size( channels );
for(i=0; i<size; ++i){
DaoValue *value = DaoList_GetItem( channels, i );
if( DaoValue_CheckCtype( value, dao_type_channel ) == 0 ){
DaoProcess_RaiseException( proc, DAO_ERROR_PARAM, "invalid type selection" );
return;
}
}
event = DaoCallServer_MakeEvent();
DaoTaskEvent_Init( event, DAO_EVENT_WAIT_SELECT, DAO_EVENT_WAIT, future, NULL );
event->channels = DArray_Copy( & channels->items );
proc->status = DAO_PROCESS_SUSPENDED;
proc->pauseType = DAO_PAUSE_CHANFUT_SELECT;
DaoCallServer_AddTimedWait( proc, event, timeout );
/* Message may have been sent before this call: */
DMutex_Lock( & daoCallServer->mutex );
DaoChannel_ActivateEvent( NULL, DAO_EVENT_WAIT_SELECT );
DCondVar_Signal( & daoCallServer->condv );
DMutex_Unlock( & daoCallServer->mutex );
}
示例7: DaoMT_Select
void DaoMT_Select( DaoProcess *proc, DaoValue *par[], int n )
{
DNode *it;
DaoTaskEvent *event = NULL;
DaoFuture *future = DaoProcess_GetInitFuture( proc );
DaoMap *selects = (DaoMap*) par[0];
float timeout = par[1]->xFloat.value;
for(it=DaoMap_First(selects); it; it=DaoMap_Next(selects,it)){
DaoValue *value = it->key.pValue;
int isfut = DaoValue_CheckCtype( value, dao_type_future );
int ischan = DaoValue_CheckCtype( value, dao_type_channel );
if( isfut == 0 && ischan == 0 ){
DaoProcess_RaiseError( proc, "Param", "invalid type selection" );
return;
}
}
event = DaoCallServer_MakeEvent();
DaoTaskEvent_Init( event, DAO_EVENT_WAIT_SELECT, DAO_EVENT_WAIT, future, NULL );
GC_Assign( & event->selects, selects );
proc->status = DAO_PROCESS_SUSPENDED;
proc->pauseType = DAO_PAUSE_CHANFUT_SELECT;
DaoCallServer_AddTimedWait( proc, event, timeout );
/* Message may have been sent before this call: */
DMutex_Lock( & daoCallServer->mutex );
DaoChannel_ActivateEvent( NULL, DAO_EVENT_WAIT_SELECT );
DCondVar_Signal( & daoCallServer->condv );
DMutex_Unlock( & daoCallServer->mutex );
}
示例8: DaoFuture_ActivateEvent
/*
// Activate all events waiting on a future value:
*/
void DaoFuture_ActivateEvent( DaoFuture *self )
{
DaoCallServer *server = daoCallServer;
DList *array = DList_New(0);
DNode *node;
daoint i;
DMutex_Lock( & server->mutex );
for(i=0; i<server->events2->size; ++i){
DaoTaskEvent *event = (DaoTaskEvent*) server->events2->items.pVoid[i];
if( DaoCallServer_CheckEvent( event, self, NULL ) ){
event->state = DAO_EVENT_RESUME;
DList_Append( server->events, event );
DList_Erase( server->events2, i, 1 );
i -= 1;
}
}
for(node=DMap_First(server->waitings); node; node=DMap_Next(server->waitings,node)){
DaoTaskEvent *event = (DaoTaskEvent*) node->value.pValue;
/* remove from timed waiting list: */
if( DaoCallServer_CheckEvent( event, self, NULL ) ){
event->state = DAO_EVENT_RESUME;
DList_Append( server->events, event );
DList_Append( array, node->key.pVoid );
}
}
for(i=0; i<array->size; i++) DMap_Erase( server->waitings, array->items.pVoid[i] );
DCondVar_Signal( & server->condv );
DMutex_Unlock( & server->mutex );
DList_Delete( array );
}
示例9: DThread_Exit
void DThread_Exit( DThread *thd )
{
thd->running = 0;
DCondVar_Signal( & thd->condv );
if( thd->cleaner ) (*(thd->cleaner))( thd->taskArg );
thd->myThread = NULL; /* it will be closed by _endthread() */
_endthread();
}
示例10: DaoCallServer_Add
static void DaoCallServer_Add( DaoTaskEvent *event )
{
DaoCallServer *server = daoCallServer;
DMutex_Lock( & server->mutex );
DaoCallServer_AddEvent( event );
DCondVar_Signal( & server->condv );
DMutex_Unlock( & server->mutex );
DaoCallServer_TryAddThread( NULL, NULL, server->pending->size );
}
示例11: DaoChannel_Send
void DaoChannel_Send( DaoChannel *self, DaoValue *data )
{
DMutex_Lock( & daoCallServer->mutex );
DList_Append( self->buffer, data );
DaoChannel_ActivateEvent( self, DAO_EVENT_WAIT_RECEIVING );
DaoChannel_ActivateEvent( self, DAO_EVENT_WAIT_SELECT );
DCondVar_Signal( & daoCallServer->condv );
DMutex_Unlock( & daoCallServer->mutex );
}
示例12: DaoCallServer_ActivateEvents
static void DaoCallServer_ActivateEvents()
{
DaoCallServer *server = daoCallServer;
char message[128];
daoint i, j, count = 0;
if( server->finishing == 0 ) return;
if( server->idle != server->total ) return;
if( server->events->size != 0 ) return;
if( server->events2->size == 0 ) return;
#ifdef DEBUG
sprintf( message, "WARNING: try activating events (%i,%i,%i,%i)!\n", server->total,
server->idle, (int)server->events->size, (int)server->events2->size );
DaoStream_WriteChars( mainVmSpace->errorStream, message );
#endif
for(i=0; i<server->events2->size; ++i){
DaoTaskEvent *event = (DaoTaskEvent*) server->events2->items.pVoid[i];
DaoChannel *chan = event->channel;
DaoFuture *fut = event->future;
int move = 0, closed = 0;
switch( event->type ){
case DAO_EVENT_WAIT_TASKLET :
move = fut->precond == NULL || fut->precond->state == DAO_CALL_FINISHED;
break;
case DAO_EVENT_WAIT_RECEIVING :
move = chan->buffer->size > 0;
if( chan->cap <= 0 && chan->buffer->size == 0 ) move = 1;
break;
case DAO_EVENT_WAIT_SENDING :
move = chan->buffer->size < chan->cap;
break;
case DAO_EVENT_WAIT_SELECT :
if( event->selects == NULL ) continue;
move = DaoTaskEvent_CheckSelect( event );
break;
default: break;
}
if( move ){
DList_Append( server->events, event );
DList_Erase( server->events2, i, 1 );
count += 1;
i -= 1;
}
}
DCondVar_Signal( & server->condv );
if( count == 0 ){
DaoStream *stream = mainVmSpace->errorStream;
DaoStream_WriteChars( stream, "ERROR: All tasklets are suspended - deadlock!\n" );
#if DEBUG
fprintf( stderr, "ERROR: All tasklets are suspended - deadlock!\n" );
#endif
exit(1);
}
}
示例13: DaoCallServer_ActivateEvents
static void DaoCallServer_ActivateEvents()
{
DaoCallServer *server = daoCallServer;
daoint i, j;
if( server->idle != server->total ) return;
if( server->events->size != 0 ) return;
if( server->events2->size == 0 ) return;
#ifdef DEBUG
DaoStream_WriteMBS( mainVmSpace->errorStream, "WARNING: activating events!\n" );
#endif
for(i=0; i<server->events2->size; ++i){
DaoTaskEvent *event = (DaoTaskEvent*) server->events2->items.pVoid[i];
DaoChannel *chan = event->channel;
DaoFuture *fut = event->future;
int move = 0, closed = 0;
switch( event->type ){
case DAO_EVENT_WAIT_TASKLET :
move = fut->precond == NULL || fut->precond->state == DAO_CALL_FINISHED;
break;
case DAO_EVENT_WAIT_RECEIVING :
move = chan->buffer->size > 0;
if( chan->cap <= 0 && chan->buffer->size == 0 ) move = 1;
break;
case DAO_EVENT_WAIT_SENDING :
move = chan->buffer->size < chan->cap;
break;
case DAO_EVENT_WAIT_SELECT :
if( event->channels == NULL ) continue;
for(j=0; j<event->channels->size; ++j){
DaoChannel *chan = (DaoChannel*) event->channels->items.pValue[j];
closed += chan->cap <= 0;
move = chan->buffer->size > 0;
if( move ) break;
}
if( closed == event->channels->size ) move = 1;
break;
default: break;
}
if( move ){
DArray_Append( server->events, event );
DArray_Erase( server->events2, i, 1 );
i -= 1;
}
}
DCondVar_Signal( & server->condv );
}
示例14: CHANNEL_Cap
static void CHANNEL_Cap( DaoProcess *proc, DaoValue *par[], int N )
{
DaoChannel *self = (DaoChannel*) par[0];
daoint i;
DaoProcess_PutInteger( proc, self->cap );
if( N == 1 ) return;
/* Closing the channel: */
DMutex_Lock( & daoCallServer->mutex );
self->cap = par[1]->xInteger.value;
if( self->cap == 0 ){
DaoChannel_ActivateEvent( self, DAO_EVENT_WAIT_RECEIVING );
DaoChannel_ActivateEvent( self, DAO_EVENT_WAIT_SELECT );
DCondVar_Signal( & daoCallServer->condv );
}
DMutex_Unlock( & daoCallServer->mutex );
}
示例15: DaoCallServer_Timer
static void DaoCallServer_Timer( void *p )
{
DaoCallServer *server = daoCallServer;
double time = 0.0;
daoint i, timeout;
server->timing = 1;
while( server->finishing == 0 || server->stopped != server->total ){
DMutex_Lock( & server->mutex );
while( server->waitings->size == 0 ){
if( server->idle == server->total && server->events2->size ){
DaoCallServer_ActivateEvents();
}
if( server->finishing && server->stopped == server->total ) break;
DCondVar_TimedWait( & server->condv2, & server->mutex, 0.01 );
}
if( server->waitings->size ){
DNode *node = DMap_First( server->waitings );
time = node->key.pValue->xComplex.value.real;
time -= Dao_GetCurrentTime();
/* wait the right amount of time for the closest arriving timeout: */
if( time > 0 ) DCondVar_TimedWait( & server->condv2, & server->mutex, time );
}
DMutex_Unlock( & server->mutex );
if( server->finishing && server->stopped == server->total ) break;
DMutex_Lock( & server->mutex );
if( server->waitings->size ){ /* a new wait timed out: */
DNode *node = DMap_First( server->waitings );
time = Dao_GetCurrentTime();
if( node->key.pValue->xComplex.value.real < time ){
DaoTaskEvent *event = (DaoTaskEvent*) node->value.pVoid;
event->state = DAO_EVENT_RESUME;
event->timeout = 1;
event->expiring = MIN_TIME;
DArray_Append( server->events, node->value.pVoid );
DMap_EraseNode( server->waitings, node );
}
}
DCondVar_Signal( & server->condv );
DMutex_Unlock( & server->mutex );
}
server->timing = 0;
}