~ubuntu-branches/ubuntu/raring/clucene-core/raring-proposed

« back to all changes in this revision

Viewing changes to src/ext/boost/smart_ptr/detail/sp_counted_base_pt.hpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-08-11 09:33:38 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120811093338-fgrx41ftqew3qt6a
Tags: 2.3.3.4-1
* New upstream release (Closes: #661703).
* Convert package to multiarch.
* Drop obsolete patches:
  - 01_add_missing_include_bug505667.diff
  - 02_posixness_fix_bug530308.diff
* Add patches:
  - Fixing_ZLIB_configuration_in_shared_CMakeLists.patch
  - Fix-pkgconfig-file-by-adding-clucene-shared-library.patch
  - Install-contribs-lib.patch
  - multiarch.patch
* Update debian/compat: bump to 8.
* Update debian/control:
  - update build dependencies (add cmake, libboost-dev and libz-dev).
  - bump Standards-Version to 3.9.3.
  - rename packages due to ABI bump: libclucene0ldbl -> libclucene-core1.
  - add libclucene-contribs1 package.
* Update debian/rules:
  - rewrite to use CMake.
  - add multiarch support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_PT_HPP_INCLUDED
 
2
#define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_PT_HPP_INCLUDED
 
3
 
 
4
// MS compatible compilers support #pragma once
 
5
 
 
6
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
 
7
# pragma once
 
8
#endif
 
9
 
 
10
//
 
11
//  detail/sp_counted_base_pt.hpp
 
12
//
 
13
//  Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
 
14
//  Copyright 2004-2005 Peter Dimov
 
15
//
 
16
// Distributed under the Boost Software License, Version 1.0. (See
 
17
// accompanying file LICENSE_1_0.txt or copy at
 
18
// http://www.boost.org/LICENSE_1_0.txt)
 
19
//
 
20
 
 
21
#include <boost/detail/sp_typeinfo.hpp>
 
22
#include <pthread.h>
 
23
 
 
24
namespace boost
 
25
{
 
26
 
 
27
namespace detail
 
28
{
 
29
 
 
30
class sp_counted_base
 
31
{
 
32
private:
 
33
 
 
34
    sp_counted_base( sp_counted_base const & );
 
35
    sp_counted_base & operator= ( sp_counted_base const & );
 
36
 
 
37
    long use_count_;        // #shared
 
38
    long weak_count_;       // #weak + (#shared != 0)
 
39
 
 
40
    mutable pthread_mutex_t m_;
 
41
 
 
42
public:
 
43
 
 
44
    sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
 
45
    {
 
46
// HPUX 10.20 / DCE has a nonstandard pthread_mutex_init
 
47
 
 
48
#if defined(__hpux) && defined(_DECTHREADS_)
 
49
        pthread_mutex_init( &m_, pthread_mutexattr_default );
 
50
#else
 
51
        pthread_mutex_init( &m_, 0 );
 
52
#endif
 
53
    }
 
54
 
 
55
    virtual ~sp_counted_base() // nothrow
 
56
    {
 
57
        pthread_mutex_destroy( &m_ );
 
58
    }
 
59
 
 
60
    // dispose() is called when use_count_ drops to zero, to release
 
61
    // the resources managed by *this.
 
62
 
 
63
    virtual void dispose() = 0; // nothrow
 
64
 
 
65
    // destroy() is called when weak_count_ drops to zero.
 
66
 
 
67
    virtual void destroy() // nothrow
 
68
    {
 
69
        delete this;
 
70
    }
 
71
 
 
72
    virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
 
73
 
 
74
    void add_ref_copy()
 
75
    {
 
76
        pthread_mutex_lock( &m_ );
 
77
        ++use_count_;
 
78
        pthread_mutex_unlock( &m_ );
 
79
    }
 
80
 
 
81
    bool add_ref_lock() // true on success
 
82
    {
 
83
        pthread_mutex_lock( &m_ );
 
84
        bool r = use_count_ == 0? false: ( ++use_count_, true );
 
85
        pthread_mutex_unlock( &m_ );
 
86
        return r;
 
87
    }
 
88
 
 
89
    void release() // nothrow
 
90
    {
 
91
        pthread_mutex_lock( &m_ );
 
92
        long new_use_count = --use_count_;
 
93
        pthread_mutex_unlock( &m_ );
 
94
 
 
95
        if( new_use_count == 0 )
 
96
        {
 
97
            dispose();
 
98
            weak_release();
 
99
        }
 
100
    }
 
101
 
 
102
    void weak_add_ref() // nothrow
 
103
    {
 
104
        pthread_mutex_lock( &m_ );
 
105
        ++weak_count_;
 
106
        pthread_mutex_unlock( &m_ );
 
107
    }
 
108
 
 
109
    void weak_release() // nothrow
 
110
    {
 
111
        pthread_mutex_lock( &m_ );
 
112
        long new_weak_count = --weak_count_;
 
113
        pthread_mutex_unlock( &m_ );
 
114
 
 
115
        if( new_weak_count == 0 )
 
116
        {
 
117
            destroy();
 
118
        }
 
119
    }
 
120
 
 
121
    long use_count() const // nothrow
 
122
    {
 
123
        pthread_mutex_lock( &m_ );
 
124
        long r = use_count_;
 
125
        pthread_mutex_unlock( &m_ );
 
126
 
 
127
        return r;
 
128
    }
 
129
};
 
130
 
 
131
} // namespace detail
 
132
 
 
133
} // namespace boost
 
134
 
 
135
#endif  // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_PT_HPP_INCLUDED