|
Boost-Commit : |
From: anthony_at_[hidden]
Date: 2007-10-19 10:52:53
Author: anthonyw
Date: 2007-10-19 10:52:52 EDT (Fri, 19 Oct 2007)
New Revision: 40187
URL: http://svn.boost.org/trac/boost/changeset/40187
Log:
small changes to reduce warnings; extracted pthread_mutex_scoped_lock to its own file
Added:
trunk/boost/thread/pthread/pthread_mutex_scoped_lock.hpp (contents, props changed)
Text files modified:
trunk/boost/thread/pthread/mutex.hpp | 28 +++++-----------------------
trunk/boost/thread/pthread/recursive_mutex.hpp | 28 +++++-----------------------
trunk/boost/thread/thread_time.hpp | 4 ++--
trunk/boost/thread/win32/basic_timed_mutex.hpp | 2 +-
4 files changed, 13 insertions(+), 49 deletions(-)
Modified: trunk/boost/thread/pthread/mutex.hpp
==============================================================================
--- trunk/boost/thread/pthread/mutex.hpp (original)
+++ trunk/boost/thread/pthread/mutex.hpp 2007-10-19 10:52:52 EDT (Fri, 19 Oct 2007)
@@ -14,6 +14,7 @@
#include <unistd.h>
#include <errno.h>
#include "timespec.hpp"
+#include "pthread_mutex_scoped_lock.hpp"
#ifdef _POSIX_TIMEOUTS
#if _POSIX_TIMEOUTS >= 0
@@ -75,25 +76,6 @@
#ifndef BOOST_PTHREAD_HAS_TIMEDLOCK
pthread_cond_t cond;
bool is_locked;
-
- struct pthread_mutex_scoped_lock
- {
- pthread_mutex_t* m;
- explicit pthread_mutex_scoped_lock(pthread_mutex_t* m_):
- m(m_)
- {
- int const res=pthread_mutex_lock(m);
- BOOST_ASSERT(!res);
- }
- ~pthread_mutex_scoped_lock()
- {
- int const res=pthread_mutex_unlock(m);
- BOOST_ASSERT(!res);
- }
-
- };
-
-
#endif
public:
timed_mutex()
@@ -159,7 +141,7 @@
#else
void lock()
{
- pthread_mutex_scoped_lock const _(&m);
+ boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
while(is_locked)
{
int const cond_res=pthread_cond_wait(&cond,&m);
@@ -170,7 +152,7 @@
void unlock()
{
- pthread_mutex_scoped_lock const _(&m);
+ boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
is_locked=false;
int const res=pthread_cond_signal(&cond);
BOOST_ASSERT(!res);
@@ -178,7 +160,7 @@
bool try_lock()
{
- pthread_mutex_scoped_lock const _(&m);
+ boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
if(is_locked)
{
return false;
@@ -190,7 +172,7 @@
bool timed_lock(system_time const & abs_time)
{
struct timespec const timeout=detail::get_timespec(abs_time);
- pthread_mutex_scoped_lock const _(&m);
+ boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
while(is_locked)
{
int const cond_res=pthread_cond_timedwait(&cond,&m,&timeout);
Added: trunk/boost/thread/pthread/pthread_mutex_scoped_lock.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/thread/pthread/pthread_mutex_scoped_lock.hpp 2007-10-19 10:52:52 EDT (Fri, 19 Oct 2007)
@@ -0,0 +1,30 @@
+#ifndef BOOST_PTHREAD_MUTEX_SCOPED_LOCK_HPP
+#define BOOST_PTHREAD_MUTEX_SCOPED_LOCK_HPP
+#include <pthread.h>
+#include <boost/assert.hpp>
+
+namespace boost
+{
+ namespace pthread
+ {
+ class pthread_mutex_scoped_lock
+ {
+ pthread_mutex_t* m;
+ public:
+ explicit pthread_mutex_scoped_lock(pthread_mutex_t* m_):
+ m(m_)
+ {
+ int const res=pthread_mutex_lock(m);
+ BOOST_ASSERT(!res);
+ }
+ ~pthread_mutex_scoped_lock()
+ {
+ int const res=pthread_mutex_unlock(m);
+ BOOST_ASSERT(!res);
+ }
+
+ };
+ }
+}
+
+#endif
Modified: trunk/boost/thread/pthread/recursive_mutex.hpp
==============================================================================
--- trunk/boost/thread/pthread/recursive_mutex.hpp (original)
+++ trunk/boost/thread/pthread/recursive_mutex.hpp 2007-10-19 10:52:52 EDT (Fri, 19 Oct 2007)
@@ -15,6 +15,7 @@
#include <boost/date_time/posix_time/conversion.hpp>
#include <errno.h>
#include "timespec.hpp"
+#include "pthread_mutex_scoped_lock.hpp"
#ifdef _POSIX_TIMEOUTS
#if _POSIX_TIMEOUTS >= 0
@@ -93,25 +94,6 @@
bool is_locked;
pthread_t owner;
unsigned count;
-
- struct pthread_mutex_scoped_lock
- {
- pthread_mutex_t* m;
- explicit pthread_mutex_scoped_lock(pthread_mutex_t* m_):
- m(m_)
- {
- int const res=pthread_mutex_lock(m);
- BOOST_ASSERT(!res);
- }
- ~pthread_mutex_scoped_lock()
- {
- int const res=pthread_mutex_unlock(m);
- BOOST_ASSERT(!res);
- }
-
- };
-
-
#endif
public:
recursive_timed_mutex()
@@ -201,7 +183,7 @@
#else
void lock()
{
- pthread_mutex_scoped_lock const _(&m);
+ boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
if(is_locked && owner==pthread_self())
{
++count;
@@ -220,7 +202,7 @@
void unlock()
{
- pthread_mutex_scoped_lock const _(&m);
+ boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
if(!--count)
{
is_locked=false;
@@ -231,7 +213,7 @@
bool try_lock()
{
- pthread_mutex_scoped_lock const _(&m);
+ boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
if(is_locked && owner!=pthread_self())
{
return false;
@@ -245,7 +227,7 @@
bool timed_lock(system_time const & abs_time)
{
struct timespec const timeout=detail::get_timespec(abs_time);
- pthread_mutex_scoped_lock const _(&m);
+ boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
if(is_locked && owner==pthread_self())
{
++count;
Modified: trunk/boost/thread/thread_time.hpp
==============================================================================
--- trunk/boost/thread/thread_time.hpp (original)
+++ trunk/boost/thread/thread_time.hpp 2007-10-19 10:52:52 EDT (Fri, 19 Oct 2007)
@@ -19,11 +19,11 @@
return system_time(boost::posix_time::pos_infin);
}
- inline unsigned get_milliseconds_until(system_time const& target_time)
+ inline system_time::time_duration_type::tick_type get_milliseconds_until(system_time const& target_time)
{
if(target_time.is_pos_infinity())
{
- return ~0u;
+ return ~(system_time::time_duration_type::tick_type)0;
}
system_time const now=get_system_time();
if(target_time<=now)
Modified: trunk/boost/thread/win32/basic_timed_mutex.hpp
==============================================================================
--- trunk/boost/thread/win32/basic_timed_mutex.hpp (original)
+++ trunk/boost/thread/win32/basic_timed_mutex.hpp 2007-10-19 10:52:52 EDT (Fri, 19 Oct 2007)
@@ -113,7 +113,7 @@
void unlock()
{
long const offset=lock_flag_value+1;
- long old_count=BOOST_INTERLOCKED_EXCHANGE_ADD(&active_count,-offset);
+ long old_count=BOOST_INTERLOCKED_EXCHANGE_ADD(&active_count,(~offset)+1);
if(old_count>offset)
{
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