1 //===-- RefCounter.h --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_RefCounter_h_
11 #define liblldb_RefCounter_h_
13 #include "lldb/lldb-public.h"
15 namespace lldb_utility {
17 //----------------------------------------------------------------------
18 // A simple reference counter object. You need an uint32_t* to use it
19 // Once that is in place, everyone who needs to ref-count, can say
20 // RefCounter ref(ptr);
21 // (of course, the pointer is a shared resource, and must be accessible to
22 // everyone who needs it). Synchronization is handled by RefCounter itself
23 // The counter is decreased each time a RefCounter to it goes out of scope
24 //----------------------------------------------------------------------
28 typedef uint32_t value_type;
30 RefCounter(value_type* ctr);
35 value_type* m_counter;
36 DISALLOW_COPY_AND_ASSIGN (RefCounter);
42 return __sync_fetch_and_add(t, 1);
49 return __sync_fetch_and_add(t, -1);
54 } // namespace lldb_utility
56 #endif // #ifndef liblldb_RefCounter_h_