Commit 9042c2ce authored by Russ Cox's avatar Russ Cox

runtime/cgo: runtime changes for new cgo

Formerly known as libcgo.
Almost no code here is changing; the diffs
are shown relative to the originals in libcgo.

R=r
CC=golang-dev
https://golang.org/cl/3420043
parent cf42a455
...@@ -109,6 +109,7 @@ DIRS=\ ...@@ -109,6 +109,7 @@ DIRS=\
rpc\ rpc\
rpc/jsonrpc\ rpc/jsonrpc\
runtime\ runtime\
runtime/cgo\
runtime/pprof\ runtime/pprof\
scanner\ scanner\
smtp\ smtp\
...@@ -152,6 +153,7 @@ NOTEST=\ ...@@ -152,6 +153,7 @@ NOTEST=\
image/jpeg\ image/jpeg\
net/dict\ net/dict\
rand\ rand\
runtime/cgo\
runtime/pprof\ runtime/pprof\
syscall\ syscall\
testing\ testing\
...@@ -247,3 +249,4 @@ deps: ...@@ -247,3 +249,4 @@ deps:
-include Make.deps -include Make.deps
../cmd/cgo.install: ../libcgo.install ../cmd/cgo.install: ../libcgo.install
runtime/cgo.install: ../cmd/cgo.install
...@@ -15,9 +15,12 @@ runtime·cgocall(void (*fn)(void*), void *arg) ...@@ -15,9 +15,12 @@ runtime·cgocall(void (*fn)(void*), void *arg)
{ {
G *oldlock; G *oldlock;
if(initcgo == nil) if(!runtime·iscgo)
runtime·throw("cgocall unavailable"); runtime·throw("cgocall unavailable");
if(fn == 0)
runtime·throw("cgocall nil");
ncgocall++; ncgocall++;
/* /*
...@@ -94,7 +97,7 @@ void (*_cgo_free)(void*); ...@@ -94,7 +97,7 @@ void (*_cgo_free)(void*);
void* void*
runtime·cmalloc(uintptr n) runtime·cmalloc(uintptr n)
{ {
struct a { struct {
uint64 n; uint64 n;
void *ret; void *ret;
} a; } a;
......
...@@ -144,8 +144,7 @@ runtime·osinit(void) ...@@ -144,8 +144,7 @@ runtime·osinit(void)
// Register our thread-creation callback (see {amd64,386}/sys.s) // Register our thread-creation callback (see {amd64,386}/sys.s)
// but only if we're not using cgo. If we are using cgo we need // but only if we're not using cgo. If we are using cgo we need
// to let the C pthread libary install its own thread-creation callback. // to let the C pthread libary install its own thread-creation callback.
extern void (*libcgo_thread_start)(void*); if(!runtime·iscgo)
if(libcgo_thread_start == nil)
runtime·bsdthread_register(); runtime·bsdthread_register();
} }
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "malloc.h" #include "malloc.h"
#include "os.h" #include "os.h"
bool runtime·iscgo;
static void unwindstack(G*, byte*); static void unwindstack(G*, byte*);
typedef struct Sched Sched; typedef struct Sched Sched;
...@@ -426,8 +428,11 @@ matchmg(void) ...@@ -426,8 +428,11 @@ matchmg(void)
runtime·allm = m; runtime·allm = m;
m->id = runtime·sched.mcount++; m->id = runtime·sched.mcount++;
if(libcgo_thread_start != nil) { if(runtime·iscgo) {
CgoThreadStart ts; CgoThreadStart ts;
if(libcgo_thread_start == nil)
runtime·throw("libcgo_thread_start missing");
// pthread_create will make us a stack. // pthread_create will make us a stack.
m->g0 = runtime·malg(-1); m->g0 = runtime·malg(-1);
ts.m = m; ts.m = m;
......
...@@ -361,6 +361,7 @@ extern int32 runtime·panicking; ...@@ -361,6 +361,7 @@ extern int32 runtime·panicking;
extern int32 runtime·fd; // usually 1; set to 2 when panicking extern int32 runtime·fd; // usually 1; set to 2 when panicking
extern int32 runtime·gcwaiting; // gc is waiting to run extern int32 runtime·gcwaiting; // gc is waiting to run
int8* runtime·goos; int8* runtime·goos;
extern bool runtime·iscgo;
/* /*
* common functions and data * common functions and data
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment