Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit d9b35cc

Browse files
committed
extern(D) for functions interacting between osthread.d and threadbase.d
1 parent 20fac73 commit d9b35cc

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

src/core/thread/osthread.d

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ else version (Posix)
105105
}
106106
}
107107

108-
package extern(C) immutable size_t threadSizeof = Thread.sizeof;
109-
110108
version (Solaris)
111109
{
112110
import core.sys.solaris.sys.priocntl;
@@ -177,7 +175,6 @@ version (DigitalMars)
177175
else
178176
mixin swapContextDefault;
179177

180-
181178
///////////////////////////////////////////////////////////////////////////////
182179
// Thread
183180
///////////////////////////////////////////////////////////////////////////////
@@ -967,12 +964,12 @@ class Thread : ThreadBase
967964
}
968965
}
969966

970-
private Thread toThread(ThreadBase t) @safe nothrow @nogc pure
967+
private Thread toThread(ThreadBase t) @trusted nothrow @nogc pure
971968
{
972-
return cast(Thread) t;
969+
return cast(Thread) cast(void*) t;
973970
}
974971

975-
private extern(C) static void thread_yield() @nogc nothrow
972+
private extern(D) static void thread_yield() @nogc nothrow
976973
{
977974
Thread.yield();
978975
}
@@ -1201,8 +1198,10 @@ version (Posix)
12011198
__gshared int resumeSignalNumber;
12021199
}
12031200

1204-
private extern (C) Thread attachThread(Thread thisThread) @nogc
1201+
private extern (D) ThreadBase attachThread(ThreadBase _thisThread) @nogc
12051202
{
1203+
Thread thisThread = _thisThread.toThread();
1204+
12061205
StackContext* thisContext = &thisThread.m_main;
12071206
assert( thisContext == thisThread.m_curr );
12081207

@@ -1219,7 +1218,7 @@ private extern (C) Thread attachThread(Thread thisThread) @nogc
12191218
thisContext.bstack = getStackBottom();
12201219
thisContext.tstack = thisContext.bstack;
12211220

1222-
atomicStore!(MemoryOrder.raw)(thisThread.m_isRunning, true);
1221+
atomicStore!(MemoryOrder.raw)(thisThread.toThread.m_isRunning, true);
12231222
}
12241223
thisThread.m_isDaemon = true;
12251224
thisThread.tlsGCdataInit();
@@ -1317,7 +1316,7 @@ version (Windows)
13171316

13181317

13191318
// Calls the given delegate, passing the current thread's stack pointer to it.
1320-
package extern(C) void callWithStackShell(scope callWithStackShellDg fn) nothrow
1319+
package extern(D) void callWithStackShell(scope callWithStackShellDg fn) nothrow
13211320
in (fn)
13221321
{
13231322
// The purpose of the 'shell' is to ensure all the registers get
@@ -1446,7 +1445,7 @@ extern (C) @nogc nothrow
14461445
}
14471446

14481447

1449-
package extern(C) void* getStackTop() nothrow @nogc
1448+
package extern(D) void* getStackTop() nothrow @nogc
14501449
{
14511450
version (D_InlineAsm_X86)
14521451
asm pure nothrow @nogc { naked; mov EAX, ESP; ret; }
@@ -1459,7 +1458,7 @@ package extern(C) void* getStackTop() nothrow @nogc
14591458
}
14601459

14611460

1462-
package extern(C) void* getStackBottom() nothrow @nogc
1461+
package extern(D) void* getStackBottom() nothrow @nogc
14631462
{
14641463
version (Windows)
14651464
{
@@ -1540,7 +1539,7 @@ package extern(C) void* getStackBottom() nothrow @nogc
15401539
* Returns:
15411540
* Whether the thread is now suspended (true) or terminated (false).
15421541
*/
1543-
private extern (C) bool suspend( Thread t ) nothrow
1542+
private extern (D) bool suspend( Thread t ) nothrow
15441543
{
15451544
Duration waittime = dur!"usecs"(10);
15461545
Lagain:
@@ -1841,8 +1840,10 @@ extern (C) void thread_suspendAll() nothrow
18411840
* Throws:
18421841
* ThreadError if the resume fails for a running thread.
18431842
*/
1844-
private extern (C) void resume( Thread t ) nothrow
1843+
private extern (D) void resume(ThreadBase _t) nothrow
18451844
{
1845+
Thread t = _t.toThread;
1846+
18461847
version (Windows)
18471848
{
18481849
if ( t.m_addr != GetCurrentThreadId() && ResumeThread( t.m_hndl ) == 0xFFFFFFFF )

src/core/thread/threadbase.d

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import core.stdc.stdlib : free, realloc;
2020

2121
private
2222
{
23-
// interface to rt.tlsgc
2423
import core.internal.traits : externDFunc;
2524

25+
// interface to rt.tlsgc
2626
alias rt_tlsgc_init = externDFunc!("rt.tlsgc.init", void* function() nothrow @nogc);
2727
alias rt_tlsgc_destroy = externDFunc!("rt.tlsgc.destroy", void function(void*) nothrow @nogc);
2828

@@ -84,10 +84,8 @@ private
8484

8585
extern(C) void* swapContext(void* newContext) nothrow @nogc;
8686

87-
extern extern(C) immutable size_t threadSizeof;
88-
89-
extern(C) void* getStackBottom() nothrow @nogc;
90-
extern(C) void* getStackTop() nothrow @nogc;
87+
alias getStackBottom = externDFunc!("core.thread.osthread.getStackBottom", void* function() nothrow @nogc);
88+
alias getStackTop = externDFunc!("core.thread.osthread.getStackTop", void* function() nothrow @nogc);
9189
}
9290

9391

@@ -355,7 +353,7 @@ class ThreadBase
355353
{
356354
static void resize(ref ThreadBase[] buf, size_t nlen)
357355
{
358-
buf = (cast(ThreadBase*)realloc(buf.ptr, nlen * threadSizeof))[0 .. nlen];
356+
buf = (cast(ThreadBase*)realloc(buf.ptr, nlen * size_t.sizeof))[0 .. nlen];
359357
}
360358
auto buf = getAllImpl!resize;
361359
scope(exit) if (buf.ptr) free(buf.ptr);
@@ -690,9 +688,9 @@ package(core.thread):
690688
}
691689
assert(idx != -1);
692690
import core.stdc.string : memmove;
693-
memmove(pAboutToStart + idx, pAboutToStart + idx + 1, threadSizeof * (nAboutToStart - idx - 1));
691+
memmove(pAboutToStart + idx, pAboutToStart + idx + 1, size_t.sizeof * (nAboutToStart - idx - 1));
694692
pAboutToStart =
695-
cast(ThreadBase*)realloc(pAboutToStart, threadSizeof * --nAboutToStart);
693+
cast(ThreadBase*)realloc(pAboutToStart, size_t.sizeof * --nAboutToStart);
696694
}
697695

698696
if (sm_tbeg)
@@ -756,7 +754,7 @@ package(core.thread):
756754
// GC Support Routines
757755
///////////////////////////////////////////////////////////////////////////////
758756

759-
extern (C) ThreadBase attachThread(ThreadBase thisThread) @nogc;
757+
private alias attachThread = externDFunc!("core.thread.osthread.attachThread", ThreadBase function(ThreadBase) @nogc);
760758

761759
extern (C) void _d_monitordelete_nogc(Object h) @nogc;
762760

@@ -969,7 +967,7 @@ package __gshared bool multiThreadedFlag = false;
969967
// Used for suspendAll/resumeAll below.
970968
package __gshared uint suspendDepth = 0;
971969

972-
private extern (C) void resume(ThreadBase) nothrow;
970+
private alias resume = externDFunc!("core.thread.osthread.resume", void function(ThreadBase) nothrow);
973971

974972
/**
975973
* Resume all threads but the calling thread for "stop the world" garbage
@@ -1044,7 +1042,7 @@ do
10441042
}
10451043

10461044
package alias callWithStackShellDg = void delegate(void* sp) nothrow;
1047-
private extern(C) void callWithStackShell(scope callWithStackShellDg fn) nothrow;
1045+
private alias callWithStackShell = externDFunc!("core.thread.osthread.callWithStackShell", void function(scope callWithStackShellDg) nothrow);
10481046

10491047
private void scanAllTypeImpl(scope ScanAllThreadsTypeFn scan, void* curStackTop) nothrow
10501048
{
@@ -1125,7 +1123,7 @@ extern (C) void thread_scanAll(scope ScanAllThreadsFn scan) nothrow
11251123
thread_scanAllType((type, p1, p2) => scan(p1, p2));
11261124
}
11271125

1128-
private extern (C) static void thread_yield() @nogc nothrow;
1126+
private alias thread_yield = externDFunc!("core.thread.osthread.thread_yield", void function() @nogc nothrow);
11291127

11301128
/**
11311129
* Signals that the code following this call is a critical region. Any code in

0 commit comments

Comments
 (0)