Skip to content

Commit

Permalink
3 air
Browse files Browse the repository at this point in the history
  • Loading branch information
CCIGAMES committed Mar 2, 2024
1 parent 77c76f7 commit c6e77cb
Show file tree
Hide file tree
Showing 6 changed files with 426 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED
#define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED

//
// boost/detail/atomic_count_gcc.hpp
//
// atomic_count for GNU libstdc++ v3
//
// http://gcc.gnu.org/onlinedocs/porting/Thread-safety.html
//
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2002 Lars Gullik Bjønnes <[email protected]>
// Copyright 2003-2005 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//

#if __GNUC__ * 100 + __GNUC_MINOR__ >= 402
# include <ext/atomicity.h>
#else
# include <bits/atomicity.h>
#endif

namespace boost
{

namespace detail
{

#if defined(__GLIBCXX__) // g++ 3.4+

using __gnu_cxx::__atomic_add;
using __gnu_cxx::__exchange_and_add;

#endif

class atomic_count
{
public:

explicit atomic_count( long v ) : value_( v ) {}

long operator++()
{
return __exchange_and_add( &value_, +1 ) + 1;
}

long operator--()
{
return __exchange_and_add( &value_, -1 ) - 1;
}

operator long() const
{
return __exchange_and_add( &value_, 0 );
}

private:

atomic_count(atomic_count const &);
atomic_count & operator=(atomic_count const &);

mutable _Atomic_word value_;
};

} // namespace detail

} // namespace boost

#endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_X86_HPP_INCLUDED
#define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_X86_HPP_INCLUDED

//
// boost/detail/atomic_count_gcc_x86.hpp
//
// atomic_count for g++ on 486+/AMD64
//
// Copyright 2007 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//

namespace boost
{

namespace detail
{

class atomic_count
{
public:

explicit atomic_count( long v ) : value_( static_cast< int >( v ) ) {}

long operator++()
{
return atomic_exchange_and_add( &value_, +1 ) + 1;
}

long operator--()
{
return atomic_exchange_and_add( &value_, -1 ) - 1;
}

operator long() const
{
return atomic_exchange_and_add( &value_, 0 );
}

private:

atomic_count(atomic_count const &);
atomic_count & operator=(atomic_count const &);

mutable int value_;

private:

static int atomic_exchange_and_add( int * pw, int dv )
{
// int r = *pw;
// *pw += dv;
// return r;

int r;

__asm__ __volatile__
(
"lock\n\t"
"xadd %1, %0":
"+m"( *pw ), "=r"( r ): // outputs (%0, %1)
"1"( dv ): // inputs (%2 == %1)
"memory", "cc" // clobbers
);

return r;
}
};

} // namespace detail

} // namespace boost

#endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_X86_HPP_INCLUDED
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_NT_HPP_INCLUDED
#define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_NT_HPP_INCLUDED

//
// boost/detail/atomic_count_nt.hpp
//
// Trivial atomic_count for the single-threaded case
//
// http://gcc.gnu.org/onlinedocs/porting/Thread-safety.html
//
// Copyright 2013 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//

namespace boost
{

namespace detail
{

class atomic_count
{
public:

explicit atomic_count( long v ): value_( v )
{
}

long operator++()
{
return ++value_;
}

long operator--()
{
return --value_;
}

operator long() const
{
return value_;
}

private:

atomic_count(atomic_count const &);
atomic_count & operator=(atomic_count const &);

long value_;
};

} // namespace detail

} // namespace boost

#endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_NT_HPP_INCLUDED
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_PTHREADS_HPP_INCLUDED
#define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_PTHREADS_HPP_INCLUDED

//
// boost/detail/atomic_count_pthreads.hpp
//
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//

#include <boost/assert.hpp>
#include <pthread.h>

//
// The generic pthread_mutex-based implementation sometimes leads to
// inefficiencies. Example: a class with two atomic_count members
// can get away with a single mutex.
//
// Users can detect this situation by checking BOOST_AC_USE_PTHREADS.
//

namespace boost
{

namespace detail
{

class atomic_count
{
private:

class scoped_lock
{
public:

scoped_lock(pthread_mutex_t & m): m_(m)
{
BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
}

~scoped_lock()
{
BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
}

private:

pthread_mutex_t & m_;
};

public:

explicit atomic_count(long v): value_(v)
{
BOOST_VERIFY( pthread_mutex_init( &mutex_, 0 ) == 0 );
}

~atomic_count()
{
BOOST_VERIFY( pthread_mutex_destroy( &mutex_ ) == 0 );
}

long operator++()
{
scoped_lock lock(mutex_);
return ++value_;
}

long operator--()
{
scoped_lock lock(mutex_);
return --value_;
}

operator long() const
{
scoped_lock lock(mutex_);
return value_;
}

private:

atomic_count(atomic_count const &);
atomic_count & operator=(atomic_count const &);

mutable pthread_mutex_t mutex_;
long value_;
};

} // namespace detail

} // namespace boost

#endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_PTHREADS_HPP_INCLUDED
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_SOLARIS_HPP_INCLUDED
#define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_SOLARIS_HPP_INCLUDED

//
// boost/detail/atomic_count_solaris.hpp
// based on: boost/detail/atomic_count_win32.hpp
//
// Copyright (c) 2001-2005 Peter Dimov
// Copyright (c) 2006 Michael van der Westhuizen
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//

#include <atomic.h>

namespace boost
{

namespace detail
{

class atomic_count
{
public:

explicit atomic_count( uint32_t v ): value_( v )
{
}

long operator++()
{
return atomic_inc_32_nv( &value_ );
}

long operator--()
{
return atomic_dec_32_nv( &value_ );
}

operator uint32_t() const
{
return static_cast<uint32_t const volatile &>( value_ );
}

private:

atomic_count( atomic_count const & );
atomic_count & operator=( atomic_count const & );

uint32_t value_;
};

} // namespace detail

} // namespace boost

#endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_SOLARIS_HPP_INCLUDED
Loading

0 comments on commit c6e77cb

Please sign in to comment.