libsc
2.8.7
The SC library provides support for parallel scientific applications.
|
Provide reference counting facilities. More...
#include <sc.h>
Go to the source code of this file.
Data Structures | |
struct | sc_refcount |
The refcount structure is declared in public so its size is known. More... | |
Typedefs | |
typedef struct sc_refcount | sc_refcount_t |
The refcount structure is declared in public so its size is known. More... | |
Functions | |
void | sc_refcount_init_invalid (sc_refcount_t *rc) |
Initialize a well-defined but unusable reference counter. More... | |
void | sc_refcount_init (sc_refcount_t *rc, int package_id) |
Initialize a reference counter to 1. More... | |
sc_refcount_t * | sc_refcount_new (int package_id) |
Create a new reference counter with count initialized to 1. More... | |
void | sc_refcount_destroy (sc_refcount_t *rc) |
Destroy a reference counter. More... | |
void | sc_refcount_ref (sc_refcount_t *rc) |
Increase a reference counter. More... | |
int | sc_refcount_unref (sc_refcount_t *rc) |
Decrease the reference counter and notify when it reaches zero. More... | |
int | sc_refcount_is_active (const sc_refcount_t *rc) |
Check whether a reference counter has a positive value. More... | |
int | sc_refcount_is_last (const sc_refcount_t *rc) |
Check whether a reference counter has value one. More... | |
Provide reference counting facilities.
The functions in this file can be used for multiple purposes. The current setup is not so much targeted at garbage collection but rather intended for debugging and verification.
typedef struct sc_refcount sc_refcount_t |
The refcount structure is declared in public so its size is known.
Its members should really never be accessed directly.
void sc_refcount_destroy | ( | sc_refcount_t * | rc | ) |
Destroy a reference counter.
It must have been counted down to zero before, thus reached an inactive state.
[in,out] | rc | This reference counter must have reached count zero. |
void sc_refcount_init | ( | sc_refcount_t * | rc, |
int | package_id | ||
) |
Initialize a reference counter to 1.
It is legal if its status prior to this call is undefined.
[out] | rc | This reference counter is initialized to one. The object's contents may be undefined on input. |
[in] | package_id | Either -1 or a package registered to libsc. |
void sc_refcount_init_invalid | ( | sc_refcount_t * | rc | ) |
Initialize a well-defined but unusable reference counter.
Specifically, we set its package identifier and reference count to -1. To make this reference counter usable, call sc_refcount_init.
[out] | rc | This reference counter is defined as invalid. It will return false on both sc_refcount_is_active and sc_refcount_is_last. It can be made valid by calling sc_refcount_init. No other functions must be called on it. |
int sc_refcount_is_active | ( | const sc_refcount_t * | rc | ) |
Check whether a reference counter has a positive value.
This means that the reference counter is in use and corresponds to a live object.
[in] | rc | A reference counter. |
int sc_refcount_is_last | ( | const sc_refcount_t * | rc | ) |
Check whether a reference counter has value one.
This means that this counter is the last of its kind, which we may optimize for.
[in] | rc | A reference counter. |
sc_refcount_t* sc_refcount_new | ( | int | package_id | ) |
Create a new reference counter with count initialized to 1.
Equivalent to calling sc_refcount_init on a newly allocated rc object.
[in] | package_id | Either -1 or a package registered to libsc. |
void sc_refcount_ref | ( | sc_refcount_t * | rc | ) |
Increase a reference counter.
The counter must be active, that is, have a value greater than zero.
[in,out] | rc | This reference counter must be valid (greater zero). Its count is increased by one. |
int sc_refcount_unref | ( | sc_refcount_t * | rc | ) |
Decrease the reference counter and notify when it reaches zero.
The count must be greater zero on input. If the reference count reaches zero, which is indicated by the return value, the counter may not be used further with sc_refcount_ref or
[in,out] | rc | This reference counter must be valid (greater zero). Its count is decreased by one. |