Renamed Unlocker to remove compiler warning. Changed function calls for sleeping.
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@1044 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
65949024b3
commit
c74e851a38
1 changed files with 22 additions and 24 deletions
|
@ -1,12 +1,12 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// Part of LevelMutex test program for The Loki Library
|
// Part of LevelMutex test program for The Loki Library
|
||||||
// Copyright (c) 2008 Richard Sposato
|
// Copyright (c) 2008, 2009 Richard Sposato
|
||||||
// The copyright on this file is protected under the terms of the MIT license.
|
// The copyright on this file is protected under the terms of the MIT license.
|
||||||
//
|
//
|
||||||
// Permission to use, copy, modify, distribute and sell this software for any
|
// Permission to use, copy, modify, distribute and sell this software for any
|
||||||
// purpose is hereby granted without fee, provided that the above copyright
|
// purpose is hereby granted without fee, provided that the above copyright
|
||||||
// notice appear in all copies and that both that copyright notice and this
|
// notice appear in all copies and that both that copyright notice and this
|
||||||
// permission notice appear in supporting documentation.
|
// permission notice appear in supporting documentation.
|
||||||
//
|
//
|
||||||
// The author makes no representations about the suitability of this software
|
// The author makes no representations about the suitability of this software
|
||||||
|
@ -22,6 +22,9 @@
|
||||||
#include "Thing.hpp"
|
#include "Thing.hpp"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#if !defined( _MSC_VER )
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
@ -68,11 +71,9 @@ ExceptionTossingMutex::ExceptionTossingMutex( unsigned int level ) :
|
||||||
{
|
{
|
||||||
assert( NULL != this );
|
assert( NULL != this );
|
||||||
#if defined( _MSC_VER )
|
#if defined( _MSC_VER )
|
||||||
SetSleepTime( 5 );
|
|
||||||
SetWakable( false );
|
SetWakable( false );
|
||||||
#else
|
|
||||||
SetSleepTime( 1 );
|
|
||||||
#endif
|
#endif
|
||||||
|
SetSleepTime( 5 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -262,10 +263,10 @@ void GoToSleep( unsigned int milliSeconds )
|
||||||
#if defined( _MSC_VER )
|
#if defined( _MSC_VER )
|
||||||
::SleepEx( milliSeconds, true );
|
::SleepEx( milliSeconds, true );
|
||||||
#elif ( __GNUC__ )
|
#elif ( __GNUC__ )
|
||||||
unsigned int seconds = milliSeconds / 1000;
|
unsigned int microseconds = milliSeconds * 1000;
|
||||||
if ( 0 == seconds )
|
if ( 0 == microseconds )
|
||||||
seconds = 1;
|
microseconds = 1;
|
||||||
::_sleep( seconds );
|
::usleep( microseconds );
|
||||||
#else
|
#else
|
||||||
#error "Find out if your compiler supports a sleep command and add it here."
|
#error "Find out if your compiler supports a sleep command and add it here."
|
||||||
#endif
|
#endif
|
||||||
|
@ -346,11 +347,9 @@ Thing::Thing( unsigned int value ) :
|
||||||
{
|
{
|
||||||
assert( NULL != this );
|
assert( NULL != this );
|
||||||
#if defined( _MSC_VER )
|
#if defined( _MSC_VER )
|
||||||
m_mutex.GetMutexPolicy().SetSleepTime( 5 );
|
|
||||||
m_mutex.GetMutexPolicy().SetWakable( false );
|
m_mutex.GetMutexPolicy().SetWakable( false );
|
||||||
#else
|
|
||||||
m_mutex.GetMutexPolicy().SetSleepTime( 1 );
|
|
||||||
#endif
|
#endif
|
||||||
|
m_mutex.GetMutexPolicy().SetSleepTime( 5 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -365,8 +364,11 @@ Thing::~Thing( void )
|
||||||
void Thing::Print( unsigned int value, unsigned int index, unsigned int startSize ) const volatile
|
void Thing::Print( unsigned int value, unsigned int index, unsigned int startSize ) const volatile
|
||||||
{
|
{
|
||||||
assert( NULL != this );
|
assert( NULL != this );
|
||||||
volatile SleepMutex & mutex = const_cast< volatile SleepMutex & >( m_mutex );
|
MutexLocker locker( m_mutex );
|
||||||
ConstSingleThingLocker pSafeThis( *this, mutex );
|
assert( m_mutex.IsLockedByCurrentThread() );
|
||||||
|
// volatile SleepMutex & mutex = const_cast< volatile SleepMutex & >( m_mutex );
|
||||||
|
// ConstSingleThingLocker pSafeThis( *this, mutex );
|
||||||
|
const Thing * pSafeThis = const_cast< const Thing * >( this );
|
||||||
pSafeThis->Print( value, index, startSize );
|
pSafeThis->Print( value, index, startSize );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,11 +455,9 @@ LevelThing::LevelThing( unsigned int level, unsigned int place ) :
|
||||||
{
|
{
|
||||||
assert( NULL != this );
|
assert( NULL != this );
|
||||||
#if defined( _MSC_VER )
|
#if defined( _MSC_VER )
|
||||||
m_mutex.GetMutexPolicy().SetSleepTime( 5 );
|
|
||||||
m_mutex.GetMutexPolicy().SetWakable( false );
|
m_mutex.GetMutexPolicy().SetWakable( false );
|
||||||
#else
|
|
||||||
m_mutex.GetMutexPolicy().SetSleepTime( 1 );
|
|
||||||
#endif
|
#endif
|
||||||
|
m_mutex.GetMutexPolicy().SetSleepTime( 5 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -469,7 +469,7 @@ LevelThing::~LevelThing( void )
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
LevelThing::Unlocker LevelThing::LockHierarchy( void ) volatile
|
LevelThing::MyUnlocker LevelThing::LockHierarchy( void ) volatile
|
||||||
{
|
{
|
||||||
assert( NULL != this );
|
assert( NULL != this );
|
||||||
for ( signed ii = m_place; 0 <= ii; --ii )
|
for ( signed ii = m_place; 0 <= ii; --ii )
|
||||||
|
@ -481,7 +481,7 @@ LevelThing::Unlocker LevelThing::LockHierarchy( void ) volatile
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Unlocker unlocker( this );
|
MyUnlocker unlocker( this );
|
||||||
return unlocker;
|
return unlocker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -578,11 +578,9 @@ SomeThing::SomeThing( unsigned int level, unsigned int place ) :
|
||||||
{
|
{
|
||||||
assert( NULL != this );
|
assert( NULL != this );
|
||||||
#if defined( _MSC_VER )
|
#if defined( _MSC_VER )
|
||||||
m_mutex.GetMutexPolicy().SetSleepTime( 5 );
|
|
||||||
m_mutex.GetMutexPolicy().SetWakable( false );
|
m_mutex.GetMutexPolicy().SetWakable( false );
|
||||||
#else
|
|
||||||
m_mutex.GetMutexPolicy().SetSleepTime( 1 );
|
|
||||||
#endif
|
#endif
|
||||||
|
m_mutex.GetMutexPolicy().SetSleepTime( 5 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue