Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52488 - in sandbox/task: boost/task boost/task/detail libs/task/src
From: oliver.kowalke_at_[hidden]
Date: 2009-04-19 08:17:26


Author: olli
Date: 2009-04-19 08:17:24 EDT (Sun, 19 Apr 2009)
New Revision: 52488
URL: http://svn.boost.org/trac/boost/changeset/52488

Log:
* atomics.hpp depended from interprocess::atomics.hpp
* atomic operations with C0x interface
* semaphore moved to boost::task namespace

Added:
   sandbox/task/boost/task/semaphore.hpp (contents, props changed)
Removed:
   sandbox/task/boost/task/detail/semaphore.hpp
   sandbox/task/boost/task/detail/semaphore_posix.hpp
   sandbox/task/boost/task/detail/semaphore_windows.hpp
Text files modified:
   sandbox/task/boost/task/detail/atomic.hpp | 130 +++------------------------------------
   sandbox/task/boost/task/detail/worker.hpp | 2
   sandbox/task/boost/task/pool.hpp | 2
   sandbox/task/libs/task/src/guard.cpp | 4
   sandbox/task/libs/task/src/semaphore_posix.cpp | 20 ++---
   sandbox/task/libs/task/src/semaphore_windows.cpp | 6 -
   6 files changed, 27 insertions(+), 137 deletions(-)

Modified: sandbox/task/boost/task/detail/atomic.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic.hpp (original)
+++ sandbox/task/boost/task/detail/atomic.hpp 2009-04-19 08:17:24 EDT (Sun, 19 Apr 2009)
@@ -7,136 +7,30 @@
 #ifndef BOOST_TASK_DETAIL_ATOMIC_H
 #define BOOST_TASK_DETAIL_ATOMIC_H
 
-#include <boost/task/detail/config.hpp>
+#include <boost/assert.hpp>
+#include <boost/interprocess/detail/atomic.hpp>
 
 namespace boost { namespace task
 {
 namespace detail
 {
-# if defined( BOOST_WINDOWS_OS)
-
-#include <Windows.h>
-
-template< typename T >
-bool atomic_compare_exchange_ptr( volatile T * object, T expected, T desired)
-{ return InterlockedCompareExchangePointer( ( PVOID *) object, ( PVOID) expected, ( PVOID) desired); }
-
-inline
-void atomic_write_32( volatile unsigned int * object, unsigned int desired)
-{ InterlockedExchange( reinterpret_cast< volatile LONG * >( object), desired); }
-
-template< typename T >
-void atomic_write_ptr( volatile T * object, T desired)
-{ InterlockedExchangePointer( reinterpret_cast< volatile LONG * >( object), desired); }
-
-inline
-unsigned int atomic_inc_32( volatile unsigned int * object)
-{ return InterlockedIncrement( reinterpret_cast< volatile LONG * >( object) ); }
-
-inline
-unsigned int atomic_dec_32( volatile unsigned int * object)
-{ return InterlockedDecrement( reinterpret_cast< volatile LONG * >( object) ); }
-
-# elif defined(BOOST_AIX_OS)
-
-#include <sys/atomic_ops.h>
-
-template< typename T >
-bool atomic_compare_exchange_ptr( volatile T * object, T expected, T desired)
-{ return ::compare_and_swap( object, expected, & desired); }
-
-inline
-void atomic_write_32( volatile unsigned int * object, unsigned int desired)
-{ * object = desired; }
-
-template< typename T >
-void atomic_write_ptr( volatile T * object, T * desired)
-{ * object = desired; }
-
-inline
-unsigned int atomic_inc_32( volatile unsigned int * object)
-{ return ::fetch_and_add( object, 1); }
-
-inline
-unsigned int atomic_dec_32( volatile unsigned int * object)
-{ return ::fetch_and_add( object, -1); }
-
-# elif defined(BOOST_HPUX_OS)
-
-#include <atomic.h>
-
-template< typename T >
-bool atomic_compare_exchange_ptr( volatile T * object, T expected, T desired)
-{ return ::atomic_cas( object, expected, & desired) == object; }
-
 inline
-void atomic_write_32( volatile unsigned int * object, unsigned int desired)
-{ * object = desired; }
-
-template< typename T >
-void atomic_write_ptr( volatile T * object, T * desired)
-{ * object = desired; }
-
-inline
-unsigned int atomic_inc_32( volatile unsigned int * object)
-{ return ::atomic_inc( object); }
-
-inline
-unsigned int atomic_dec_32( volatile unsigned int * object)
-{ return ::atomic_dec( object); }
-
-# elif defined(BOOST_SOLARIS_OS)
-
-#include <atomic.h>
-
-template< typename T >
-bool atomic_compare_exchange_ptr( volatile T * object, T expected, T desired)
-{ return ::atomic_cas_ptr( object, expected, & desired) == object; }
+void atomic_exchange( volatile unsigned int * object, unsigned int desired)
+{ interprocess::detail::atomic_write32( object, desired); }
 
 inline
-void atomic_write_32( volatile unsigned int * object, unsigned int desired)
+unsigned int atomic_fetch_add( volatile unsigned int * object, unsigned int operand)
 {
- unsigned int desired_( desired);
- ::atomic_swap_32( object, desired_);
+ BOOST_ASSERT( operand == 1);
+ return interprocess::detail::atomic_dec32( object);
 }
 
-template< typename T >
-void atomic_write_ptr( volatile T * object, T * desired)
-{ * object = desired; }
-
 inline
-unsigned int atomic_inc_32( volatile unsigned int * object)
-{ return ::atomic_inc_32( object); }
-
-inline
-unsigned int atomic_dec_32( volatile unsigned int * object)
-{ return ::atomic_dec_32( object); }
-
-#elif defined(__GNUC__) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
-
-template< typename T >
-bool atomic_compare_exchange_ptr( volatile T * object, T expected, T desired)
-{ return __sync_bool_compare_and_swap( object, expected, desired); }
-
-inline
-void atomic_write_32( volatile unsigned int * object, unsigned int desired)
-{ * object = desired; }
-
-template< typename T >
-void atomic_write_ptr( volatile T * object, T desired)
-{ * object = desired; }
-
-inline
-unsigned int atomic_inc_32( volatile unsigned int * object)
-{ return __sync_fetch_and_add( object, 1); }
-
-inline
-unsigned int atomic_dec_32( volatile unsigned int * object)
-{ return __sync_fetch_and_sub( object, 1); }
-
-# else
-# error "No atomic operations available for this platform!"
-# endif
+unsigned int atomic_fetch_sub( volatile unsigned int * object, unsigned int operand)
+{
+ BOOST_ASSERT( operand == 1);
+ return interprocess::detail::atomic_inc32( object);
+}
 } } }
 
 #endif // BOOST_TASK_DETAIL_ATOMIC_H

Deleted: sandbox/task/boost/task/detail/semaphore.hpp
==============================================================================
--- sandbox/task/boost/task/detail/semaphore.hpp 2009-04-19 08:17:24 EDT (Sun, 19 Apr 2009)
+++ (empty file)
@@ -1,20 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// 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)
-
-#ifndef BOOST_TASK_DETAIL_SEMAPHORE_H
-#define BOOST_TASK_DETAIL_SEMAPHORE_H
-
-#include <boost/task/detail/config.hpp>
-
-# if defined(BOOST_WINDOWS_API)
-# include <boost/task/detail/semaphore_windows.hpp>
-# elif defined(BOOST_POSIX_API)
-# include <boost/task/detail/semaphore_posix.hpp>
-# else
-# error "No semaphore available for this platform!"
-# endif
-
-#endif // BOOST_TASK_DETAIL_SEMAPHORE_H

Deleted: sandbox/task/boost/task/detail/semaphore_posix.hpp
==============================================================================
--- sandbox/task/boost/task/detail/semaphore_posix.hpp 2009-04-19 08:17:24 EDT (Sun, 19 Apr 2009)
+++ (empty file)
@@ -1,46 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// 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)
-
-#ifndef BOOST_TASK_DETAIL_SEMAPHORE_POSIX_H
-#define BOOST_TASK_DETAIL_SEMAPHORE_POSIX_H
-
-extern "C"
-{
-#include <semaphore.h>
-}
-
-#include <boost/utility.hpp>
-
-#include <boost/task/detail/config.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost { namespace task
-{
-namespace detail
-{
-class BOOST_TASK_DECL semaphore : private boost::noncopyable
-{
-private:
- sem_t sem_;
-
-public:
- semaphore( int);
-
- ~semaphore();
-
- void post();
-
- bool try_wait();
- void wait();
-
- int value();
-};
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASK_DETAIL_SEMAPHORE_POSIX_H

Deleted: sandbox/task/boost/task/detail/semaphore_windows.hpp
==============================================================================
--- sandbox/task/boost/task/detail/semaphore_windows.hpp 2009-04-19 08:17:24 EDT (Sun, 19 Apr 2009)
+++ (empty file)
@@ -1,46 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// 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)
-
-#ifndef BOOST_TASK_DETAIL_SEMAPHORE_WINDOWS_H
-#define BOOST_TASK_DETAIL_SEMAPHORE_WINDOWS_H
-
-extern "C"
-{
-#include <Windows.h>
-}
-
-#include <boost/utility.hpp>
-
-#include <boost/task/detail/config.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost { namespace task
-{
-namespace detail
-{
-class BOOST_TASK_DECL semaphore : private boost::noncopyable
-{
-private:
- HANDLE handle_;
-
-public:
- semaphore( int);
-
- ~semaphore();
-
- void post();
-
- bool try_wait();
- void wait();
-
- int value();
-};
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASK_DETAIL_SEMAPHORE_WINDOWS_H

Modified: sandbox/task/boost/task/detail/worker.hpp
==============================================================================
--- sandbox/task/boost/task/detail/worker.hpp (original)
+++ sandbox/task/boost/task/detail/worker.hpp 2009-04-19 08:17:24 EDT (Sun, 19 Apr 2009)
@@ -21,10 +21,10 @@
 #include <boost/task/detail/config.hpp>
 #include <boost/task/detail/guard.hpp>
 #include <boost/task/detail/interrupter.hpp>
-#include <boost/task/detail/semaphore.hpp>
 #include <boost/task/detail/wsq.hpp>
 #include <boost/task/poolsize.hpp>
 #include <boost/task/scanns.hpp>
+#include <boost/task/semaphore.hpp>
 
 #include <boost/config/abi_prefix.hpp>
 

Modified: sandbox/task/boost/task/pool.hpp
==============================================================================
--- sandbox/task/boost/task/pool.hpp (original)
+++ sandbox/task/boost/task/pool.hpp 2009-04-19 08:17:24 EDT (Sun, 19 Apr 2009)
@@ -116,7 +116,7 @@
         { return state_ > 0; }
 
         unsigned int close_()
- { return detail::atomic_inc_32( & state_); }
+ { return detail::atomic_fetch_add( & state_, 1); }
 
 public:
         explicit pool(

Added: sandbox/task/boost/task/semaphore.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/semaphore.hpp 2009-04-19 08:17:24 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,53 @@
+
+// Copyright Oliver Kowalke 2009.
+// 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)
+
+#ifndef BOOST_TASK_SEMAPHORE_H
+#define BOOST_TASK_SEMAPHORE_H
+
+#include <boost/task/detail/config.hpp>
+
+extern "C"
+{
+# if defined(BOOST_WINDOWS_API)
+#include <Windows.h>
+# elif defined(BOOST_POSIX_API)
+#include <semaphore.h>
+# endif
+}
+
+#include <boost/utility.hpp>
+
+#include <boost/task/detail/config.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost { namespace task
+{
+class BOOST_TASK_DECL semaphore : private boost::noncopyable
+{
+private:
+# if defined(BOOST_WINDOWS_API)
+ HANDLE handle_;
+# elif defined(BOOST_POSIX_API)
+ sem_t handle_;;
+# endif
+public:
+ semaphore( int);
+
+ ~semaphore();
+
+ void post();
+
+ bool try_wait();
+ void wait();
+
+ int value();
+};
+}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_TASK_SEMAPHORE_H

Modified: sandbox/task/libs/task/src/guard.cpp
==============================================================================
--- sandbox/task/libs/task/src/guard.cpp (original)
+++ sandbox/task/libs/task/src/guard.cpp 2009-04-19 08:17:24 EDT (Sun, 19 Apr 2009)
@@ -18,12 +18,12 @@
 : active_worker_( active_worker)
 {
         BOOST_ASSERT( active_worker_ >= 0);
- atomic_inc_32( & active_worker_);
+ atomic_fetch_add( & active_worker_, 1);
 }
 
 guard::~guard()
 {
- atomic_dec_32( & active_worker_);
+ atomic_fetch_sub( & active_worker_, 1);
         BOOST_ASSERT( active_worker_ >= 0);
 }
 } } }

Modified: sandbox/task/libs/task/src/semaphore_posix.cpp
==============================================================================
--- sandbox/task/libs/task/src/semaphore_posix.cpp (original)
+++ sandbox/task/libs/task/src/semaphore_posix.cpp 2009-04-19 08:17:24 EDT (Sun, 19 Apr 2009)
@@ -4,7 +4,7 @@
 // (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
-#include "boost/task/detail/semaphore_posix.hpp"
+#include "boost/task/semaphore.hpp"
 
 #include <cerrno>
 
@@ -13,36 +13,34 @@
 
 namespace boost { namespace task
 {
-namespace detail
-{
 semaphore::semaphore( int value)
-: sem_()
+: handle_()
 {
- if ( ::sem_init( & sem_, 0, value) == -1)
+ if ( ::sem_init( & handle_, 0, value) == -1)
                 throw system::system_error( errno, system::system_category);
 }
 
 semaphore::~semaphore()
-{ ::sem_destroy( & sem_); }
+{ ::sem_destroy( & handle_); }
 
 void
 semaphore::post()
 {
- if ( ::sem_post( & sem_) == -1)
+ if ( ::sem_post( & handle_) == -1)
                 throw system::system_error( errno, system::system_category);
 }
 
 void
 semaphore::wait()
 {
- if ( ::sem_wait( & sem_) == -1)
+ if ( ::sem_wait( & handle_) == -1)
                 throw system::system_error( errno, system::system_category);
 }
 
 bool
 semaphore::try_wait()
 {
- if ( ::sem_trywait( & sem_) == -1)
+ if ( ::sem_trywait( & handle_) == -1)
         {
                 if ( errno == EAGAIN)
                         return false;
@@ -56,8 +54,8 @@
 semaphore::value()
 {
         int value( 0);
- if ( ::sem_getvalue( & sem_, & value) == -1)
+ if ( ::sem_getvalue( & handle_, & value) == -1)
                 throw system::system_error( errno, system::system_category);
         return value;
 }
-}}}
+}}

Modified: sandbox/task/libs/task/src/semaphore_windows.cpp
==============================================================================
--- sandbox/task/libs/task/src/semaphore_windows.cpp (original)
+++ sandbox/task/libs/task/src/semaphore_windows.cpp 2009-04-19 08:17:24 EDT (Sun, 19 Apr 2009)
@@ -4,7 +4,7 @@
 // (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
-#include "boost/task/detail/semaphore_windows.hpp"
+#include "boost/task/semaphore.hpp"
 
 #include <cerrno>
 #include <limits>
@@ -14,8 +14,6 @@
 
 namespace boost { namespace task
 {
-namespace detail
-{
 semaphore::semaphore( int value)
 : handle_()
 {
@@ -67,4 +65,4 @@
         }
         return value;
 }
-}}}
+}}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk