amino
Lightweight Robot Utility Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
refcount.h
1 /* -*- mode: C; c-basic-offset: 4 -*- */
2 /* ex: set shiftwidth=4 tabstop=4 expandtab: */
3 /*
4  * Copyright (c) 2016, Rice University
5  * All rights reserved.
6  *
7  * This file is provided under the following "BSD-style" License:
8  *
9  *
10  * Redistribution and use in source and binary forms, with or
11  * without modification, are permitted provided that the following
12  * conditions are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  *
17  * * Redistributions in binary form must reproduce the above
18  * copyright notice, this list of conditions and the following
19  * disclaimer in the documentation and/or other materials provided
20  * with the distribution.
21  *
22  * * Neither the name of copyright holder the names of its
23  * contributors may be used to endorse or promote products derived
24  * from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
27  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
28  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
31  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
34  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
35  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  *
40  */
41 
42 #ifndef AA_REFCOUNT_H
43 #define AA_REFCOUNT_H
44 
45 /***********************************/
46 /* Synchronized Reference Counting */
47 /***********************************/
48 
49 #ifndef __cplusplus
50 
51 #if ( (__STDC_VERSION__ >= 201112L) && ! defined(__STD_NO_ATOMICS__) ) || defined (_STDATOMIC_H)
52 
53 /* C11 atomics version */
54 #define AA_ATOMIC _Atomic
55 #define aa_mem_ref_inc aa_mem_ref_inc_atomic
56 #define aa_mem_ref_dec aa_mem_ref_dec_atomic
57 
63 AA_API unsigned
64 aa_mem_ref_inc_atomic( AA_ATOMIC unsigned *count );
65 
71 AA_API unsigned
72 aa_mem_ref_dec_atomic( AA_ATOMIC unsigned *count );
73 
74 #else
75 
76 #warning "No C11 atomics. Include stdatomic.h or refcounts will be slow."
77 
78 /* Mutex fallback version */
79 #define AA_ATOMIC
80 #define aa_mem_ref_inc aa_mem_ref_inc_mutex
81 #define aa_mem_ref_dec aa_mem_ref_dec_mutex
82 
83 #endif /* __STDC_VERSION__ >= 201112L */
84 
85 #else
86 
87 /* TODO: C++ Atomic refcounts */
88 
89 #endif
90 
91 
97 AA_API unsigned
98 aa_mem_ref_inc_mutex( unsigned *count );
99 
105 AA_API unsigned
106 aa_mem_ref_dec_mutex( unsigned *count );
107 
108 #endif /* AA_REFCOUNT_H */
#define AA_API
calling and name mangling convention for functions
Definition: amino.h:95