コード例 #1
0
ファイル: OovThreadedWaitQueue.cpp プロジェクト: 8l/oovcde
bool OovThreadedWaitQueuePrivate::waitPopPrivate(void *item)
    {
    std::unique_lock<std::mutex> lock(mProcessQueueMutex);
    bool gotItem = false;
    LOG_PROC("pop lock", this);
    // Wait while empty
    while(isQueueEmpty() && !mQuitPopping)
        {
        // Release lock and wait for signal.
        mProviderPushedSignal.wait(lock);
        // After signaled, lock is reaquired.
        }

    // In the normal case this will not be empty.
    // If it is empty, then there was a signal, but nothing was
    // in the queue. This means that the quit function was called.
    gotItem = !isQueueEmpty();
    LOG_PROC_INT("pop got item", this, gotItem);
    if(gotItem)
        {
        getFront(item);
        }

    LOG_PROC_INT("pop unlock", this, gotItem);
    // unlock and signal to provider thread that queue is processed.
    lock.unlock();
    mConsumerPoppedSignal.notify_one();
    LOG_PROC("pop done", this);
    return gotItem;
    }
コード例 #2
0
ファイル: testQueue.c プロジェクト: jesseau/1921-15s2
int main(int argc, char *argv[]) {
    printf("Creating queue... ");
    Queue q = emptyQueue();
    assert(q != NULL);
    printf("OK\n");

    printf("Checking if queue is empty... ");
    assert(isQueueEmpty(q));
    printf("OK\n");

    printf("Adding 1..%d to queue... ", TEST1);
    int i;
    for (i = 1; i <= TEST1; i++) {
        queue(q, i);
        assert(!isEmpty(q->s1) || !isEmpty(q->s2));
    }
    printf("OK\n");

    printf("Removing 1..%d from queue... ", TEST1);
    for (i = 1; i <= TEST1; i++) {
        assert(dequeue(q) == i);
    }
    printf("OK\n");

    printf("Checking if queue is empty... ");
    assert(isQueueEmpty(q));
    printf("OK\n");

    printf("All tests passed. You are awesome!\n");

    return EXIT_SUCCESS;
}
コード例 #3
0
ファイル: algo3_note.c プロジェクト: duneplanet/mpi
int bfs(int s,int a, struct vertex *adj) {
    int i, u, j, l, v, w, k;

    struct queue *queue = malloc(sizeof(struct queue));
    struct queue *queueHyphen = malloc(sizeof(struct queue));
    queueInit(queue);
    queueInit(queueHyphen);
#pragma omp parallel for shared(adj)
    for (i = 0; i < adj[s].indeg; i++) { //par begin //compare ok
        u = adj[s].ins[i].u;
        j = adj[s].ins[i].iuout;
        eliminate(adj, u, j);                       //compare ok
    } //par end                                     //compare ok
    l = 0;                                          //compare ok
    adj[s].traversal = a;                           //compare ok
    adj[s].distance = l;                            //compare ok //before was adj[s].distance = l //compare with php
    struct queueNode *queueNode1 = malloc(sizeof(struct queueNode));
    enque(s, queue, queueNode1);                               //todo
//    printf("l74:queue -- should've queued %i\n", s);
    queueReset(queueHyphen);                        //todo
//    printf("l76:queueHypen -- should've reset");
    while (true) {  //repeat 1 begin
        l = l + 1;                                  //compare ok
        while (true) {  //repeat 2 begin
            u = deque(queue);                      //todo
//            printf("l81:queue -- should've dequeued %i\n", u);
            while (adj[u].first < adj[u].outdeg) {  //compare ok
                i = adj[u].first;                   //compare ok
                v = adj[u].out[i];                  //compare ok
#pragma omp parallel for shared(adj)
                for (j = 0; j < adj[v].indeg; j++) {  //par begin //compare ok
                    w = adj[v].ins[j].u;
                    k = adj[v].ins[j].iuout;
                    eliminate(adj, w, k);           //compare ok
                } //par end                         //compare ok
                a = a + 1;                          //compare ok
                adj[v].traversal = a;               //compare ok
                adj[v].distance = l;                //compare ok
                adj[v].parent = u;                  //compare ok
//                printf(":%i parent of %i\n", u, v);  //comment me
                struct queueNode *queueNode2 = malloc(sizeof(struct queueNode));
                enque(v, queueHyphen, queueNode2);              //todo
//                printf("l103:queueHyphen -- should've queued %i\n", v);
            } //end while                           //compare ok
            if (isQueueEmpty(queue)) {  //until
                break;
            }
        } //repeat 2 end                            //compare ok
        *queue = *queueHyphen;
        queueInit(queueHyphen);
//        printf("l121:queue = queueHyphen\n");
        if (isQueueEmpty(queue)) {
            break;
        }
    } //end repeat 1                                //compare ok
    return EXIT_SUCCESS;
}
コード例 #4
0
ファイル: mythread.c プロジェクト: gramesh3/Threading-library
void removeParentFromBlockedQueue(Thread *thread) {
	Thread *parent = thread->parent;
	
	if(parent != NULL)
		removeFromQueue(parent->children, thread);

	if(!isQueueEmpty(blockedQueue) && isPresent(blockedQueue, parent)) {
		
		if(isQueueEmpty(parent->children) || (parent->waitingFor == thread)) {
			removeFromQueue(blockedQueue, parent);
			parent->waitingFor = NULL;
			insertIntoQueue(readyQueue, parent);
		}	
	}
}	
コード例 #5
0
void ReadableStream::readInternalPostAction()
{
    ASSERT(m_state == Readable);
    if (isQueueEmpty() && m_isDraining)
        closeInternal();
    callPullIfNeeded();
}
コード例 #6
0
ファイル: cache.c プロジェクト: gvanvari/CPP-Codes
// A function to add a page with given 'pageNumber' to both queue
// and hash
void Enqueue( Queue* queue, Hash* hash, unsigned pageNumber )
{
    // If all frames are full, remove the page at the rear
    if ( AreAllFramesFull ( queue ) )
    {
        // remove page from hash
        hash->array[ queue->rear->pageNumber ] = NULL;
        deQueue( queue );
    }

    // Create a new node with given page number,
    // And add the new node to the front of queue
    QNode* temp = newQNode( pageNumber );
    temp->next = queue->front;

    // If queue is empty, change both front and rear pointers
    if ( isQueueEmpty( queue ) )
        queue->rear = queue->front = temp;
    else  // Else change the front
    {
        queue->front->prev = temp;
        queue->front = temp;
    }

    // Add page entry to hash also
    hash->array[ pageNumber ] = temp;

    // increment number of full frames
    queue->count++;
}
コード例 #7
0
ファイル: queue_lk.cpp プロジェクト: franktly/data-structure
int LkQueue::locateQueue(ElemType &key)
{
	if (isQueueEmpty())
	{
		std::cout << "queue is empty" << std::endl;
		return _queue->front->element; // 默认空返回init操作的head结点元素值(初始化为0)
	}

	int loopIndex = 0;
	QNode *loopNode = _queue->front->next;
	bool isFound = false;

	while (!NULL_PTR(loopNode)) // 从(front--> rear],rear为尾结点 rear->next == NULL
	{
		if (loopNode->element == key)
		{
			isFound = true;
			return loopIndex;
		}
		loopNode = loopNode->next;
		loopIndex++;
	}

	if (!isFound)
	{
		std::cout << "not found key is " << key << std::endl;
		return _queue->front->element; // 空默认返回init操作的front的元素值(值为0,初始化为0)
	}
}
コード例 #8
0
//add node to the front
void enque(Queue *q, Hash *h, unsigned int page_no)
{
	if(q == NULL || h == NULL || page_no > h->capacity)
		return;
	//if queue is full, remove page from the rear
	//remive it from hash table
	if(isQueueFull(q))
	{
		dequeue(q);
		h->array[q->rear->page_no] = NULL;
	}
	QNode *node = new_node(page_no);
	node->next = q->front;
	
	if(isQueueEmpty(q))
	  q->front = q->rear = node;
    else
	{
		q->front->prev = node;
		q->front = node;
	}
	
	//make an entry into hash table
	h->array[page_no] = node;
	q->count++;

}
// A utility function to delete a frame from queue
uint16_t deQueue( Queue* queue )
{
 uint16_t n ;
	if( isQueueEmpty( queue ) )
		return  ;

	// If this is the only node in list, then change front
	if (queue->front == queue->rear)
		queue->front = NULL;

	// Change rear and remove the previous rear
	QNode* temp = queue->rear;
	queue->rear = queue->rear->prev;

	//printf("\n\n%u",
		n=(temp->pageNumber);

	if (queue->rear)
		queue->rear->next = NULL;

	free( temp );

	// decrement the number of full frames by 1
	queue->count--;

	return n;
}
コード例 #10
0
void bfs(struct Graph* g){
	struct Queue* q= (struct Queue*)malloc(sizeof(struct Queue));
	initQueue(q);
	int i,v;
	struct Vertex* to;
	enqueue(q,g->start);
	g->v_list[g->start]->visited = 1;
	g->v_list[g->start]->cost = 0;
	while(!isQueueEmpty(q)){
		i = dequeue(q);
	//	if(i!=g->start)
	//		printf("%d ",g->v_list[i]->cost);
		struct list_edges *list = g->v_list[i]->adj_list;
		while(list!= NULL){
			to = list->edge_node->to;
			if(to->visited == 0)
			{	
				enqueue(q,to->v);
				to->visited =1;
				to->cost = list->edge_node->cost  + g->v_list[i]->cost;
			}
			list=list->next;
		}
	}
	for(i =1;i <= g->V;i++){
		if(i != g->start){
		if(g->v_list[i]->visited == 0)
			printf("-1 ");
		else 
			printf("%d ",g->v_list[i]->cost);
	}
	}
	free(q);
}
int evaluate(ParseTreeNode *p_root){
    ParseTreeNode *result_node;
    int val;

    initializeStack();
    initializeQueue(); /* So that the tree will not be changed */

    postOrderTraversal(p_root, &evaluatorHelper);

    result_node = pop();
    val = *(result_node->m_token->m_data_container->m_int);

    /* Free the resources */
    while(!isQueueEmpty()){
        result_node = dequeue();

        free(result_node->m_token->m_data_container);
        result_node->m_token->m_data_container = NULL;

        free(result_node->m_token);
        result_node->m_token = NULL;

        free(result_node);
        result_node = NULL;
    }

    return val;
}
コード例 #12
0
ファイル: queue.c プロジェクト: exeasy/tcm2
char	*DeQueue( MyQueue *p )
{
	int	typesize = 0;
	int	maxsize = 0;
	int	offset = 0;
	char	*element = NULL;

	if( !isQueueInit(p) )
	{
		printf( "[%s][%d]the queue donot init\n", __FILE__, __LINE__ );
		return NULL;
	}

	if( isQueueEmpty(p) )
	{
		printf( "[%s][%d]the queue is empty\n", __FILE__, __LINE__ );
		return NULL;
	}

//	pthread_mutex_lock( &(p->mutex) );

	typesize = p->typesize;
	maxsize = p->maxsize*typesize;
	offset = typesize;

	element = p->queue+p->front;
	p->front = (p->front+offset)%(maxsize);
	p->length--;
//	pthread_mutex_unlock( &(p->mutex) );

	return element;
}
コード例 #13
0
ファイル: graph.c プロジェクト: aaa1616/Fairy
void bfs(GRAPH *g, int data)
{
	int i, vet = g->vetNum;
	g->adj[data].color = 1;
	for (i = 0; i < vet; i++) {
		if (i != data) {
			g->adj[i].color = 0;
		}
	}
	QUEUE *q = initQueue();
	enqueue(q, data);
	while (!isQueueEmpty(q)) {
		int u = dequeue(q);
		printf("%c ", u + 'A');
		EDGE *p = g->adj[u].adj;
		while (p != NULL) {
			int next = p->dest;
			if (g->adj[next].color == 0) {
				g->adj[next].color = 1;
				enqueue(q, next);
			}
			p = p->link;
		}
		g->adj[u].color = 2;
	}
	printf("\n");
}
コード例 #14
0
ファイル: queue_lk.cpp プロジェクト: franktly/data-structure
ElemType& LkQueue::getQueueByIndex(int index)
{
	if (isQueueEmpty())
	{
		std::cout << "queue is empty" << std::endl;
		return _queue->front->element; // 默认空返回init操作的head结点元素值(初始化为0)
	}

	if (index < 0 || index > _size-1)
	{
		std::cout << "index [" << index << "] is out of range: [0, "<< _size << ")" << std::endl;
		return _queue->front->element; // 默认空返回init操作的head结点元素值(初始化为0)
	}

	int loopIndex = 0;
	QNode *loopNode = _queue->front->next;

	while (!NULL_PTR(loopNode)) // 从(front--> rear],rear为尾结点 rear->next == NULL
	{
		if (loopIndex == index)
		{
			return loopNode->element;
		}
		loopNode = loopNode->next;
		loopIndex++;
	}
}
コード例 #15
0
ファイル: BFS.c プロジェクト: nobody-nowhere/G
void BFS() {
   int i;

   //mark first node as visited
   lstVertices[0]->visited = true;

   //display the vertex
   displayVertex(0);   

   //insert vertex index in queue
   insert(0);
   int unvisitedVertex;

   while(!isQueueEmpty()) {
      //get the unvisited vertex of vertex which is at front of the queue
      int tempVertex = removeData();   

      //no adjacent vertex found
      while((unvisitedVertex = getAdjUnvisitedVertex(tempVertex)) != -1) {    
         lstVertices[unvisitedVertex]->visited = true;
         displayVertex(unvisitedVertex);
         insert(unvisitedVertex);               
      }
		
   }   

   //queue is empty, search is complete, reset the visited flag        
   for(i = 0;i<vertexCount;i++) {
      lstVertices[i]->visited = false;
   }    
}
コード例 #16
0
ファイル: Queue.c プロジェクト: jblairkiel/UA-CS-201
/*Method that 'adds' the node parameter to the Queue (FIFO)
	Also builds the Heap Structure in level order.*/
void
enqueue(struct queue *q, struct stack *s, struct binaryTreeNode *n, int optionD){
	//Add node to the Queue
        if (isQueueEmpty(q) == 1){
		q->front->node = n;
		q->front->next = NULL;
		q->rear = q->front;
        }
        else{
		struct queueNode *temp = malloc(sizeof(struct queueNode));
		temp->next = NULL;
		temp->node = n;
                q->rear->next = temp;
                q->rear = temp;

		//'Adds' the Node to the Heap in level order (priority of left to right)
		if(q->front->node->left == NULL){
			q->front->node->left = n;	
			n->parent = q->front->node;
		}
		else if(q->front->node->right == NULL){
			q->front->node->right = n;
			n->parent = q->front->node;
		}
		else{
			//The front of the queue has full children so dequeue it
			dequeue(q,s, optionD);
			q->front->node->left = n;
			n->parent = q->front->node;
		}	
        }
	q->size += 1;
	return;
}
コード例 #17
0
ファイル: queue.c プロジェクト: exeasy/tcm2
char	*GetQueueElem( MyQueue *p, int i )
{
	char	*element = NULL;
	int	typesize = 0; 
	int	maxsize = 0;
	int	index = 0;

	if( !isQueueInit(p) )
	{
		printf( "[%s][%d]do not init\n", __FILE__, __LINE__ );
		return NULL;
	}

	if( isQueueEmpty(p) )
	{
		printf( "[%s][%d]queue is empty\n", __FILE__, __LINE__ );
		return NULL;
	}

	if( i > p->length || i <= 0 )
	{
		printf( "[%s][%d]i is wrong number\n", __FILE__, __LINE__ );
		return NULL;
	}

	typesize = p->typesize;
	maxsize = p->maxsize*typesize;

	index = (p->front + (i-1)*typesize) % maxsize;
	element = p->queue + index;

	return element;
}
コード例 #18
0
ファイル: mythread.c プロジェクト: gramesh3/Threading-library
void MyThreadJoinAll(void) {

	if(!isQueueEmpty(currentThread->children)) {
		Thread *this = currentThread;
		insertIntoQueue(blockedQueue, currentThread);
		currentThread = getNextThread();
		swapcontext(&(this->uctxt), &(currentThread->uctxt));
	}	
}	
コード例 #19
0
int dequeue(struct Queue *Q)
{
	if(!isQueueEmpty(*Q))
	{
		(*Q).front++;
		(*Q).front=(*Q).front%(*Q).size;
		return (*Q).arr[(*Q).front];
	}
}
コード例 #20
0
void ReadableStream::close()
{
    if (m_state != Readable)
        return;

    if (isQueueEmpty())
        closeInternal();
    else
        m_isDraining = true;
}
コード例 #21
0
void PDFJam::run(){
    while(!isQueueEmpty()){
        QString cmd = nextCommand();
        int value = system(cmd.toStdString().c_str());

        //if(value)
            //qDebug() << "ERROR: Failed to execute " << cmd;
        //else
            //qDebug() << "SUCCESS: executed " << cmd;
    }
}
コード例 #22
0
ファイル: queue.c プロジェクト: phrocker/TestBase
/************************************************************************************
*
*	peekAtFrontElement
*
*	Allows the programmer to peek at the top element, without removing it from the queue
*      
*	Arguments:
*
*      Queue inputQueue
*
*	Return Value:
*
*		Pointer to the element at the front of the queue
*
*************************************************************************************/
command *peekAtFrontElement(Queue inputQueue) 
{
    // if queue is empty, return null
    if (isQueueEmpty(inputQueue))
        return NULL;

    
    command *cmd = &inputQueue->localDataStructure[inputQueue->currentFrontIndex];
    
    return cmd;

}
コード例 #23
0
void addToQueue(queue aQueue, int data) {
  queueNode temp = (queueNode) malloc(sizeof(struct aNode));
  temp->data = data;
  temp->next = NULL;
  if(isQueueEmpty(aQueue)) {
    aQueue->last = temp;
    aQueue->first = temp;
  } else {
    aQueue->last->next = temp;
    aQueue->last = temp;
  }
}
コード例 #24
0
ファイル: ReadableStream.cpp プロジェクト: kjthegod/WebKit
void ReadableStream::readPostAction()
{
    ASSERT(m_state == Readable);
    if (isQueueEmpty()) {
        if (m_isDraining) {
            m_closed->resolve(ToV8UndefinedGenerator());
            m_state = Closed;
        } else {
            m_ready->reset();
            m_state = Waiting;
        }
    }
    callPullIfNeeded();
}
コード例 #25
0
ファイル: NFAPostfix.c プロジェクト: mathlover777/CompilerLab
void queueToString(queue *q,char *a){
	char x;
	int i=0;
	while(1){
		if(isQueueEmpty(q)==1){
			break;
		}
		x=queue_top(q);
		dequeue(q);
		a[i]=x;
		i++;
	}
	a[i]='\0';
}
コード例 #26
0
//remove node from the rear 
void dequeue(Queue *q)
{
	if(q == NULL || isQueueEmpty(q))
		return;
	//only one node
	if(q->front == q->rear)
		q->front = NULL;
	QNode *temp = q->rear;
	q->rear = q->rear->prev;
	if(q->rear)
		q->rear->next = NULL;
	free(temp);
	q->count--;
}
コード例 #27
0
ファイル: Queue.c プロジェクト: jblairkiel/UA-CS-201
/*Method that prints the Linked List structure of the Queue*/
void 
printQueue(struct queue *q){
        if(isQueueEmpty(q) == 0){
                struct queueNode *tNode = malloc(sizeof(struct queueNode));
		tNode = q->front;
                printf("\nQueue Structure is \n");
		while(tNode->next != NULL){
                        printf("%d->",tNode->node->value);
                        tNode = tNode->next;
                }
                printf("%d\n",tNode->node->value);
        }
	return;
}
コード例 #28
0
ファイル: OovThreadedWaitQueue.cpp プロジェクト: 8l/oovcde
void OovThreadedWaitQueuePrivate::quitPopsPrivate()
    {
    std::unique_lock<std::mutex> lock(mProcessQueueMutex);
    LOG_PROC("quitPops lock", this);
    mQuitPopping = true;
    // Wait to make sure all queue items were processed.
    while(!isQueueEmpty())
        {
        mConsumerPoppedSignal.wait(lock);
        }
    LOG_PROC("quitPops unlock", this);
    lock.unlock();
    mProviderPushedSignal.notify_all();
    LOG_PROC("quitPops done", this);
    }
コード例 #29
0
ファイル: cpuLoad.c プロジェクト: Susandhi/Susandhi-4
LinkPtr getCpuLoad(LinkPtr head,LinkPtr headLog)
{
	int i=0;
	char *str;
	for(i=0;i<10;i++)
	{
		if(isQueueEmpty(&myQueue)!=1)
		{
			str=(char*)deqQueue(&myQueue);
			UartPrint(str);
			UartPrint("\r\n");
		}
	}
	return NULL;
}
コード例 #30
0
ファイル: linkedQueue.c プロジェクト: gabrielarpino/C-Labs
void dequeue(struct Queue * Q, struct Data * d)
{
    struct queueNode * temp;
    if (!isQueueEmpty(Q)) {
        temp=Q->front;
        *d=*(temp->data);
        if (Q->front==Q->rear) {
            Q->front=NULL;
            Q->rear=NULL;
        }
        else{
            Q->front=temp->link;
        }
        free(temp->data);
        free(temp);
        Q->currSize--;
    }
}