github.com/aloncn/graphics-go@v0.0.1/src/runtime/cgo/gcc_android_arm64.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 7 #include <pthread.h> 8 #include <signal.h> 9 #include <stdio.h> 10 #include <sys/limits.h> 11 #include "libcgo.h" 12 13 #define magic1 (0x23581321345589ULL) 14 15 // inittls allocates a thread-local storage slot for g. 16 // 17 // It finds the first available slot using pthread_key_create and uses 18 // it as the offset value for runtime.tlsg. 19 static void 20 inittls(void **tlsg, void **tlsbase) 21 { 22 pthread_key_t k; 23 int i, err; 24 25 err = pthread_key_create(&k, nil); 26 if(err != 0) { 27 fatalf("pthread_key_create failed: %d", err); 28 } 29 pthread_setspecific(k, (void*)magic1); 30 for (i=0; i<PTHREAD_KEYS_MAX; i++) { 31 if (*(tlsbase+i) == (void*)magic1) { 32 *tlsg = (void*)(i*sizeof(void *)); 33 pthread_setspecific(k, 0); 34 return; 35 } 36 } 37 fatalf("could not find pthread key"); 38 } 39 40 void (*x_cgo_inittls)(void **tlsg, void **tlsbase) = inittls;