예제 #1
0
Queue * QueueCreate(BOOL NoCritSec) {
    Queue * pQueue;

#ifdef DEBUG2
    DbgMsgRecord(TEXT("-> QueueCreate\n"));
#endif

    pQueue = (Queue *)AutoHeapAlloc(sizeof(Queue));

    if (pQueue == NULL) {
        AddToMessageLog(TEXT("QueueCreate: AutoHeapAlloc failed"));
        return NULL;
    }

    pQueue->pFirst = NULL;
    pQueue->pLast = NULL;    

    if (NoCritSec) {
        pQueue->lpCriticalSection = NULL;
    }
    else {
        pQueue->lpCriticalSection = (LPCRITICAL_SECTION) AutoHeapAlloc(sizeof(CRITICAL_SECTION));
        if (InitializeCriticalSectionAndSpinCount(pQueue->lpCriticalSection, 100) == 0) {
            AddToMessageLogProcFailure(TEXT("QueueCreate: InitializeCriticalSectionAndSpinCount"), GetLastError());
            QueueDelete(pQueue);
            return NULL;
        }
    }

#ifdef DEBUG2
    DbgMsgRecord(TEXT("<- QueueCreate\n"));
#endif

    return pQueue;
}
예제 #2
0
static void *calendar_manager_thread_entry(void *param)
{
  UNUSED(param);
  mqd_hdl mq;

  memset(input_buffer, '\0', MAX_MSG_QUEUE_SIZE+1);
  memset(answer_buffer, '\0', MAX_MSG_QUEUE_SIZE+1);

  if(FAILURE == QueueCreate(&mq, QUEUE_NAME, MAX_MSG_QUEUE_SIZE, MAX_MSG_QUEUE_NUM))
  {
    calendar_quit();
  }

  while(!calendar_exit)
  {
    if(FAILURE == QueueReceive(&mq, input_buffer, MODE_BLOCK))
    {
      calendar_quit();
    }

    CALENDER_DEBUG("Success to receive message : [ %s ] from user input process thread.", input_buffer);

    process_input_string(input_buffer, answer_buffer);

    if(FAILURE == QueueSend(&mq, answer_buffer, MODE_BLOCK))
    {
      calendar_quit();
    }

    CALENDER_DEBUG("Success to Answer message to user input process thread.");
    memset(answer_buffer, '\0', strlen(answer_buffer));
  }

  QueueDelete(&mq, QUEUE_NAME);
}
예제 #3
0
파일: cQueueP.cpp 프로젝트: palmerc/lab
cQueueP::~cQueueP()
{
    bool Success;

    while (!QueueIsEmpty())
        QueueDelete(Success);
    // Assertion: BackPtr == NULL
} // end destructor
int main()
{

    static int x[QUEUE_SIZE];
    static int RP= -1,FP=-1;
    int data;
    StackStatus status;
    char option;
    char exitFalg = 0;

    while(exitFalg == 0)
    {
    do
    {
     printf("\nPlease Select \n 1: Insert \n 2: Delete \n 3: Exit\n");
     scanf("%d",&option);
    }while(!(option>=1 && option<= 3));

    switch (option)
    {
        case 1:
        printf("\n Please Enter data\n");
        scanf("%d",&data);
        status = QueueInsert(x,data,&RP);
        if(status == OK)
        {
            QueueDisplay(x,RP,FP);
        }
        else
        {
            printf("Queue is full");
        }
        break;
        case 2:
        status = QueueDelete(x,&data,&RP,&FP);
        if(status == OK)
        {
            printf("Data = %d",data);
        }
        else
        {
            printf("Queue is Empty");
        }
        break;
        case 3:
        exitFalg =1;
        break;

    }
    }

return 0;

}
예제 #5
0
파일: cQueueP.cpp 프로젝트: palmerc/lab
void cQueueP::QueueDelete(queueItemType& QueueFront,
                          bool& Success)
{
    Success = bool(!QueueIsEmpty());

    if (Success)
    {   // queue is not empty; retrieve front
        ptrType FrontPtr = BackPtr->Next;
        QueueFront = FrontPtr->Item;

        QueueDelete(Success); // delete front
    } // end if
} // end QueueDelete
예제 #6
0
void enet_slirp_queue_poll(void)
{
    SDL_LockMutex(slirp_mutex);
    if (QueuePeek(slirpq)>0)
    {
        struct queuepacket *qp;
        qp=QueueDelete(slirpq);
        Log_Printf(LOG_WARN, "[SLIRP] Getting packet from queue");
        enet_receive(qp->data,qp->len);
        free(qp);
    }
    SDL_UnlockMutex(slirp_mutex);
}
예제 #7
0
int main()
{
  Queue q;
  QueueNew(&q, sizeof(int));
  int a = 2;
  int b = 3;
  int c = 4;

  QueueEnter(&q, &a);
  QueueEnter(&q, &b);
  QueueEnter(&q, &c);

  int d, e, f;
  QueueDelete(&q, &d);
  printf("%d\n", d);

  QueueDelete(&q, &e);
  printf("%d\n", e);

  QueueDelete(&q, &f);
  printf("%d\n", f);
  
  QueueFree(&q);
}
예제 #8
0
VOID QueuesDelete(Queue *Queues[], UINT n) {

#ifdef DEBUG2
    DbgMsgRecord(TEXT("-> QueuesDelete\n"));
#endif

    for (UINT i=0; i<n; i++) {
        QueueDelete(Queues[i]);
        Queues[i] = NULL;
    }

#ifdef DEBUG2
    DbgMsgRecord(TEXT("<- QueuesDelete\n"));
#endif

}
예제 #9
0
//求所有路径之间的距离
int GrapgAllWay(AdjList *graph, int f, int t, void (*weizhi)(int))
{
	int done[MAX_VERTEX_NUM] = {0};
	Queue *que;
	QueueDataElem *p, *q;
	ArcNode *x;
	List * head;
	int i;
	int leap = 0;

	que = (Queue *)malloc(sizeof(Queue));
	p = (QueueDataElem *)malloc(sizeof(QueueDataElem));
	x = (ArcNode *)malloc(sizeof(ArcNode));
	QueueInit(que);
	p->l = 0;
	p->vn = f;
	p->datanext = NULL;
	done[p->vn] = 1;
	QueueEnter(que, *p);
	do{
		QueueDelete(que, p);
		q = p;
		while(p != NULL){
			done[p->vn] = 1;
			p = p->datanext;
			continue;
		}
		p = q;
		if(p->vn == t){
			leap++;
			head = (List *)malloc(sizeof(List));
			ListInit(head);
			while(p != NULL){
//				printf("%d\t", p->vn + 1);
//				p = p->datanext;
				ListInsert(head, *p);
				p = p->datanext;
			}
			ListDxu(head);
			head = head->next;
			while(head != NULL){
//				printf("%d\t\t", head->data.vn);
				weizhi(head->data.vn);
				head = head->next;
			}
			printf("\n");
			printf("%d", leap);
			printf("\n");
		}
		p = q;
		x = graph->vertex[p->vn].fristarc;
		while(x != NULL){
			if(done[x->adjvex] == 1){
				x = x->nextarc;
				continue;
			}
			p = (QueueDataElem *)malloc(sizeof(QueueDataElem));
			p->vn = x->adjvex;
			p->datanext = q;
			QueueEnter(que, *p);
			x = x->nextarc;
		}
		for(i = 0 ; i < graph->vexnum ; i++){
			done[i] = 0;
		}
	}while(QueueEmpty(que));

	return 0;
}