diff --git a/src/core/sync/condition.d b/src/core/sync/condition.d index c86220883a4..68afb94ba00 100644 --- a/src/core/sync/condition.d +++ b/src/core/sync/condition.d @@ -570,8 +570,8 @@ version( unittest ) synchronized( mutex ) { waiting = true; - alertedOne = condReady.wait( 10_000_000 ); // 1s - alertedTwo = condReady.wait( 10_000_000 ); // 1s + alertedOne = condReady.wait( dur!"seconds"(1) ); + alertedTwo = condReady.wait( dur!"seconds"(1) ); } } diff --git a/src/core/sync/exception.d b/src/core/sync/exception.d index 89077d34ce9..c5661b6af29 100644 --- a/src/core/sync/exception.d +++ b/src/core/sync/exception.d @@ -20,8 +20,13 @@ module core.sync.exception; */ class SyncException : Exception { - this( string msg ) + this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) { - super( msg ); + super(msg, file, line, next); + } + + this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__) + { + super(msg, file, line, next); } } diff --git a/src/core/sync/mutex.d b/src/core/sync/mutex.d index 4fa18d04ff4..35515a08151 100644 --- a/src/core/sync/mutex.d +++ b/src/core/sync/mutex.d @@ -62,8 +62,16 @@ class Mutex : } else version( Posix ) { - int rc = pthread_mutex_init( &m_hndl, &sm_attr ); - if( rc ) + pthread_mutexattr_t attr = void; + + if( pthread_mutexattr_init( &attr ) ) + throw new SyncException( "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" ); + + if( pthread_mutex_init( &m_hndl, &attr ) ) throw new SyncException( "Unable to initialize mutex" ); } m_proxy.link = this; @@ -177,26 +185,6 @@ class Mutex : } - version( Posix ) - { - shared static this() - { - int rc = pthread_mutexattr_init( &sm_attr ); - assert( !rc ); - - rc = pthread_mutexattr_settype( &sm_attr, PTHREAD_MUTEX_RECURSIVE ); - assert( !rc ); - } - - - shared static ~this() - { - int rc = pthread_mutexattr_destroy( &sm_attr ); - assert( !rc ); - } - } - - private: version( Win32 ) { @@ -204,8 +192,6 @@ private: } else version( Posix ) { - __gshared pthread_mutexattr_t sm_attr; - pthread_mutex_t m_hndl; } diff --git a/src/core/sync/semaphore.d b/src/core/sync/semaphore.d index e88200e7a0f..3eb497d2aac 100644 --- a/src/core/sync/semaphore.d +++ b/src/core/sync/semaphore.d @@ -493,8 +493,8 @@ version( unittest ) { waiting = true; } - alertedOne = semReady.wait( 10_000_000 ); // 100ms - alertedTwo = semReady.wait( 10_000_000 ); // 100ms + alertedOne = semReady.wait( dur!"msecs"(200) ); + alertedTwo = semReady.wait( dur!"msecs"(200) ); } auto thread = new Thread( &waiter ); diff --git a/src/core/thread.d b/src/core/thread.d index a3173062138..9ef2372570d 100644 --- a/src/core/thread.d +++ b/src/core/thread.d @@ -33,9 +33,14 @@ version = StackGrowsDown; */ class ThreadException : Exception { - this( string msg ) + this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) { - super( msg ); + super(msg, file, line, next); + } + + this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__) + { + super(msg, file, line, next); } } @@ -45,15 +50,22 @@ class ThreadException : Exception */ class FiberException : Exception { - this( string msg ) + this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) { - super( msg ); + super(msg, file, line, next); + } + + this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__) + { + super(msg, file, line, next); } } private { + import core.sync.mutex; + // // from core.memory // @@ -1577,9 +1589,21 @@ private: // // All use of the global lists should synchronize on this lock. // - static Object slock() + static Mutex slock() { - return Thread.classinfo; + static Mutex m = null; + + if( m !is null ) + return m; + else + { + auto ci = Mutex.classinfo; + auto p = malloc( ci.init.length ); + (cast(byte*) p)[0 .. ci.init.length] = ci.init[]; + m = cast(Mutex) p; + m.__ctor(); + return m; + } } @@ -2105,6 +2129,11 @@ extern (C) void thread_joinAll() foreach( t; Thread ) { + if( !t.isRunning ) + { + Thread.remove( t ); + continue; + } if( !t.isDaemon ) { nonDaemon = t; @@ -2338,7 +2367,8 @@ extern (C) void thread_suspendAll() suspend( Thread.getThis() ); return; } - synchronized( Thread.slock ) + + Thread.slock.lock(); { if( ++suspendDepth > 1 ) return; @@ -2462,7 +2492,8 @@ body resume( Thread.getThis() ); return; } - synchronized( Thread.slock ) + + scope(exit) Thread.slock.unlock(); { if( --suspendDepth > 0 ) return; diff --git a/src/object_.d b/src/object_.d index 53b95b3c96b..2c408274bed 100644 --- a/src/object_.d +++ b/src/object_.d @@ -1328,6 +1328,7 @@ class Exception : Throwable { super(msg, file, line, next); } + this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__) { super(msg, file, line, next);