Beispiel #1
0
static char *test_q_is_full() {
  packet *q = q_create();
  packet p = pkt_create(ERROR, 0, 0, 0, 0);
  mu_assert("FAIL: test_q_is_full [1]", !q_is_full(0, 0, q, N));
  for (int i = 0; i < 16; i++) {
    q_write(p, 0, q, N);
  }
  mu_assert("FAIL: test_q_is_full [2]", q_is_full(0, 0, q, N));
  q_read(&p, 0, q, N);
  mu_assert("FAIL: test_q_is_full [3]", !q_is_full(0, 0, q, N));
  q_destroy(q);
  return NULL;
}
Beispiel #2
0
/* Mete un nuevo cliente (con tiempo de arribo absoluto == 'ta')
 * al final de la cola global 'q'
 * PRE: ! q_is_full (q)
 */
void q_enqueue (queue_t q, double ta)
{
	assert (!q_is_full(q));
	
	q->q[q->l] = ta;
	q->l = (q->l + 1) % q->n;
	
	return;
}
Beispiel #3
0
int q_enqueue(QUEUE *p_q, ELEMENT_TYPE a)
{
	if (p_q == NULL) return -1;

	if (q_is_full(p_q)) return -1;
	else
	{
		p_q->p_data[p_q->back] = a;
		p_q->back = ++p_q->back % p_q->size;

		return 0;
	}
}
/* Mete un nuevo cliente en el servidor
 *
 * PRE: ta == tiempo (absoluto) de arribo del cliente al sistema
 *	CASE1: !busy
 *	CASE2:  busy
 *
 * accepted = receive_customer (q, ta, &busy, &tsal)
 *
 * POS: !accepted	   => servidor lleno, cliente rechazado
 *
 *	 accepted && CASE1 => el servidor estaba vacio, atendimos al cliente
 *			      *tsal contiene el proximo tiempo (abs) de salida
 *
 *	 accepted && CASE2 => el servidor estaba ocupado, cliente puesto en cola
 *			      *tsal no fue modificado
 */
static bool receive_customer (queue_t q, double ta, bool *busy, double *tsal)
{
	bool accepted = true;
	
	if (q_is_full(q))
		/* Servidor lleno => se descarta al cliente */
		accepted = false;
	
	else {
		q_enqueue (q, ta);
		
		if (!(*busy)) {
			/* Servidor vacío => se atiende al cliente directamente */
			*tsal = ta + gen_exp (Ts);
			*busy = true;
		}
		/* else: Servidor ocupado => sólo encolabamos al cliente */
	}
	
	return accepted;
}