Ejemplo n.º 1
0
static void
z_stacked_proxy_unref(ZStackedProxy *self)
{
  if (self && z_refcount_dec(&self->ref_cnt))
    {
      g_free(self);
    }
}
Ejemplo n.º 2
0
/**
 * Decrease reference count of a blob system; destroy it if the count reaches zero.
 *
 * @param[in] self the blob system object
 *
 * This function decreases the reference count of the blob system
 * object given. If the reference count reaches zero, the blob system
 * will be destroyed. If there were pending requests in a to-be-destroyed
 * blob system, this fact will be logged.
 **/
void
z_blob_system_unref(ZBlobSystem *self)
{
  ZBlob *blob;
  GList *cur, *next;
  gint n;

  z_enter();
  g_assert(self); 
  if (z_refcount_dec(&self->ref_cnt))
    {
      self->active = FALSE;
      /** @todo FIXME: itt lockolni kell */
      g_async_queue_push(self->req_queue, Z_BLOB_THREAD_KILL);
      g_thread_join(self->thr_management);

      n = 0;
      for (cur = self->waiting_list; cur; cur = next)
        {
          next = cur->next;
          blob = (ZBlob*) cur->data;
          blob->approved = FALSE;
          z_blob_signal_ready(blob);
          self->waiting_list = g_list_delete_link(self->waiting_list, cur);
          n++;
        }
      if (n)
        z_log(NULL, CORE_INFO, 5, "Pending requests found for a to-be-destroyed blob system; num_requests='%d'", n);

      n = 0;
      for (cur = self->blobs; cur; cur = next)
        {
          next = cur->next;
          blob = (ZBlob*)cur->data;
          z_blob_unref(blob);
          n++;
        }
      if (n)
        z_log(NULL, CORE_INFO, 5, "Active blobs found in a to-be-destroyed blob system; num_blobs='%d'", n);

      if (self->dir)
        g_free(self->dir);
      if (g_mutex_trylock(self->mtx_blobsys))
        {
          g_mutex_unlock(self->mtx_blobsys);
          g_mutex_free(self->mtx_blobsys);
        }
      else
        {
          /* Some blob operations are in progress: z_blob_new, _unref, _alloc, _get_file */
        }
      g_cond_free(self->cond_thread_started);
      g_async_queue_unref(self->req_queue);
      g_list_free(self->waiting_list);
      g_free(self);
    }
  z_return();
}
Ejemplo n.º 3
0
static void
z_stacked_proxy_unref(ZStackedProxy *self)
{
  if (self && z_refcount_dec(&self->ref_cnt))
    {
      g_static_mutex_free(&self->destroy_lock);
      g_free(self);
    }
}
Ejemplo n.º 4
0
/**
 * z_listener_entry_unref:
 * @self: listener entry
 *
 * Decreases the reference count of the listener entry. If it reaches zero, the listener entry is freed
 * and the reference count listener inside of the object is decreased.
 *
 * Returns true if the entry is freed
 */
gboolean
z_listener_entry_unref(ZListenerEntry *self)
{
  if (self && z_refcount_dec(&self->ref_cnt))
    {
      z_listener_entry_destroy(self);
      return TRUE;
    }
  return FALSE;
}
Ejemplo n.º 5
0
/**
 * Decrement the reference count of a ZSockAddr instance, and free if
 * the refcnt reaches 0.
 *
 * @param[in] a ZSockAddr instance
 **/
void 
z_sockaddr_unref(ZSockAddr *a)
{
  if (a && z_refcount_dec(&a->refcnt)) 
    {
      if (!a->sa_funcs->freefn)
        g_free(a);
      else
        a->sa_funcs->freefn(a);
    }
}
Ejemplo n.º 6
0
/**
 * z_dispatch_bind_unref: 
 * @self: this
 *
 * Decrement reference count for @self and free if that reaches zero.
 *
 **/
void
z_dispatch_bind_unref(ZDispatchBind *self)
{
  if (self && z_refcount_dec(&self->ref_cnt))
    {
      if (self->type == ZD_BIND_SOCKADDR)
        z_sockaddr_unref(self->sa.addr);
      
      g_free(self);
      
    }
}
Ejemplo n.º 7
0
/**
 * Decrease reference count of blob; destroy it if the count reaches zero.
 *
 * @param[in] self this
 **/
void
z_blob_unref(ZBlob *self)
{
  z_enter();
  if (self && z_refcount_dec(&self->ref_cnt))
    {
      g_mutex_lock(self->system->mtx_blobsys);
      self->alloc_req = -self->alloc_size;
      self->system->blobs = g_list_remove(self->system->blobs, self);
      z_blob_check_alloc(self);
      g_mutex_unlock(self->system->mtx_blobsys);

      if (self->data)
        g_free(self->data);

      if (self->fd >= 0)
        close(self->fd);

      if (self->filename)
        {
          if (unlink(self->filename))
            z_log(NULL, CORE_ERROR, 3, "Error removing blob file, unlink() failed; file='%s', error='%s'", self->filename, strerror(errno));
          g_free(self->filename);
          self->filename = NULL;
        }

      g_mutex_free(self->mtx_reply);
      g_cond_free(self->cond_reply);
      if (g_mutex_trylock(self->mtx_lock))
        {
          g_mutex_unlock(self->mtx_lock);
          g_mutex_free(self->mtx_lock);
        }
      else
        {
          z_log(NULL, CORE_ERROR, 3, "Error while destroying blob, someone still has a lock on it;");
          /* someone has locked the blob by z_blob_get_file or _get_ptr, and forgot to release it */
        }
      g_free(self);
    }
  z_return();
}