Greg Clayton | e49f79d | 2010-06-12 17:45:57 +0000 | [diff] [blame] | 1 | //===---------------------SharingPtr.cpp ------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Eli Friedman | 17b7136 | 2010-06-12 18:29:53 +0000 | [diff] [blame] | 10 | #include "lldb/Utility/SharingPtr.h" |
Greg Clayton | e49f79d | 2010-06-12 17:45:57 +0000 | [diff] [blame] | 11 | |
Greg Clayton | 6a5aa8a | 2010-09-24 23:07:41 +0000 | [diff] [blame] | 12 | namespace lldb_private { |
Greg Clayton | e49f79d | 2010-06-12 17:45:57 +0000 | [diff] [blame] | 13 | |
| 14 | namespace imp |
| 15 | { |
| 16 | |
| 17 | template <class T> |
| 18 | inline T |
| 19 | increment(T& t) |
| 20 | { |
| 21 | return __sync_add_and_fetch(&t, 1); |
| 22 | } |
| 23 | |
| 24 | template <class T> |
| 25 | inline T |
| 26 | decrement(T& t) |
| 27 | { |
| 28 | return __sync_add_and_fetch(&t, -1); |
| 29 | } |
| 30 | |
| 31 | shared_count::~shared_count() |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | void |
| 36 | shared_count::add_shared() |
| 37 | { |
| 38 | increment(shared_owners_); |
| 39 | } |
| 40 | |
| 41 | void |
| 42 | shared_count::release_shared() |
| 43 | { |
| 44 | if (decrement(shared_owners_) == -1) |
| 45 | { |
| 46 | on_zero_shared(); |
| 47 | delete this; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | } // imp |
| 52 | |
| 53 | } // namespace lldb |