Exemplo n.º 1
0
void *
osip_fifo_get (osip_fifo_t * ff)
{
  void *el;
  int i = osip_sem_wait (ff->qisempty);

  if (i != 0)
    return NULL;
  osip_mutex_lock (ff->qislocked);

  if (ff->etat != vide)
    {
      el = osip_list_get (ff->queue, 0);
      osip_list_remove (ff->queue, 0);
      /* ff->nb_elt--; */
    }
  else
    {
      OSIP_TRACE (osip_trace
		  (__FILE__, __LINE__, OSIP_ERROR, NULL,
		   "no element in fifo.\n"));
      osip_mutex_unlock (ff->qislocked);
      return 0;			/* pile vide */
    }
  /* if (ff->nb_elt <= 0) */
  if (osip_list_size (ff->queue) <= 0)
    ff->etat = vide;
  else
    ff->etat = ok;

  osip_mutex_unlock (ff->qislocked);
  return el;
}
Exemplo n.º 2
0
void *
osip_fifo_get (osip_fifo_t * ff)
{
  void *el = NULL;

#ifdef OSIP_MT
  int i = osip_sem_wait (ff->qisempty);

  if (i != 0)
    return NULL;
  osip_mutex_lock (ff->qislocked);
#endif

  if (ff->state != osip_empty)
    {
      el = osip_list_get (&ff->queue, 0);
      osip_list_remove (&ff->queue, 0);
      /* ff->nb_elt--; */
  } else
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL, "no element in fifo.\n"));
#ifdef OSIP_MT
      osip_mutex_unlock (ff->qislocked);
#endif
      return 0;                 /* pile vide */
    }
  /* if (ff->nb_elt <= 0) */
  if (osip_list_size (&ff->queue) <= 0)
    ff->state = osip_empty;
  else
    ff->state = osip_ok;

#ifdef OSIP_MT
  osip_mutex_unlock (ff->qislocked);
#endif
  return el;
}
Exemplo n.º 3
0
int
osip_cond_wait (struct osip_cond *_cond, struct osip_mutex *_mut)
{
  int ret1 = 0, ret2 = 0, ret3 = 0;

  if (!_cond) return -1;

  if (osip_mutex_lock (_cond->mut))
    return -1;

  if (osip_mutex_unlock (_mut))
    return -1;

  ret1 = osip_sem_wait (_cond->sem);

  ret2 = osip_mutex_lock (_mut);

  ret3 = osip_mutex_unlock (_cond->mut);

  if (ret1 || ret2 || ret3)
    return -1;
  return 0;
}