]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: split minit() to mpreinit() and minit()
authorDmitriy Vyukov <dvyukov@google.com>
Thu, 21 Feb 2013 12:24:38 +0000 (16:24 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Thu, 21 Feb 2013 12:24:38 +0000 (16:24 +0400)
mpreinit() is called on the parent thread and with mcache (can allocate memory),
minit() is called on the child thread and can not allocate memory.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7389043

src/pkg/runtime/proc.c
src/pkg/runtime/runtime.h
src/pkg/runtime/thread_darwin.c
src/pkg/runtime/thread_freebsd.c
src/pkg/runtime/thread_linux.c
src/pkg/runtime/thread_netbsd.c
src/pkg/runtime/thread_openbsd.c
src/pkg/runtime/thread_plan9.c
src/pkg/runtime/thread_windows.c

index 67d6dad4885f29f67cf0f7e267d2a6c8788bde2b..5c36ddf745fb4dd298766f67e623cc6c2da52c09 100644 (file)
@@ -370,6 +370,8 @@ mcommoninit(M *mp)
 
        runtime·callers(1, mp->createstack, nelem(mp->createstack));
 
+       runtime·mpreinit(mp);
+
        // Add to runtime·allm so garbage collector doesn't free m
        // when it is just in a register or thread-local storage.
        mp->alllink = runtime·allm;
index 8162874bbe8cc5f03789ea8fe72af51427b8d04a..4ca7cc7dc9dfb49ff86f71dab90ae045588cb8b3 100644 (file)
@@ -660,6 +660,7 @@ int32       runtime·atoi(byte*);
 void   runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void));
 G*     runtime·malg(int32);
 void   runtime·asminit(void);
+void   runtime·mpreinit(M*);
 void   runtime·minit(void);
 void   runtime·unminit(void);
 void   runtime·signalstack(byte*, int32);
index 1d6037b48b07c2c54874d6fa631d235fd8674adf..1a13eba1cdbc24a3a7886985525a2f7b68470d3a 100644 (file)
@@ -109,12 +109,19 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
 }
 
 // Called to initialize a new m (including the bootstrap m).
+// Called on the parent thread (main thread in case of bootstrap), can allocate memory.
+void
+runtime·mpreinit(M *mp)
+{
+       mp->gsignal = runtime·malg(32*1024);   // OS X wants >=8K, Linux >=2K
+}
+
+// Called to initialize a new m (including the bootstrap m).
+// Called on the new thread, can not allocate memory.
 void
 runtime·minit(void)
 {
        // Initialize signal handling.
-       if(m->gsignal == nil)
-               m->gsignal = runtime·malg(32*1024);    // OS X wants >=8K, Linux >=2K
        runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024);
 
        runtime·sigprocmask(SIG_SETMASK, &sigset_none, nil);
index 4d5f69a9f3f8861755679bf9a112e9c215ae0494..d7758eaafbbeada1bf39406f041b1fcb2dd6c1c9 100644 (file)
@@ -121,11 +121,19 @@ runtime·goenvs(void)
 }
 
 // Called to initialize a new m (including the bootstrap m).
+// Called on the parent thread (main thread in case of bootstrap), can allocate memory.
+void
+runtime·mpreinit(M *mp)
+{
+       mp->gsignal = runtime·malg(32*1024);
+}
+
+// Called to initialize a new m (including the bootstrap m).
+// Called on the new thread, can not allocate memory.
 void
 runtime·minit(void)
 {
        // Initialize signal handling
-       m->gsignal = runtime·malg(32*1024);
        runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024);
        runtime·sigprocmask(&sigset_none, nil);
 }
index 02a5eaee2f653393c2a24c93c0142093fd5349aa..85c3e6b8cf61a143505ac711b31485b76466d47d 100644 (file)
@@ -171,12 +171,19 @@ runtime·goenvs(void)
 }
 
 // Called to initialize a new m (including the bootstrap m).
+// Called on the parent thread (main thread in case of bootstrap), can allocate memory.
+void
+runtime·mpreinit(M *mp)
+{
+       mp->gsignal = runtime·malg(32*1024);   // OS X wants >=8K, Linux >=2K
+}
+
+// Called to initialize a new m (including the bootstrap m).
+// Called on the new thread, can not allocate memory.
 void
 runtime·minit(void)
 {
        // Initialize signal handling.
-       if(m->gsignal == nil)
-               m->gsignal = runtime·malg(32*1024);    // OS X wants >=8K, Linux >=2K
        runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024);
        runtime·rtsigprocmask(SIG_SETMASK, &sigset_none, nil, sizeof(Sigset));
 }
index ebef45e75712381ef0d30f32c3a6c8df5cbb55d1..aba8fea7a2ef0a1d5c068049c56fc2b97107dac4 100644 (file)
@@ -187,14 +187,21 @@ runtime·goenvs(void)
 }
 
 // Called to initialize a new m (including the bootstrap m).
+// Called on the parent thread (main thread in case of bootstrap), can allocate memory.
+void
+runtime·mpreinit(M *mp)
+{
+       mp->gsignal = runtime·malg(32*1024);
+}
+
+// Called to initialize a new m (including the bootstrap m).
+// Called on the new thread, can not allocate memory.
 void
 runtime·minit(void)
 {
        m->procid = runtime·lwp_self();
 
        // Initialize signal handling
-       if(m->gsignal == nil)
-               m->gsignal = runtime·malg(32*1024);
        runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024);
        runtime·sigprocmask(SIG_SETMASK, &sigset_none, nil);
 }
index 8433e8bae5362349ed31f823f67251bc6a5cef88..525dc697e018ca2571bc4e9904a12dc912426a27 100644 (file)
@@ -166,12 +166,19 @@ runtime·goenvs(void)
 }
 
 // Called to initialize a new m (including the bootstrap m).
+// Called on the parent thread (main thread in case of bootstrap), can allocate memory.
+void
+runtime·mpreinit(M *mp)
+{
+       mp->gsignal = runtime·malg(32*1024);
+}
+
+// Called to initialize a new m (including the bootstrap m).
+// Called on the new thread, can not allocate memory.
 void
 runtime·minit(void)
 {
        // Initialize signal handling
-       if(m->gsignal == nil)
-               m->gsignal = runtime·malg(32*1024);
        runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024);
        runtime·sigprocmask(SIG_SETMASK, sigset_none);
 }
index bca0deac62f72f408559e6ca1c3d9f3345e83e2f..625c8b48d4d9cbcffcaa790fda86b142f7a012d0 100644 (file)
@@ -11,13 +11,21 @@ extern SigTab runtime·sigtab[];
 
 int32 runtime·postnote(int32, int8*);
 
+// Called to initialize a new m (including the bootstrap m).
+// Called on the parent thread (main thread in case of bootstrap), can allocate memory.
 void
-runtime·minit(void)
+runtime·mpreinit(M *mp)
 {
        // Initialize stack and goroutine for note handling.
-       m->gsignal = runtime·malg(32*1024);
-       m->notesig = (int8*)runtime·malloc(ERRMAX*sizeof(int8));
+       mp->gsignal = runtime·malg(32*1024);
+       mp->notesig = (int8*)runtime·malloc(ERRMAX*sizeof(int8));
+}
 
+// Called to initialize a new m (including the bootstrap m).
+// Called on the new thread, can not allocate memory.
+void
+runtime·minit(void)
+{
        // Mask all SSE floating-point exceptions
        // when running on the 64-bit kernel.
        runtime·setfpmasks();
index 7110c6efe423c5c66e431cc98b99899a5e644d60..4d95e998707267ba6a8178146aa04136ce11ff36 100644 (file)
@@ -206,6 +206,15 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
 }
 
 // Called to initialize a new m (including the bootstrap m).
+// Called on the parent thread (main thread in case of bootstrap), can allocate memory.
+void
+runtime·mpreinit(M *mp)
+{
+       USED(mp);
+}
+
+// Called to initialize a new m (including the bootstrap m).
+// Called on the new thread, can not allocate memory.
 void
 runtime·minit(void)
 {