blob: 3ee01285a3b29dfe6c51613a00f69cc4e5a5986b [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
Greg Clayton6e0101c2011-09-17 06:21:20 +000017 template <class T>
18 inline T
19 increment(T& t)
Greg Claytone49f79d2010-06-12 17:45:57 +000020 {
Greg Clayton6e0101c2011-09-17 06:21:20 +000021 return __sync_add_and_fetch(&t, 1);
Greg Claytone49f79d2010-06-12 17:45:57 +000022 }
Greg Clayton6e0101c2011-09-17 06:21:20 +000023
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 }
Greg Claytone49f79d2010-06-12 17:45:57 +000050
51} // imp
52
Greg Clayton6e0101c2011-09-17 06:21:20 +000053
Greg Claytone49f79d2010-06-12 17:45:57 +000054} // namespace lldb
Greg Clayton6e0101c2011-09-17 06:21:20 +000055