| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 #include <android/log.h> | |
| 6 #include <pthread.h> | |
| 7 #include <signal.h> | |
| 8 #include <stdio.h> | |
| 9 #include "libcgo.h" | |
| 10 | |
| 11 #define magic1 (0x23581321U) | |
| 12 | |
| 13 // inittls finds the first available pthread slot and uses it as | |
|
minux
2014/07/02 04:21:15
s/pthread slot/thread-local storage slot/
see pkg
crawshaw
2014/07/02 14:57:22
Done.
| |
| 14 // the offset value for runtime.tlsg. | |
| 15 static void | |
| 16 inittls(void **tlsg, void **tlsbase) | |
| 17 { | |
| 18 pthread_key_t k; | |
| 19 int i, err; | |
| 20 | |
| 21 err = pthread_key_create(&k, nil); | |
| 22 if(err != 0) { | |
| 23 fprintf(stderr, "runtime/cgo: pthread_key_create failed: %d\n", err); | |
| 24 __android_log_print(ANDROID_LOG_FATAL, "runtime/cgo", "pthread_k ey_create failed: %d", err); | |
| 25 abort(); | |
| 26 } | |
| 27 pthread_setspecific(k, (void*)magic1); | |
| 28 for (i=0; i<50; i++) { | |
|
minux
2014/07/02 04:21:15
probably 50 is too small? darwin/386 tries 128 slo
crawshaw
2014/07/02 14:57:22
I'm not comfortable assuming that pthread_getspeci
minux
2014/07/02 17:16:53
ok.
| |
| 29 if (*(tlsbase+i) == (void*)magic1) { | |
| 30 *tlsg = (void*)(i*sizeof(void *)); | |
| 31 pthread_setspecific(k, 0); | |
| 32 return; | |
| 33 } | |
| 34 } | |
| 35 fprintf(stderr, "runtime/cgo: could not find pthread key\n"); | |
| 36 __android_log_print(ANDROID_LOG_FATAL, "runtime/cgo", "could not find pt hread key"); | |
| 37 abort(); | |
| 38 } | |
| 39 | |
| 40 extern void (*x_cgo_inittls)(void **tlsg, void **tlsbase); | |
| 41 void (*x_cgo_inittls)(void **tlsg, void **tlsbase) = inittls; | |
|
minux
2014/07/02 04:21:15
i think you can remove the extern declaration here
crawshaw
2014/07/02 14:57:22
Done.
| |
| OLD | NEW |