Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DLR-AMR
GitHub Repository: DLR-AMR/t8code
Path: blob/main/src/t8_refcount.h
898 views
1
/*
2
This file is part of t8code.
3
t8code is a C library to manage a collection (a forest) of multiple
4
connected adaptive space-trees of general element classes in parallel.
5
6
Copyright (C) 2015 the developers
7
8
t8code 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
t8code 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 t8code; if not, write to the Free Software Foundation, Inc.,
20
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
*/
22
23
/** \file t8_refcount.h
24
*
25
* We inherit the reference counting mechanism from libsc.
26
* The only customization is to pass the package id of the t8code.
27
* This file is compatible with sc_refcount_ref and sc_refcount_unref.
28
*/
29
30
#ifndef T8_REFCOUNT_H
31
#define T8_REFCOUNT_H
32
33
#include <t8.h>
34
#include <sc_refcount.h>
35
36
/** We want to export the whole implementation to be callable from "C". */
37
T8_EXTERN_C_BEGIN ();
38
39
/** We can reuse the reference counter type from libsc. */
40
typedef sc_refcount_t t8_refcount_t;
41
42
/** Initialize a reference counter to 1.
43
* It is legal if its status prior to this call is undefined.
44
* \param [out] rc The reference counter is set to one by this call.
45
*/
46
void
47
t8_refcount_init (t8_refcount_t *rc);
48
49
/** Create a new reference counter with count initialized to 1.
50
* Equivalent to calling t8_refcount_init on a newly allocated refcount_t.
51
* It is mandatory to free this with \ref t8_refcount_destroy.
52
* \return An allocated reference counter whose count has been set to one.
53
*/
54
t8_refcount_t *
55
t8_refcount_new (void);
56
57
/** Destroy a reference counter that we allocated with \ref t8_refcount_new.
58
* Its reference count must have decreased to zero.
59
* \param [in,out] rc Allocated, formerly valid reference counter.
60
*/
61
void
62
t8_refcount_destroy (t8_refcount_t *rc);
63
64
/** Increase the reference count by one.
65
* It is not necessary to duplicate this functionality as a function. */
66
#define t8_refcount_ref(rc) sc_refcount_ref (rc)
67
68
/** Decrease the reference count by one.
69
* The count must be greater zero on input. If the reference count reaches
70
* zero, which is indicated by the return value, the counter may NOT be used
71
* further with \ref t8_refcount_ref or \see t8_refcount_unref. It IS legal to
72
* query it with \ref t8_refcount_is_active and \ref t8_refcount_is_last and to
73
* repurpose it later by calling \ref t8_refcount_init.
74
* It is not necessary to duplicate this functionality as a function.
75
* \param [in] rc Reference counter
76
* \return true if and only if the refcount is 0 after the operation.
77
*/
78
#define t8_refcount_unref(rc) sc_refcount_unref (rc)
79
80
/** Query whether a reference counter is has a positive value. */
81
#define t8_refcount_is_active(rc) sc_refcount_is_active (rc)
82
83
/** Query whether a reference counter has value one. */
84
#define t8_refcount_is_last(rc) sc_refcount_is_last (rc)
85
86
/** End of code that is callable from "C".*/
87
T8_EXTERN_C_END ();
88
89
#endif /* !T8_REFCOUNT_H */
90
91