void Enqueue(struct queue * queue, struct hash *thash, int pageno,
		char *contents, time_t expirystamp, char *etag,char *modifystampstr) {
	if (IsQueueFull(queue)) {

		thash->array[queue->rear->pageno] = NULL;
		Dequeue(queue);
	}

	struct queuenode *newnode = CreateNewQueueNode(pageno, contents,
			expirystamp, etag,modifystampstr);

	if (IsQueueEmpty(queue)) {
		queue->front = queue->rear = newnode;

	} else {
		newnode->next = queue->front;
		queue->front->prev = newnode;
		queue->front = newnode;
	}

	thash->array[pageno] = newnode;

	queue->count++;

}
Exemple #2
0
void Enqueue (int data)
{
	/*
	 * Increment end when new item is added to the list
	 * Reset end when it reaches QUEUELENGTH
	 * Check when incrementing if end == start then this indicates that the list is full. Do not allow this
	 * 	Special case when resetting this needs to be checked.
	 *
	 * 	Boundary
	 * 	1. Enqueue only when start
	*/


	// Rearrange the program to
	if ( rear == -1 )
	{
		front = 0 ;
		rear = 0;
		Queue[rear] = data;
	}
	else
	{
		if ( !IsQueueFull())
		{
			rear = (rear+1)%QUEUELENGTH;
			Queue[rear]= data;
		}
		else
		{
			return ;
		}
	}

}
/****************************** QUEUE ******************************/
int EnqueueProcess(struct processQueue* queue, struct proc* process )
{
	if(!IsQueueFull(queue))
	{
		if(queue!=0)
		{
			queue->proc[queue->tail]=process;
			queue->tail=(queue->tail+1)%QUEUE_CAPACITY;
			queue->size=(queue->size)+1;
			return 0;
		}

	}
	return -1;
}
Exemple #4
0
int EnqueueMessage(struct PP_Var message)
{
    pthread_mutex_lock(&g_queue_mutex);
    // We shouldn't block the main thread waiting for the queue to not be full, so just drop the message.
    if ( IsQueueFull() != 0)
    {
        PostMessage("EnqueueMessage: full Q, drop message\n");
        pthread_mutex_unlock(&g_queue_mutex);
        return(0);
    }
    g_queue[g_queue_end] = message;
    g_queue_end = (g_queue_end + 1) % MAX_QUEUE_SIZE;
    g_queue_size++;
    pthread_cond_signal(&g_queue_not_empty_cond);
    pthread_mutex_unlock(&g_queue_mutex);
    return 1;
}
Exemple #5
0
/** Enqueue a message (i.e. add to the end)
 *
 * If the queue is full, the message will be dropped.
 *
 * NOTE: this function assumes g_queue_mutex is _NOT_ held.
 * @param[in] message The message to enqueue.
 * @return non-zero if the message was added to the queue. */
int EnqueueMessage(struct PP_Var message) {
  pthread_mutex_lock(&g_queue_mutex);

  /* We shouldn't block the main thread waiting for the queue to not be full,
   * so just drop the message. */
  if (IsQueueFull()) {
    pthread_mutex_unlock(&g_queue_mutex);
    return 0;
  }

  g_queue[g_queue_end] = message;
  g_queue_end = (g_queue_end + 1) % MAX_QUEUE_SIZE;
  g_queue_size++;

  pthread_cond_signal(&g_queue_not_empty_cond);

  pthread_mutex_unlock(&g_queue_mutex);

  return 1;
}