コード例 #1
0
ファイル: dbus-memory.c プロジェクト: 325116067/semc-qsd8x50
/**
 * Frees a block of memory previously allocated by dbus_malloc() or
 * dbus_malloc0(). If passed #NULL, does nothing.
 * 
 * @param memory block to be freed
 */
void
dbus_free (void  *memory)
{
#ifdef DBUS_BUILD_TESTS
  if (guards)
    {
      check_guards (memory, TRUE);
      if (memory)
        {
	  _dbus_atomic_dec (&n_blocks_outstanding);
          
	  _dbus_assert (n_blocks_outstanding.value >= 0);
          
          free (((unsigned char*)memory) - GUARD_START_OFFSET);
        }
      
      return;
    }
#endif
    
  if (memory) /* we guarantee it's safe to free (NULL) */
    {
#ifdef DBUS_BUILD_TESTS
      _dbus_atomic_dec (&n_blocks_outstanding);
      
      _dbus_assert (n_blocks_outstanding.value >= 0);
#endif

      free (memory);
    }
}
コード例 #2
0
EXPORT_C 
#endif
void
dbus_pending_call_unref (DBusPendingCall *pending)
{
  dbus_bool_t last_unref;

  _dbus_return_if_fail (pending != NULL);

  /* More efficient to use the connection lock instead of atomic
   * int fallback if we lack atomic int decrement
   */
#ifdef DBUS_HAVE_ATOMIC_INT
  last_unref = (_dbus_atomic_dec (&pending->refcount) == 1);
#else
  CONNECTION_LOCK (pending->connection);
  _dbus_assert (pending->refcount.value > 0);
  pending->refcount.value -= 1;
  last_unref = pending->refcount.value == 0;
  CONNECTION_UNLOCK (pending->connection);
#endif
  
  if (last_unref)
    _dbus_pending_call_last_unref(pending);
}
コード例 #3
0
ファイル: dbus-server.c プロジェクト: balagopalraj/clearlinux
/**
 * Like dbus_server_unref() but does not acquire the lock (must already be held)
 *
 * @param server the server.
 */
void
_dbus_server_unref_unlocked (DBusServer *server)
{
    dbus_int32_t old_refcount;

    /* Keep this in sync with dbus_server_unref */

    _dbus_assert (server != NULL);

    HAVE_LOCK_CHECK (server);

    old_refcount = _dbus_atomic_dec (&server->refcount);
    _dbus_assert (old_refcount > 0);

    _dbus_server_trace_ref (server, old_refcount, old_refcount - 1,
                            "unref_unlocked");

    if (old_refcount == 1)
    {
        _dbus_assert (server->disconnected);

        SERVER_UNLOCK (server);

        _dbus_assert (server->vtable->finalize != NULL);

        (* server->vtable->finalize) (server);
    }
}
コード例 #4
0
EXPORT_C 
#endif
void
dbus_server_unref (DBusServer *server)
{
  dbus_bool_t last_unref;

  /* keep this in sync with unref_unlocked */
  
  _dbus_return_if_fail (server != NULL);
  _dbus_return_if_fail (server->refcount.value > 0);

#ifdef DBUS_HAVE_ATOMIC_INT
  last_unref = (_dbus_atomic_dec (&server->refcount) == 1);
#else
  SERVER_LOCK (server);
  
  _dbus_assert (server->refcount.value > 0);

  server->refcount.value -= 1;
  last_unref = (server->refcount.value == 0);
  
  SERVER_UNLOCK (server);
#endif
  
  if (last_unref)
    {
      /* lock not held! */
      _dbus_assert (server->disconnected);
      
      _dbus_assert (server->vtable->finalize != NULL);
      
      (* server->vtable->finalize) (server);
    }
}
コード例 #5
0
/**
 * Like dbus_server_unref() but does not acquire the lock (must already be held)
 *
 * @param server the server.
 */
void
_dbus_server_unref_unlocked (DBusServer *server)
{
  dbus_bool_t last_unref;

  /* Keep this in sync with dbus_server_unref */
  
  _dbus_assert (server != NULL);
  _dbus_assert (server->refcount.value > 0);

  HAVE_LOCK_CHECK (server);
  
#ifdef DBUS_HAVE_ATOMIC_INT
  last_unref = (_dbus_atomic_dec (&server->refcount) == 1);
#else
  _dbus_assert (server->refcount.value > 0);

  server->refcount.value -= 1;
  last_unref = (server->refcount.value == 0);
#endif
  
  if (last_unref)
    {
      _dbus_assert (server->disconnected);
      
      SERVER_UNLOCK (server);
      
      _dbus_assert (server->vtable->finalize != NULL);
      
      (* server->vtable->finalize) (server);
    }
}
コード例 #6
0
/**
 * Frees a block of memory previously allocated by dbus_malloc() or
 * dbus_malloc0(). If passed #NULL, does nothing.
 * 
 * @param memory block to be freed
 */
void
dbus_free (void  *memory)
{
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
  if (guards)
    {
      check_guards (memory, TRUE);
      if (memory)
        {
#ifdef DBUS_DISABLE_ASSERT
          _dbus_atomic_dec (&n_blocks_outstanding);
#else
          dbus_int32_t old_value;

          old_value = _dbus_atomic_dec (&n_blocks_outstanding);
          _dbus_assert (old_value >= 1);
#endif

          free (((unsigned char*)memory) - GUARD_START_OFFSET);
          dbus_track_free (memory);
        }
      
      return;
    }
#endif
    
  if (memory) /* we guarantee it's safe to free (NULL) */
    {
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#ifdef DBUS_DISABLE_ASSERT
      _dbus_atomic_dec (&n_blocks_outstanding);
#else
      dbus_int32_t old_value;

      old_value = _dbus_atomic_dec (&n_blocks_outstanding);
      _dbus_assert (old_value >= 1);
#endif
#endif

      free (memory);
      dbus_track_free (memory);
    }
}
コード例 #7
0
/**
 * Decrements the reference count on a pending call,
 * freeing it if the count reaches 0.
 *
 * @param pending the pending call object
 */
void
dbus_pending_call_unref (DBusPendingCall *pending)
{
  dbus_bool_t last_unref;

  _dbus_return_if_fail (pending != NULL);

  last_unref = (_dbus_atomic_dec (&pending->refcount) == 1);

  if (last_unref)
    _dbus_pending_call_last_unref(pending);
}
コード例 #8
0
/**
 * Decrements the reference count on a pending call,
 * freeing it if the count reaches 0. Assumes
 * connection lock is already held.
 *
 * @param pending the pending call object
 */
void
_dbus_pending_call_unref_and_unlock (DBusPendingCall *pending)
{
  dbus_int32_t old_refcount;

  old_refcount = _dbus_atomic_dec (&pending->refcount);
  _dbus_assert (old_refcount > 0);

  CONNECTION_UNLOCK (pending->connection);

  if (old_refcount == 1)
    _dbus_pending_call_last_unref (pending);
}
コード例 #9
0
/**
 * Decrements the reference count on a pending call,
 * freeing it if the count reaches 0.
 *
 * @param pending the pending call object
 */
void
dbus_pending_call_unref (DBusPendingCall *pending)
{
  dbus_int32_t old_refcount;

  _dbus_return_if_fail (pending != NULL);

  old_refcount = _dbus_atomic_dec (&pending->refcount);
  _dbus_pending_call_trace_ref (pending, old_refcount, old_refcount - 1,
      "unref");

  if (old_refcount == 1)
    _dbus_pending_call_last_unref(pending);
}
コード例 #10
0
ファイル: dbus-server.c プロジェクト: balagopalraj/clearlinux
/**
 * Decrements the reference count of a DBusServer.  Finalizes the
 * server if the reference count reaches zero.
 *
 * The server must be disconnected before the refcount reaches zero.
 *
 * @param server the server.
 */
void
dbus_server_unref (DBusServer *server)
{
    dbus_int32_t old_refcount;

    /* keep this in sync with unref_unlocked */

    _dbus_return_if_fail (server != NULL);

    old_refcount = _dbus_atomic_dec (&server->refcount);

#ifndef DBUS_DISABLE_CHECKS
    if (_DBUS_UNLIKELY (old_refcount <= 0))
    {
        /* undo side-effect first
         * please do not try to simplify the code here by using
         * _dbus_atomic_get(), why we don't use it is
         * because it issues another atomic operation even though
         * DBUS_DISABLE_CHECKS defined.
         * Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68303
         */
        _dbus_atomic_inc (&server->refcount);
        _dbus_warn_check_failed (_dbus_return_if_fail_warning_format,
                                 _DBUS_FUNCTION_NAME, "old_refcount > 0",
                                 __FILE__, __LINE__);
        return;
    }
#endif

    _dbus_server_trace_ref (server, old_refcount, old_refcount - 1, "unref");

    if (old_refcount == 1)
    {
        /* lock not held! */
        _dbus_assert (server->disconnected);

        _dbus_assert (server->vtable->finalize != NULL);

        (* server->vtable->finalize) (server);
    }
}
コード例 #11
0
ファイル: dbus-server.c プロジェクト: halfline/dbus
/**
 * Increments the reference count of a DBusServer.
 *
 * @param server the server.
 * @returns the server
 */
DBusServer *
dbus_server_ref (DBusServer *server)
{
  dbus_int32_t old_refcount;

  _dbus_return_val_if_fail (server != NULL, NULL);

  old_refcount = _dbus_atomic_inc (&server->refcount);

#ifndef DBUS_DISABLE_CHECKS
  if (_DBUS_UNLIKELY (old_refcount <= 0))
    {
      _dbus_atomic_dec (&server->refcount);
      _dbus_warn_return_if_fail (_DBUS_FUNCTION_NAME, "old_refcount > 0",
                                 __FILE__, __LINE__);
      return NULL;
    }
#endif

  _dbus_server_trace_ref (server, old_refcount, old_refcount + 1, "ref");

  return server;
}