mirror of
https://github.com/golang/go
synced 2024-10-06 21:11:22 -06:00
718be3215f
(eliminate assumption of package global name space, make code easier to move between packages). R=r CC=golang-dev https://golang.org/cl/194072
63 lines
995 B
C
63 lines
995 B
C
// Copyright 2009 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
#include "runtime.h"
|
|
#include "cgocall.h"
|
|
|
|
void *initcgo; /* filled in by dynamic linker when Cgo is available */
|
|
int64 ncgocall;
|
|
void ·entersyscall(void);
|
|
void ·exitsyscall(void);
|
|
|
|
void
|
|
cgocall(void (*fn)(void*), void *arg)
|
|
{
|
|
if(initcgo == nil)
|
|
throw("cgocall unavailable");
|
|
|
|
ncgocall++;
|
|
|
|
/*
|
|
* Announce we are entering a system call
|
|
* so that the scheduler knows to create another
|
|
* M to run goroutines while we are in the
|
|
* foreign code.
|
|
*/
|
|
·entersyscall();
|
|
runcgo(fn, arg);
|
|
·exitsyscall();
|
|
return;
|
|
}
|
|
|
|
void
|
|
·Cgocalls(int64 ret)
|
|
{
|
|
ret = ncgocall;
|
|
FLUSH(&ret);
|
|
}
|
|
|
|
void (*_cgo_malloc)(void*);
|
|
void (*_cgo_free)(void*);
|
|
|
|
void*
|
|
cmalloc(uintptr n)
|
|
{
|
|
struct a {
|
|
uint64 n;
|
|
void *ret;
|
|
} a;
|
|
|
|
a.n = n;
|
|
a.ret = nil;
|
|
cgocall(_cgo_malloc, &a);
|
|
return a.ret;
|
|
}
|
|
|
|
void
|
|
cfree(void *p)
|
|
{
|
|
cgocall(_cgo_free, p);
|
|
}
|
|
|