github.com/aloncn/graphics-go@v0.0.1/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 cgo 6 // +build darwin dragonfly freebsd linux netbsd solaris 7 // +build !ppc64,!ppc64le 8 9 #include <pthread.h> 10 #include <stdio.h> 11 #include <stdlib.h> 12 #include <string.h> // strerror 13 14 static pthread_cond_t runtime_init_cond = PTHREAD_COND_INITIALIZER; 15 static pthread_mutex_t runtime_init_mu = PTHREAD_MUTEX_INITIALIZER; 16 static int runtime_init_done; 17 18 void 19 x_cgo_sys_thread_create(void* (*func)(void*), void* arg) { 20 pthread_t p; 21 int err = pthread_create(&p, NULL, func, arg); 22 if (err != 0) { 23 fprintf(stderr, "pthread_create failed: %s", strerror(err)); 24 abort(); 25 } 26 } 27 28 void 29 _cgo_wait_runtime_init_done() { 30 pthread_mutex_lock(&runtime_init_mu); 31 while (runtime_init_done == 0) { 32 pthread_cond_wait(&runtime_init_cond, &runtime_init_mu); 33 } 34 pthread_mutex_unlock(&runtime_init_mu); 35 } 36 37 void 38 x_cgo_notify_runtime_init_done(void* dummy) { 39 pthread_mutex_lock(&runtime_init_mu); 40 runtime_init_done = 1; 41 pthread_cond_broadcast(&runtime_init_cond); 42 pthread_mutex_unlock(&runtime_init_mu); 43 }