/*1This file is part of t8code.2t8code is a C library to manage a collection (a forest) of multiple3connected adaptive space-trees of general element classes in parallel.45Copyright (C) 2015 the developers67t8code is free software; you can redistribute it and/or modify8it under the terms of the GNU General Public License as published by9the Free Software Foundation; either version 2 of the License, or10(at your option) any later version.1112t8code is distributed in the hope that it will be useful,13but WITHOUT ANY WARRANTY; without even the implied warranty of14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15GNU General Public License for more details.1617You should have received a copy of the GNU General Public License18along with t8code; if not, write to the Free Software Foundation, Inc.,1951 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.20*/2122/** \file t8_refcount.h23*24* We inherit the reference counting mechanism from libsc.25* The only customization is to pass the package id of the t8code.26* This file is compatible with sc_refcount_ref and sc_refcount_unref.27*/2829#ifndef T8_REFCOUNT_H30#define T8_REFCOUNT_H3132#include <t8.h>33#include <sc_refcount.h>3435/** We want to export the whole implementation to be callable from "C". */36T8_EXTERN_C_BEGIN ();3738/** We can reuse the reference counter type from libsc. */39typedef sc_refcount_t t8_refcount_t;4041/** Initialize a reference counter to 1.42* It is legal if its status prior to this call is undefined.43* \param [out] rc The reference counter is set to one by this call.44*/45void46t8_refcount_init (t8_refcount_t *rc);4748/** Create a new reference counter with count initialized to 1.49* Equivalent to calling t8_refcount_init on a newly allocated refcount_t.50* It is mandatory to free this with \ref t8_refcount_destroy.51* \return An allocated reference counter whose count has been set to one.52*/53t8_refcount_t *54t8_refcount_new (void);5556/** Destroy a reference counter that we allocated with \ref t8_refcount_new.57* Its reference count must have decreased to zero.58* \param [in,out] rc Allocated, formerly valid reference counter.59*/60void61t8_refcount_destroy (t8_refcount_t *rc);6263/** Increase the reference count by one.64* It is not necessary to duplicate this functionality as a function. */65#define t8_refcount_ref(rc) sc_refcount_ref (rc)6667/** Decrease the reference count by one.68* The count must be greater zero on input. If the reference count reaches69* zero, which is indicated by the return value, the counter may NOT be used70* further with \ref t8_refcount_ref or \see t8_refcount_unref. It IS legal to71* query it with \ref t8_refcount_is_active and \ref t8_refcount_is_last and to72* repurpose it later by calling \ref t8_refcount_init.73* It is not necessary to duplicate this functionality as a function.74* \param [in] rc Reference counter75* \return true if and only if the refcount is 0 after the operation.76*/77#define t8_refcount_unref(rc) sc_refcount_unref (rc)7879/** Query whether a reference counter is has a positive value. */80#define t8_refcount_is_active(rc) sc_refcount_is_active (rc)8182/** Query whether a reference counter has value one. */83#define t8_refcount_is_last(rc) sc_refcount_is_last (rc)8485/** End of code that is callable from "C".*/86T8_EXTERN_C_END ();8788#endif /* !T8_REFCOUNT_H */899091