github.com/peggyl/go@v0.0.0-20151008231540-ae315999c2d5/src/runtime/cgo/gcc_libinit.c (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build darwin dragonfly freebsd linux netbsd solaris 6 // +build !ppc64,!ppc64le 7 8 #include <pthread.h> 9 #include <stdio.h> 10 #include <stdlib.h> 11 #include <string.h> // strerror 12 13 static pthread_cond_t runtime_init_cond = PTHREAD_COND_INITIALIZER; 14 static pthread_mutex_t runtime_init_mu = PTHREAD_MUTEX_INITIALIZER; 15 static int runtime_init_done; 16 17 void 18 x_cgo_sys_thread_create(void* (*func)(void*), void* arg) { 19 pthread_t p; 20 int err = pthread_create(&p, NULL, func, arg); 21 if (err != 0) { 22 fprintf(stderr, "pthread_create failed: %s", strerror(err)); 23 abort(); 24 } 25 } 26 27 void 28 _cgo_wait_runtime_init_done() { 29 pthread_mutex_lock(&runtime_init_mu); 30 while (runtime_init_done == 0) { 31 pthread_cond_wait(&runtime_init_cond, &runtime_init_mu); 32 } 33 pthread_mutex_unlock(&runtime_init_mu); 34 } 35 36 void 37 x_cgo_notify_runtime_init_done(void* dummy) { 38 pthread_mutex_lock(&runtime_init_mu); 39 runtime_init_done = 1; 40 pthread_cond_broadcast(&runtime_init_cond); 41 pthread_mutex_unlock(&runtime_init_mu); 42 }