blob: 22387627154194f6445ba7d6628828e9fc107ab1 (
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// **********************************************************************
//
// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
#include <IceUtil/Shared.h>
using namespace IceUtil;
IceUtil::SimpleShared::SimpleShared() :
_ref(0),
_noDelete(false)
{
}
IceUtil::SimpleShared::SimpleShared(const SimpleShared&) :
_ref(0),
_noDelete(false)
{
}
IceUtil::Shared::Shared() :
#ifndef ICE_HAS_ATOMIC_FUNCTIONS
_ref(0),
#endif
_noDelete(false)
{
#ifdef ICE_HAS_ATOMIC_FUNCTIONS
ice_atomic_set(&_ref, 0);
#endif
}
IceUtil::Shared::Shared(const Shared&) :
#ifndef ICE_HAS_ATOMIC_FUNCTIONS
_ref(0),
#endif
_noDelete(false)
{
#ifdef ICE_HAS_ATOMIC_FUNCTIONS
ice_atomic_set(&_ref, 0);
#endif
}
int
IceUtil::Shared::__getRef() const
{
#if defined(_WIN32)
return InterlockedExchangeAdd(const_cast<LONG*>(&_ref), 0);
#elif defined(ICE_HAS_ATOMIC_FUNCTIONS)
return ice_atomic_exchange_add(0, const_cast<ice_atomic_t*>(&_ref));
#else
_mutex.lock();
int ref = _ref;
_mutex.unlock();
return ref;
#endif
}
void
IceUtil::Shared::__setNoDelete(bool b)
{
_noDelete = b;
}
|