/*
* Copyright (C) 2004-2007, 2012 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 2001, 2003 Internet Software Consortium.
*
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id$ */
#ifndef ISC_REFCOUNT_H
#include <isc/platform.h>
/*! \file isc/refcount.h
* \brief Implements a locked reference counter.
*
* These functions may actually be
* implemented using macros, and implementations of these macros are below.
* The isc_refcount_t type should not be accessed directly, as its contents
* depend on the implementation.
*/
/*
* Function prototypes
*/
/*
* isc_result_t
* isc_refcount_init(isc_refcount_t *ref, unsigned int n);
*
* Initialize the reference counter. There will be 'n' initial references.
*
* Requires:
* ref != NULL
*/
/*
* void
* isc_refcount_destroy(isc_refcount_t *ref);
*
* Destroys a reference counter.
*
* Requires:
* ref != NULL
* The number of references is 0.
*/
/*
* void
* isc_refcount_increment(isc_refcount_t *ref, unsigned int *targetp);
* isc_refcount_increment0(isc_refcount_t *ref, unsigned int *targetp);
*
* Increments the reference count, returning the new value in targetp if it's
* not NULL. The reference counter typically begins with the initial counter
* of 1, and will be destroyed once the counter reaches 0. Thus,
* isc_refcount_increment() additionally requires the previous counter be
* larger than 0 so that an error which violates the usage can be easily
* caught. isc_refcount_increment0() does not have this restriction.
*
* Requires:
* ref != NULL.
*/
/*
* void
* isc_refcount_decrement(isc_refcount_t *ref, unsigned int *targetp);
*
* Decrements the reference count, returning the new value in targetp if it's
* not NULL.
*
* Requires:
* ref != NULL.
*/
/*
* Sample implementations
*/
#ifdef ISC_PLATFORM_USETHREADS
#ifdef ISC_PLATFORM_HAVEXADD
typedef struct isc_refcount {
do { \
isc_int32_t prev; \
} while (0)
do { \
isc_int32_t prev; \
} while (0)
do { \
isc_int32_t prev; \
} while (0)
#else /* ISC_PLATFORM_HAVEXADD */
typedef struct isc_refcount {
int refs;
/*% Destroys a reference counter. */
#define isc_refcount_destroy(rp) \
do { \
} while (0)
/*% Increments the reference count, returning the new value in targetp if it's not NULL. */
do { \
} while (0)
do { \
} while (0)
/*% Decrements the reference count, returning the new value in targetp if it's not NULL. */
do { \
} while (0)
#endif /* ISC_PLATFORM_HAVEXADD */
#else /* ISC_PLATFORM_USETHREADS */
typedef struct isc_refcount {
int refs;
do { \
} while (0)
do { \
int _n; \
} while (0)
do { \
int _n; \
} while (0)
#endif /* ISC_PLATFORM_USETHREADS */
#endif /* ISC_REFCOUNT_H */