summaryrefslogtreecommitdiffstats
path: root/lldb/source/Utility/SharingPtr.cpp
blob: 88c103ac9e2600d9955c55173411748633e22b89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//===---------------------SharingPtr.cpp ------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "lldb/Utility/SharingPtr.h"

namespace lldb_private {

namespace imp
{

template <class T>
inline T
increment(T& t)
{
    return __sync_add_and_fetch(&t, 1);
}

template <class T>
inline T
decrement(T& t)
{
    return __sync_add_and_fetch(&t, -1);
}

shared_count::~shared_count()
{
}

void
shared_count::add_shared()
{
    increment(shared_owners_);
}

void
shared_count::release_shared()
{
    if (decrement(shared_owners_) == -1)
    {
        on_zero_shared();
        delete this;
    }
}

} // imp

} // namespace lldb
OpenPOWER on IntegriCloud