예제 #1
0
int main(){
	int i = 0, tmp = 0;
	Queue *q = queue_create();
	for(i = 0; i < 10; i++)
		enQueue(q, i);
	printf("%d\n", queueLength(q));
	for(i = 0; i < 10; i++){
		deQueue(q, &tmp);
		printf("%d ", tmp);
	}
	printf("\n%d\n", queueLength(q));
	return 0;
}
예제 #2
0
int minimum(linkQueue *ptrQ)
{
  int minQueue = queueLength(ptrQ[0]);
  int minIndex = 0;

  for(int i = 1; i < 5; ++i)
  {
      if(queueLength(ptrQ[i]) < minQueue)
      {
          minIndex = i;
      }
  }

  return minIndex;
}
예제 #3
0
void customerArrived(int closeTime)
{
    int durTime = -1;               //客户办理事务所需时间
    int interTime = -1;             //下一个客户到达的时间间隔
    int nextArrivalTime = -1;        //下一个客户到达的时刻
    ++customerNum;

    random(durTime, interTime);           //生成随机数

    nextArrivalTime = en.occurTime + interTime;

    if(nextArrivalTime < closeTime)
    {
        Event tmpEn;
        tmpEn.occurTime = nextArrivalTime;
        tmpEn.nType = 0;

        orderInsert(ev, tmpEn, cmp);
    }

    int i = minimum(q);         //获取长度最短的队列

    customer.arrivalTime = nextArrivalTime;
    customer.duration = durTime;
    enQueue(q[i], customer);

    if(1 == queueLength(q[i]))
    {
        Event tmpEn2;
        tmpEn2.occurTime = nextArrivalTime + durTime;
        tmpEn2.nType = i;

        orderInsert(ev, tmpEn2, cmp);
    }
}
예제 #4
0
void cCharDevice::scheduleDevice(ProcessInfo* proc) {
	assert(proc != NULL);

	pthread_mutex_lock(&deviceLock);
	waitQueue.push(proc);

	if ( queueLength() == 1) {
		/* Schedule Interrupt */
		if ( timer_settime(timerid, 0, &iTime, NULL) == -1 )
			throw ((string) "Failed to start CharDevice timer: " + strerror(errno));
	}

	pthread_mutex_unlock(&deviceLock);

	return;
}
예제 #5
0
파일: testQ.c 프로젝트: hamyoh1/COMP15s2
int main (int argc, char *argv[])
{
    int i;
    Item it;
    Queue q1,q2;

    printf("Test 1: Create queues\n");
    q1 = createQueue();
    q2 = createQueue();
    assert(q1 != NULL);
    assert(q2 != NULL);
    assert(queueLength(q1) == 0);
    assert(queueLength(q2) == 0);
    printf("Passed\n");

    printf("Test 2: Add to queues\n");
    for (i = 1; i <= MAX; i++) {
        enterQueue(q2,i);
        enterQueue(q1,i);
        assert(queueLength(q2) == i);
        assert(queueLength(q1) == i);
    }
    printf("Final q1: ");
    showQueue(q1);
    printf("Final q2: ");
    showQueue(q2);
    printf("Passed\n");

    printf("Test 3: Remove from queues\n");
    for (i = 1; i <= MAX; i++) {
        it = leaveQueue(q1);
        assert(queueLength(q1) == MAX-i);
        assert(i == it);
        it = leaveQueue(q2);
        assert(queueLength(q2) == MAX-i);
        assert(i == it);
    }
    printf("Passed\n");

    printf("Test 4: Destroy queues\n");
    dropQueue(q1);
    dropQueue(q2);
    printf("Passed\n");

    printf("Test 5: Remove from emoty queue\n");
    printf("This test should fail an assertion\n");
    q1 = createQueue();
    it = leaveQueue(q1);
    printf("Passed\n");

    return 0;
}
예제 #6
0
ProcessInfo* cCharDevice::timerFinished() {
	pthread_mutex_lock(&deviceLock);

	if ( timer_settime(timerid, 0, &iDisarm, NULL) == -1 )
		throw ((string) "Failed to disarm timer: " + strerror(errno));

	ProcessInfo* finishedProc = waitQueue.front();
	waitQueue.pop();

	if ( queueLength() > 0) {
		/* Schedule next interrupt */
		if ( timer_settime(timerid, 0, &iTime, NULL) == -1 )
			throw ((string) "Failed to start CharDevice timer: " + strerror(errno));
	}

	pthread_mutex_unlock(&deviceLock);

	return finishedProc;
}
예제 #7
0
void lQueueTestMain()
{
	SqQueue<float> Q;
	initQueue(Q);
	for(int i=0;i<18;++i)
		enQueue(Q,3.14f*i);
	queueTraverse(Q);

	float a;
	for(int i=0;i<4;++i)
		deQueue(Q,a);
	queueTraverse(Q);

	cout<<queueLength(Q)<<endl;
	getQueueHead(Q,a);
	cout<<a<<endl;

	clearQueue(Q);
	destroyQueue(Q);
	int aa=100;
}
예제 #8
0
 void QueueMediator::moveTrackToEnd(int fromIndex, quint32 queueId) {
     auto toIndex = queueLength() - 1;
     moveTrack(fromIndex, toIndex, queueId);
 }