Ejemplo n.º 1
0
/*
* 목적 : 큐에 데이큐 데이터 추출을 위한 뮤텍스 추가
*      		 queue - queue handler
*			 status - 데이터 추출 결과 상태 저장
* 반환값 : 추추출된 데이터의 포인터
* 개정 이력 : 2016.03.17 초기작성
*/
void* qPopMutex (Queue *queue, status_t *status)
{
    status_t _status;
    QLink *qlinkCurrentTail;

    _status = pthread_mutex_lock(&queue->mutex);
    *status = _status;
    if (_status != EOK){
  		printLog( "by pcw : gQueue.c : %d... \n",__LINE__);
        qlinkCurrentTail = NULL;
    }else{
    	qlinkCurrentTail = qPop(queue, status);
	}
   	pthread_mutex_unlock(&queue->mutex);
    return((void *)qlinkCurrentTail);
}
Ejemplo n.º 2
0
// Starts the event loop. While the event is still running, pop items off the queue and
// execute their functions
void startEventLoop( void * handle, void (*initialFunction )( void * ),
                                                    void * initialArgument ){
    Handle * hand = ( Handle * )handle;
    EventQueue * que = hand->cue;

    qInsert( que, initialFunction, initialArgument );

    if( pthread_mutex_lock( &hand->mu ) != 0 ){
        fprintf( stderr, "Error in mutex lock.\n" );
        exit( -1 );
    }
    
    while( hand->terminated != 1 ){
        while( qIsEmpty( que ) == 1 ){
            if( pthread_cond_wait( &hand->cv, &hand->mu ) != 0 ){
                fprintf( stderr, "Error in cond_wait\n" );
                exit( -1 );
            }
        }
        
        if( qIsEmpty( que ) == 0 ){
            qEntry * popped = qPop( que );
            void ( *f )( void * ) = popped->func;
            void * arg = popped->args;
            free( popped );
            f( arg );
        }
         
    }
    if( pthread_mutex_unlock( &hand->mu ) != 0 ){
        fprintf( stderr, "error in mutex unlock\n" );
        exit( -1 );
    }
    
    
    
}