|
@@ -7,13 +7,13 @@ extern "C"
|
|
|
#endif
|
|
|
|
|
|
/** \ingroup cds
|
|
|
- * @{
|
|
|
+ * @{
|
|
|
*
|
|
|
* \defgroup cds_ref_cnt Reference counting
|
|
|
*
|
|
|
* Experimental functions for reference counting (to simplify
|
|
|
* this code elsewhere).
|
|
|
- *
|
|
|
+ *
|
|
|
* Reference counter (\ref reference_counter_data_t) holds integer number which
|
|
|
* should be changed using functions \ref add_reference and \ref
|
|
|
* remove_reference. Using these functions is the number read/changed from
|
|
@@ -21,7 +21,7 @@ extern "C"
|
|
|
*
|
|
|
* Often used scenario:
|
|
|
* - list of structures, change in the list (adding, removing) is guarded by
|
|
|
- * one mutex,
|
|
|
+ * one mutex,
|
|
|
* - each structure has reference counter, when the count is zero, the
|
|
|
* structure can be removed from the list and freed
|
|
|
*
|
|
@@ -37,7 +37,7 @@ extern "C"
|
|
|
* };
|
|
|
*
|
|
|
* reference_counter_group_t *some_grp;
|
|
|
- *
|
|
|
+ *
|
|
|
* void init()
|
|
|
* {
|
|
|
* some_grp = init_reference_counter_group(16);
|
|
@@ -47,7 +47,7 @@ extern "C"
|
|
|
* {
|
|
|
* free_reference_counter_group(some_grp);
|
|
|
* }
|
|
|
- *
|
|
|
+ *
|
|
|
* ...
|
|
|
*
|
|
|
* // adding a member:
|
|
@@ -72,17 +72,17 @@ extern "C"
|
|
|
* free(ss);
|
|
|
* unlock(list);
|
|
|
* }
|
|
|
- *
|
|
|
- * // or
|
|
|
- * // releasing a member when not needed for caller and it is possible
|
|
|
- * // to 'search' in the list (reference to released member can be somehow
|
|
|
+ *
|
|
|
+ * // or
|
|
|
+ * // releasing a member when not needed for caller and it is possible
|
|
|
+ * // to 'search' in the list (reference to released member can be somehow
|
|
|
* // obtained by inspecting the list):
|
|
|
* lock(list);
|
|
|
* if (remove_reference(&ss->ref)) {
|
|
|
* // last reference removed
|
|
|
* remove_from_list(ss);
|
|
|
* free(ss);
|
|
|
- * }
|
|
|
+ * }
|
|
|
* unlock(list);
|
|
|
* \endcode
|
|
|
*
|
|
@@ -98,15 +98,15 @@ extern "C"
|
|
|
cds_mutex_t *mutex; /**< mutex assigned to this reference counter */
|
|
|
} reference_counter_data_t;
|
|
|
|
|
|
- /** Structure holding information about group of reference counters.
|
|
|
- * It holds array of mutexes which are assigned to single reference
|
|
|
- * counters in this group. The assignment is done using an operation
|
|
|
+ /** Structure holding information about group of reference counters.
|
|
|
+ * It holds array of mutexes which are assigned to single reference
|
|
|
+ * counters in this group. The assignment is done using an operation
|
|
|
* on pointer to reference_counter_data_t. */
|
|
|
typedef struct
|
|
|
{
|
|
|
int mutex_cnt; /**< number of mutexes for this group */
|
|
|
|
|
|
- /** number of next mutex to be assigned - this member is NOT
|
|
|
+ /** number of next mutex to be assigned - this member is NOT
|
|
|
* read/changed from critical section but it doesn't matter
|
|
|
* if it will be rewritten between processes because it is used
|
|
|
* for load distributing only (the worst thing that can happen
|
|
@@ -116,13 +116,13 @@ extern "C"
|
|
|
[1]; /**< array of mutexes (allocated together with the structure)*/
|
|
|
} reference_counter_group_t;
|
|
|
|
|
|
- /** Initializes reference counter - sets its value to 1.
|
|
|
- * After call to this function, the caller is owner of first
|
|
|
+ /** Initializes reference counter - sets its value to 1.
|
|
|
+ * After call to this function, the caller is owner of first
|
|
|
* reference. From now it can call other functions like
|
|
|
- * \ref add_reference or \ref remove_reference.
|
|
|
+ * \ref add_reference or \ref remove_reference.
|
|
|
*
|
|
|
- * This function initializes the mutex - it chooses one from
|
|
|
- * group mutexes. The mutex can not be changed after this
|
|
|
+ * This function initializes the mutex - it chooses one from
|
|
|
+ * group mutexes. The mutex can not be changed after this
|
|
|
* call (it is only for reading). */
|
|
|
void init_reference_counter(
|
|
|
reference_counter_group_t *grp, reference_counter_data_t *ref);
|
|
@@ -143,7 +143,7 @@ extern "C"
|
|
|
* */
|
|
|
int remove_reference(reference_counter_data_t *ref);
|
|
|
|
|
|
- /** Creates and initializes group of reference counters. All reference
|
|
|
+ /** Creates and initializes group of reference counters. All reference
|
|
|
* counters 'belonging' to this group are using the same set of mutexes. */
|
|
|
reference_counter_group_t *create_reference_counter_group(int mutex_cnt);
|
|
|
|
|
@@ -152,7 +152,7 @@ extern "C"
|
|
|
* by this group can be used. */
|
|
|
void free_reference_counter_group(reference_counter_group_t *grp);
|
|
|
|
|
|
- /** @}
|
|
|
+ /** @}
|
|
|
* @} */
|
|
|
|
|
|
#ifdef __cplusplus
|