Skip to content

Commit d0e52a1

Browse files
committed
receive() now works even if thisTid() has never been called within the main thread. also applied use of Duration throughout the receiveTimeout code, since core.sync uses Duration as its native time representation internally as well.
1 parent 083a91a commit d0e52a1

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

std/concurrency.d

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,9 @@ private
162162
}
163163

164164

165-
static this()
165+
shared static this()
166166
{
167-
// NOTE: thisTid will construct a new MessageBox if one doesn't exist,
168-
// which should only be true of the main thread and threads created
169-
// via core.thread instead of spawn.
167+
mbox = new MessageBox;
170168
}
171169

172170

@@ -496,17 +494,22 @@ receiveOnlyRet!(T) receiveOnly(T...)()
496494
*/
497495
bool receiveTimeout(T...)( long ms, T ops )
498496
{
497+
//return receiveTimeout( dur!"msecs"( ms ), ops );
499498
checkops( ops );
500-
static enum long TICKS_PER_MILLI = 10_000;
501-
return mbox.get( ms * TICKS_PER_MILLI, ops );
499+
return mbox.get( dur!"msecs"( ms ), ops );
502500
}
503501

504-
/++ ditto +/
505-
bool receiveTimeout(T...)( Duration duration, T ops )
502+
503+
/**
504+
*
505+
*/
506+
bool receiveTimeout(T...)( Duration val, T ops )
506507
{
507-
return receiveTimeout(duration.total!"msecs"(), ops);
508+
checkops( ops );
509+
return mbox.get( val, ops );
508510
}
509511

512+
510513
unittest
511514
{
512515
assert( __traits( compiles,
@@ -527,7 +530,7 @@ unittest
527530

528531
assert( __traits( compiles,
529532
{
530-
receiveTimeout( dur!"msecs"(10), (int x) {}, (Variant x) {} );
533+
receiveTimeout( dur!"msecs"( 10 ), (Variant x) {} );
531534
} ) );
532535
}
533536

@@ -848,13 +851,12 @@ private
848851
{
849852
static assert( T.length );
850853

851-
static if( isImplicitlyConvertible!(T[0], long) )
854+
static if( is( T[0] : Duration ) )
852855
{
853856
alias TypeTuple!(T[1 .. $]) Ops;
854857
alias vals[1 .. $] ops;
855-
assert( vals[0] >= 0 );
856858
enum timedWait = true;
857-
long period = vals[0];
859+
auto period = vals[0];
858860
}
859861
else
860862
{

0 commit comments

Comments
 (0)