Exemple #1
0
void
sp_writer_free_block (ShmBlock * block)
{
    shm_alloc_space_block_dec (block->ablock);
    sp_shm_area_dec (block->pipe, block->area);
    spalloc_free (ShmBlock, block);
}
Exemple #2
0
static int
sp_shmbuf_dec (ShmPipe * self, ShmBuffer * buf, ShmBuffer * prev_buf)
{
    buf->use_count--;

    if (buf->use_count == 0) {
        /* Remove from linked list */
        if (prev_buf)
            prev_buf->next = buf->next;
        else
            self->buffers = buf->next;

        shm_alloc_space_block_dec (buf->block);
        sp_shm_area_dec (self, buf->shm_area);
        spalloc_free1 (sizeof (ShmBuffer) + sizeof (int) * buf->num_clients, buf);
        return 0;
    }

    return 1;
}
Exemple #3
0
static int
sp_shmbuf_dec (ShmPipe * self, ShmBuffer * buf, ShmBuffer * prev_buf,
    ShmClient * client, void **tag)
{
  int i;
  int had_client = 0;

  /**
   * Remove client from the list of buffer users. Here we make sure that
   * if a client closes connection but already decremented the use count
   * for this buffer, but other clients didn't have time to decrement
   * buffer will not be freed too early in sp_writer_close_client.
   */
  for (i = 0; i < buf->num_clients; i++) {
    if (buf->clients[i] == client->fd) {
      buf->clients[i] = -1;
      had_client = 1;
      break;
    }
  }
  assert (had_client);

  buf->use_count--;

  if (buf->use_count == 0) {
    /* Remove from linked list */
    if (prev_buf)
      prev_buf->next = buf->next;
    else
      self->buffers = buf->next;

    if (tag)
      *tag = buf->tag;
    shm_alloc_space_block_dec (buf->ablock);
    sp_shm_area_dec (self, buf->shm_area);
    spalloc_free1 (sizeof (ShmBuffer) + sizeof (int) * buf->num_clients, buf);
    return 0;
  }
  return 1;
}