CppCMS
|
00001 #ifndef BOOSTER_SMART_PTR_DETAIL_SP_COUNTED_BASE_SPIN_HPP_INCLUDED 00002 #define BOOSTER_SMART_PTR_DETAIL_SP_COUNTED_BASE_SPIN_HPP_INCLUDED 00003 00004 // 00005 // detail/sp_counted_base_spin.hpp - spinlock pool atomic emulation 00006 // 00007 // Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd. 00008 // Copyright 2004-2008 Peter Dimov 00009 // 00010 // Distributed under the Boost Software License, Version 1.0. (See 00011 // accompanying file LICENSE_1_0.txt or copy at 00012 // http://www.boost.org/LICENSE_1_0.txt) 00013 // 00014 00015 #include <booster/config.h> 00016 #include <booster/smart_ptr/sp_typeinfo.h> 00017 00018 #ifndef BOOSTER_WIN32 00019 #include <pthread.h> 00020 #endif 00021 00022 namespace booster 00023 { 00024 00025 namespace detail 00026 { 00027 00028 typedef union sp_counted_base_atomic { 00029 int i; 00030 unsigned int ui; 00031 long int li; 00032 unsigned long int uli; 00033 long long int lli; 00034 unsigned long long int ulli; 00035 char at_least[8]; 00036 } sp_counted_base_atomic_type; 00037 00038 00039 class BOOSTER_API sp_counted_base 00040 { 00041 private: 00042 00043 sp_counted_base( sp_counted_base const & ); 00044 sp_counted_base & operator= ( sp_counted_base const & ); 00045 00046 typedef sp_counted_base_atomic_type atomic_type; 00047 00048 mutable atomic_type use_count_; // #shared 00049 mutable atomic_type weak_count_; // #weak + (#shared != 0) 00050 #ifndef BOOSTER_WIN32 00051 mutable pthread_mutex_t lock_; 00052 #endif 00053 00054 public: 00055 00056 sp_counted_base(); 00057 virtual ~sp_counted_base(); // nothrow 00058 00059 // dispose() is called when use_count_ drops to zero, to release 00060 // the resources managed by *this. 00061 00062 virtual void dispose() = 0; // nothrow 00063 00064 // destroy() is called when weak_count_ drops to zero. 00065 00066 virtual void destroy(); // nothrow 00067 virtual void * get_deleter( sp_typeinfo const & ti ) = 0; 00068 void add_ref_copy(); 00069 bool add_ref_lock(); // true on success 00070 void release(); // nothrow 00071 void weak_add_ref(); // nothrow 00072 void weak_release(); // nothrow 00073 long use_count() const; // nothrow 00074 }; 00075 00076 } // namespace detail 00077 00078 } // namespace boost 00079 00080 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_SPIN_HPP_INCLUDED 00081 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4