blob: 88c103ac9e2600d9955c55173411748633e22b89 [file] [log] [blame]
Greg Claytone49f79d2010-06-12 17:45:57 +00001//===---------------------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 Friedman17b71362010-06-12 18:29:53 +000010#include "lldb/Utility/SharingPtr.h"
Greg Claytone49f79d2010-06-12 17:45:57 +000011
Greg Clayton6a5aa8a2010-09-24 23:07:41 +000012namespace lldb_private {
Greg Claytone49f79d2010-06-12 17:45:57 +000013
14namespace imp
15{
16
17template <class T>
18inline T
19increment(T& t)
20{
21 return __sync_add_and_fetch(&t, 1);
22}
23
24template <class T>
25inline T
26decrement(T& t)
27{
28 return __sync_add_and_fetch(&t, -1);
29}
30
31shared_count::~shared_count()
32{
33}
34
35void
36shared_count::add_shared()
37{
38 increment(shared_owners_);
39}
40
41void
42shared_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