Showing with 76 additions and 77 deletions.
  1. +3 −2 src/core/sync/barrier.d
  2. +13 −12 src/core/sync/condition.d
  3. +3 −3 src/core/sync/config.d
  4. +2 −2 src/core/sync/exception.d
  5. +10 −9 src/core/sync/mutex.d
  6. +7 −8 src/core/sync/rwmutex.d
  7. +21 −20 src/core/sync/semaphore.d
  8. +1 −0 src/core/sys/osx/mach/semaphore.d
  9. +8 −8 src/core/thread.d
  10. +2 −7 src/gc/gc.d
  11. +2 −2 src/object.di
  12. +4 −4 src/object_.d
5 changes: 3 additions & 2 deletions src/core/sync/barrier.d
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ else version( Posix )
*/
class Barrier
{
nothrow:
////////////////////////////////////////////////////////////////////////////
// Initialization
////////////////////////////////////////////////////////////////////////////
Expand All @@ -57,7 +58,7 @@ class Barrier
* limit = The number of waiting threads to release in unison.
*
* Throws:
* SyncException on error.
* SyncError on error.
*/
this( uint limit )
in
Expand All @@ -83,7 +84,7 @@ class Barrier
* Wait for the pre-determined number of threads and then proceed.
*
* Throws:
* SyncException on error.
* SyncError on error.
*/
void wait()
{
Expand Down
25 changes: 13 additions & 12 deletions src/core/sync/condition.d
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ else
*/
class Condition
{
nothrow:
////////////////////////////////////////////////////////////////////////////
// Initialization
////////////////////////////////////////////////////////////////////////////
Expand All @@ -67,20 +68,20 @@ class Condition
* m = The mutex with which this condition will be associated.
*
* Throws:
* SyncException on error.
* SyncError on error.
*/
this( Mutex m ) @safe
{
version( Windows )
{
m_blockLock = CreateSemaphoreA( null, 1, 1, null );
if( m_blockLock == m_blockLock.init )
throw new SyncException( "Unable to initialize condition" );
throw new SyncError( "Unable to initialize condition" );
scope(failure) CloseHandle( m_blockLock );

m_blockQueue = CreateSemaphoreA( null, 0, int.max, null );
if( m_blockQueue == m_blockQueue.init )
throw new SyncException( "Unable to initialize condition" );
throw new SyncError( "Unable to initialize condition" );
scope(failure) CloseHandle( m_blockQueue );

InitializeCriticalSection( &m_unblockLock );
Expand All @@ -91,7 +92,7 @@ class Condition
m_assocMutex = m;
int rc = pthread_cond_init( &m_hndl, null );
if( rc )
throw new SyncException( "Unable to initialize condition" );
throw new SyncError( "Unable to initialize condition" );
}
}

Expand Down Expand Up @@ -140,7 +141,7 @@ class Condition
* Wait until notified.
*
* Throws:
* SyncException on error.
* SyncError on error.
*/
void wait()
{
Expand All @@ -152,7 +153,7 @@ class Condition
{
int rc = pthread_cond_wait( &m_hndl, m_assocMutex.handleAddr() );
if( rc )
throw new SyncException( "Unable to wait for condition" );
throw new SyncError( "Unable to wait for condition" );
}
}

Expand All @@ -168,7 +169,7 @@ class Condition
* val must be non-negative.
*
* Throws:
* SyncException on error.
* SyncError on error.
*
* Returns:
* true if notified before the timeout and false if not.
Expand Down Expand Up @@ -205,7 +206,7 @@ class Condition
return true;
if( rc == ETIMEDOUT )
return false;
throw new SyncException( "Unable to wait for condition" );
throw new SyncError( "Unable to wait for condition" );
}
}

Expand All @@ -214,7 +215,7 @@ class Condition
* Notifies one waiter.
*
* Throws:
* SyncException on error.
* SyncError on error.
*/
void notify()
{
Expand All @@ -226,7 +227,7 @@ class Condition
{
int rc = pthread_cond_signal( &m_hndl );
if( rc )
throw new SyncException( "Unable to notify condition" );
throw new SyncError( "Unable to notify condition" );
}
}

Expand All @@ -235,7 +236,7 @@ class Condition
* Notifies all waiters.
*
* Throws:
* SyncException on error.
* SyncError on error.
*/
void notifyAll()
{
Expand All @@ -247,7 +248,7 @@ class Condition
{
int rc = pthread_cond_broadcast( &m_hndl );
if( rc )
throw new SyncException( "Unable to notify condition" );
throw new SyncError( "Unable to notify condition" );
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/sync/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ version( Posix )
private import core.time;


void mktspec( ref timespec t )
void mktspec( ref timespec t ) nothrow
{
static if( false && is( typeof( clock_gettime ) ) )
{
Expand All @@ -41,14 +41,14 @@ version( Posix )
}


void mktspec( ref timespec t, Duration delta )
void mktspec( ref timespec t, Duration delta ) nothrow
{
mktspec( t );
mvtspec( t, delta );
}


void mvtspec( ref timespec t, Duration delta )
void mvtspec( ref timespec t, Duration delta ) nothrow
{
auto val = delta;
val += dur!"seconds"( t.tv_sec );
Expand Down
4 changes: 2 additions & 2 deletions src/core/sync/exception.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ module core.sync.exception;


/**
* Base class for synchronization exceptions.
* Base class for synchronization errors.
*/
class SyncException : Exception
class SyncError : Error
{
@safe pure nothrow this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null)
{
Expand Down
19 changes: 10 additions & 9 deletions src/core/sync/mutex.d
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ else
class Mutex :
Object.Monitor
{
nothrow:
////////////////////////////////////////////////////////////////////////////
// Initialization
////////////////////////////////////////////////////////////////////////////
Expand All @@ -56,7 +57,7 @@ class Mutex :
* Initializes a mutex object.
*
* Throws:
* SyncException on error.
* SyncError on error.
*/
this() @trusted
{
Expand All @@ -69,14 +70,14 @@ class Mutex :
pthread_mutexattr_t attr = void;

if( pthread_mutexattr_init( &attr ) )
throw new SyncException( "Unable to initialize mutex" );
throw new SyncError( "Unable to initialize mutex" );
scope(exit) pthread_mutexattr_destroy( &attr );

if( pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE ) )
throw new SyncException( "Unable to initialize mutex" );
throw new SyncError( "Unable to initialize mutex" );

if( pthread_mutex_init( &m_hndl, &attr ) )
throw new SyncException( "Unable to initialize mutex" );
throw new SyncError( "Unable to initialize mutex" );
}
m_proxy.link = this;
this.__monitor = &m_proxy;
Expand Down Expand Up @@ -126,11 +127,11 @@ class Mutex :
* then the internal counter is incremented by one.
*
* Throws:
* SyncException on error.
* SyncError on error.
*/
@trusted void lock()
{
lock_impl!SyncException();
lock_impl!SyncError();
}

@trusted void lock_nothrow() nothrow
Expand All @@ -156,11 +157,11 @@ class Mutex :
* zero, the lock is released.
*
* Throws:
* SyncException on error.
* SyncError on error.
*/
@trusted void unlock()
{
unlock_impl!SyncException();
unlock_impl!SyncError();
}

@trusted void unlock_nothrow() nothrow
Expand Down Expand Up @@ -188,7 +189,7 @@ class Mutex :
* counter is incremented by one.
*
* Throws:
* SyncException on error.
* SyncError on error.
*
* Returns:
* true if the lock was acquired and false if not.
Expand Down
15 changes: 7 additions & 8 deletions src/core/sync/rwmutex.d
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ else version( Posix )
*/
class ReadWriteMutex
{
nothrow:
/**
* Defines the policy used by this mutex. Currently, two policies are
* defined.
Expand Down Expand Up @@ -88,31 +89,27 @@ class ReadWriteMutex
* policy = The policy to use.
*
* Throws:
* SyncException on error.
* SyncError on error.
*/
this( Policy policy = Policy.PREFER_WRITERS )
{
m_commonMutex = new Mutex;
if( !m_commonMutex )
throw new SyncException( "Unable to initialize mutex" );
scope(failure) { destroy(m_commonMutex); GC.free(cast(void*)m_commonMutex); }
throw new SyncError( "Unable to initialize mutex" );

m_readerQueue = new Condition( m_commonMutex );
if( !m_readerQueue )
throw new SyncException( "Unable to initialize mutex" );
scope(failure) { destroy(m_readerQueue); GC.free(cast(void*)m_readerQueue); }
throw new SyncError( "Unable to initialize mutex" );

m_writerQueue = new Condition( m_commonMutex );
if( !m_writerQueue )
throw new SyncException( "Unable to initialize mutex" );
scope(failure) { destroy(m_writerQueue); GC.free(cast(void*)m_writerQueue); }
throw new SyncError( "Unable to initialize mutex" );

m_policy = policy;
m_reader = new Reader;
m_writer = new Writer;
}


////////////////////////////////////////////////////////////////////////////
// General Properties
////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -171,6 +168,7 @@ class ReadWriteMutex
class Reader :
Object.Monitor
{
nothrow:
/**
* Initializes a read/write mutex reader proxy object.
*/
Expand Down Expand Up @@ -274,6 +272,7 @@ class ReadWriteMutex
class Writer :
Object.Monitor
{
nothrow:
/**
* Initializes a read/write mutex writer proxy object.
*/
Expand Down
Loading