mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
bugfix: in freebsd, libthr may call calloc before globalinit
This commit is contained in:
@@ -33,8 +33,8 @@ linux freebsd : SKYNET_LIBS += -lrt
|
|||||||
|
|
||||||
# Turn off jemalloc and malloc hook on macosx and freebsd
|
# Turn off jemalloc and malloc hook on macosx and freebsd
|
||||||
|
|
||||||
freebsd macosx : MALLOC_STATICLIB :=
|
macosx : MALLOC_STATICLIB :=
|
||||||
freebsd macosx : SKYNET_DEFINES :=-DNOUSE_JEMALLOC
|
macosx : SKYNET_DEFINES :=-DNOUSE_JEMALLOC
|
||||||
|
|
||||||
linux macosx freebsd :
|
linux macosx freebsd :
|
||||||
$(MAKE) all PLAT=$@ SKYNET_LIBS="$(SKYNET_LIBS)" SHARED="$(SHARED)" EXPORT="$(EXPORT)" MALLOC_STATICLIB="$(MALLOC_STATICLIB)" SKYNET_DEFINES="$(SKYNET_DEFINES)"
|
$(MAKE) all PLAT=$@ SKYNET_LIBS="$(SKYNET_LIBS)" SHARED="$(SHARED)" EXPORT="$(EXPORT)" MALLOC_STATICLIB="$(MALLOC_STATICLIB)" SKYNET_DEFINES="$(SKYNET_DEFINES)"
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ struct skynet_context {
|
|||||||
|
|
||||||
struct skynet_node {
|
struct skynet_node {
|
||||||
int total;
|
int total;
|
||||||
|
int init;
|
||||||
uint32_t monitor_exit;
|
uint32_t monitor_exit;
|
||||||
pthread_key_t handle_key;
|
pthread_key_t handle_key;
|
||||||
};
|
};
|
||||||
@@ -75,8 +76,13 @@ context_dec() {
|
|||||||
|
|
||||||
uint32_t
|
uint32_t
|
||||||
skynet_current_handle(void) {
|
skynet_current_handle(void) {
|
||||||
|
if (G_NODE.init) {
|
||||||
void * handle = pthread_getspecific(G_NODE.handle_key);
|
void * handle = pthread_getspecific(G_NODE.handle_key);
|
||||||
return (uint32_t)(uintptr_t)handle;
|
return (uint32_t)(uintptr_t)handle;
|
||||||
|
} else {
|
||||||
|
uintptr_t v = (uint32_t)(-THREAD_MAIN);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -650,6 +656,7 @@ void
|
|||||||
skynet_globalinit(void) {
|
skynet_globalinit(void) {
|
||||||
G_NODE.total = 0;
|
G_NODE.total = 0;
|
||||||
G_NODE.monitor_exit = 0;
|
G_NODE.monitor_exit = 0;
|
||||||
|
G_NODE.init = 1;
|
||||||
if (pthread_key_create(&G_NODE.handle_key, NULL)) {
|
if (pthread_key_create(&G_NODE.handle_key, NULL)) {
|
||||||
fprintf(stderr, "pthread_key_create failed");
|
fprintf(stderr, "pthread_key_create failed");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user