Coverage report for dbus/dbus-resources.c.gcov

        -:    0:Source:dbus-resources.c
        -:    0:Graph:.libs/dbus-resources.gcno
        -:    0:Data:.libs/dbus-resources.gcda
        -:    0:Runs:11811
        -:    0:Programs:5
        -:    1:/* -*- mode: C; c-file-style: "gnu" -*- */
        -:    2:/* dbus-resources.c Resource tracking/limits
        -:    3: *
        -:    4: * Copyright (C) 2003  Red Hat Inc.
        -:    5: *
        -:    6: * Licensed under the Academic Free License version 2.1
        -:    7: * 
        -:    8: * This program is free software; you can redistribute it and/or modify
        -:    9: * it under the terms of the GNU General Public License as published by
        -:   10: * the Free Software Foundation; either version 2 of the License, or
        -:   11: * (at your option) any later version.
        -:   12: *
        -:   13: * This program is distributed in the hope that it will be useful,
        -:   14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
        -:   15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        -:   16: * GNU General Public License for more details.
        -:   17: * 
        -:   18: * You should have received a copy of the GNU General Public License
        -:   19: * along with this program; if not, write to the Free Software
        -:   20: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        -:   21: *
        -:   22: */
        -:   23:#include <dbus/dbus-resources.h>
        -:   24:#include <dbus/dbus-internals.h>
        -:   25:
        -:   26:/**
        -:   27: * @defgroup DBusResources Resource limits related code
        -:   28: * @ingroup  DBusInternals
        -:   29: * @brief DBusCounter and other stuff related to resource limits
        -:   30: *
        -:   31: * Types and functions related to tracking resource limits,
        -:   32: * such as the maximum amount of memory a connection can use
        -:   33: * for messages, etc.
        -:   34: */
        -:   35:
        -:   36:/**
        -:   37: * @defgroup DBusResourcesInternals Resource limits implementation details
        -:   38: * @ingroup  DBusInternals
        -:   39: * @brief Resource limits implementation details
        -:   40: *
        -:   41: * Implementation details of resource limits code.
        -:   42: *
        -:   43: * @{
        -:   44: */
        -:   45:
        -:   46:/**
        -:   47: * @brief Internals of DBusCounter.
        -:   48: * 
        -:   49: * DBusCounter internals. DBusCounter is an opaque object, it must be
        -:   50: * used via accessor functions.
        -:   51: */
        -:   52:struct DBusCounter
        -:   53:{
        -:   54:  int refcount;  /**< reference count */
        -:   55:
        -:   56:  long value;    /**< current counter value */
        -:   57:
        -:   58:  long notify_guard_value; /**< call notify function when crossing this value */
        -:   59:  DBusCounterNotifyFunction notify_function; /**< notify function */
        -:   60:  void *notify_data; /**< data for notify function */
        -:   61:};
        -:   62:
        -:   63:/** @} */  /* end of resource limits internals docs */
        -:   64:
        -:   65:/**
        -:   66: * @addtogroup DBusResources
        -:   67: * @{
        -:   68: */
        -:   69:
        -:   70:/**
        -:   71: * Creates a new DBusCounter. DBusCounter is used
        -:   72: * to count usage of some resource such as memory.
        -:   73: *
        -:   74: * @returns new counter or #NULL on failure
        -:   75: */
        -:   76:DBusCounter*
        -:   77:_dbus_counter_new (void)
function _dbus_counter_new called 28983 returned 100% blocks executed 100%
    28983:   78:{
        -:   79:  DBusCounter *counter;
        -:   80:
    28983:   81:  counter = dbus_new (DBusCounter, 1);
call    0 returned 100%
    28983:   82:  if (counter == NULL)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
       30:   83:    return NULL;
        -:   84:  
    28953:   85:  counter->refcount = 1;
    28953:   86:  counter->value = 0;
        -:   87:
    28953:   88:  counter->notify_guard_value = 0;
    28953:   89:  counter->notify_function = NULL;
    28953:   90:  counter->notify_data = NULL;
        -:   91:  
    28953:   92:  return counter;
        -:   93:}
        -:   94:
        -:   95:/**
        -:   96: * Increments refcount of the counter
        -:   97: *
        -:   98: * @param counter the counter
        -:   99: * @returns the counter
        -:  100: */
        -:  101:DBusCounter *
        -:  102:_dbus_counter_ref (DBusCounter *counter)
function _dbus_counter_ref called 156253 returned 100% blocks executed 100%
   156253:  103:{
   156253:  104:  _dbus_assert (counter->refcount > 0);
call    0 returned 100%
        -:  105:  
   156253:  106:  counter->refcount += 1;
        -:  107:
   156253:  108:  return counter;
        -:  109:}
        -:  110:
        -:  111:/**
        -:  112: * Decrements refcount of the counter and possibly
        -:  113: * finalizes the counter.
        -:  114: *
        -:  115: * @param counter the counter
        -:  116: */
        -:  117:void
        -:  118:_dbus_counter_unref (DBusCounter *counter)
function _dbus_counter_unref called 183955 returned 100% blocks executed 100%
   183955:  119:{
   183955:  120:  _dbus_assert (counter->refcount > 0);
call    0 returned 100%
        -:  121:
   183955:  122:  counter->refcount -= 1;
        -:  123:
   183955:  124:  if (counter->refcount == 0)
branch  0 taken 15% (fallthrough)
branch  1 taken 85%
        -:  125:    {
        -:  126:      
    28119:  127:      dbus_free (counter);
call    0 returned 100%
        -:  128:    }
   183955:  129:}
        -:  130:
        -:  131:/**
        -:  132: * Adjusts the value of the counter by the given
        -:  133: * delta which may be positive or negative.
        -:  134: * Calls the notify function from _dbus_counter_set_notify()
        -:  135: * if that function has been specified.
        -:  136: *
        -:  137: * @param counter the counter
        -:  138: * @param delta value to add to the counter's current value
        -:  139: */
        -:  140:void
        -:  141:_dbus_counter_adjust (DBusCounter *counter,
        -:  142:                      long         delta)
function _dbus_counter_adjust called 289449 returned 100% blocks executed 71%
   289449:  143:{
   289449:  144:  long old = counter->value;
        -:  145:  
   289449:  146:  counter->value += delta;
        -:  147:
        -:  148:#if 0
        -:  149:  _dbus_verbose ("Adjusting counter %ld by %ld = %ld\n",
        -:  150:                 old, delta, counter->value);
        -:  151:#endif
        -:  152:  
   289449:  153:  if (counter->notify_function != NULL &&
branch  0 taken 48% (fallthrough)
branch  1 taken 52%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 0% (fallthrough)
branch  7 taken 100%
branch  8 never executed
branch  9 never executed
        -:  154:      ((old < counter->notify_guard_value &&
        -:  155:        counter->value >= counter->notify_guard_value) ||
        -:  156:       (old >= counter->notify_guard_value &&
        -:  157:        counter->value < counter->notify_guard_value)))
    #####:  158:    (* counter->notify_function) (counter, counter->notify_data);
call    0 never executed
   289449:  159:}
        -:  160:
        -:  161:/**
        -:  162: * Gets the current value of the counter.
        -:  163: *
        -:  164: * @param counter the counter
        -:  165: * @returns its current value
        -:  166: */
        -:  167:long
        -:  168:_dbus_counter_get_value (DBusCounter *counter)
function _dbus_counter_get_value called 1705229 returned 100% blocks executed 100%
  1705229:  169:{
  1705229:  170:  return counter->value;
        -:  171:}
        -:  172:
        -:  173:/**
        -:  174: * Sets the notify function for this counter; the notify function is
        -:  175: * called whenever the counter's value crosses the guard value in
        -:  176: * either direction (moving up, or moving down).
        -:  177: *
        -:  178: * @param counter the counter
        -:  179: * @param guard_value the value we're notified if the counter crosses
        -:  180: * @param function function to call in order to notify
        -:  181: * @param user_data data to pass to the function
        -:  182: */
        -:  183:void
        -:  184:_dbus_counter_set_notify (DBusCounter               *counter,
        -:  185:                          long                       guard_value,
        -:  186:                          DBusCounterNotifyFunction  function,
        -:  187:                          void                      *user_data)
function _dbus_counter_set_notify called 36767 returned 100% blocks executed 100%
    36767:  188:{
    36767:  189:  counter->notify_guard_value = guard_value;
    36767:  190:  counter->notify_function = function;
    36767:  191:  counter->notify_data = user_data;
    36767:  192:}
        -:  193:
        -:  194:/** @} */  /* end of resource limits exported API */