Commit 51ba2bb8 authored by Hiroshi Ioka's avatar Hiroshi Ioka Committed by Ian Lance Taylor

runtime/cgo: make code robust

According to http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_key_create.html,
pthread_key_create return an error number which is greater than or equal
to 0. I don't know the scenario that pthread_setspecific would fail, but
also don't know the future. Add some error handlings just in case.

Change-Id: I0774b79ef658d67e300f4a9aab1f2e3879acc7ee
Reviewed-on: https://go-review.googlesource.com/54811Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 57bf6aca
......@@ -36,7 +36,7 @@ inittls(void)
*/
ntofree = 0;
for(;;) {
if(pthread_key_create(&k, nil) < 0) {
if(pthread_key_create(&k, nil) != 0) {
fprintf(stderr, "runtime/cgo: pthread_key_create failed\n");
abort();
}
......@@ -77,7 +77,10 @@ threadentry(void *v)
ts = *(ThreadStart*)v;
free(v);
pthread_setspecific(k1, (void*)ts.g);
if (pthread_setspecific(k1, (void*)ts.g) != 0) {
fprintf(stderr, "runtime/cgo: pthread_setspecific failed\n");
abort();
}
crosscall_386(ts.fn);
return nil;
......
......@@ -41,7 +41,7 @@ inittls(void)
*/
ntofree = 0;
for(;;) {
if(pthread_key_create(&k, nil) < 0) {
if(pthread_key_create(&k, nil) != 0) {
fprintf(stderr, "runtime/cgo: pthread_key_create failed\n");
abort();
}
......@@ -82,7 +82,10 @@ threadentry(void *v)
ts = *(ThreadStart*)v;
free(v);
pthread_setspecific(k1, (void*)ts.g);
if (pthread_setspecific(k1, (void*)ts.g) != 0) {
fprintf(stderr, "runtime/cgo: pthread_setspecific failed\n");
abort();
}
crosscall_amd64(ts.fn);
return nil;
......
......@@ -64,7 +64,7 @@ inittls(void)
*/
ntofree = 0;
for(;;) {
if(pthread_key_create(&k, nil) < 0) {
if(pthread_key_create(&k, nil) != 0) {
fprintf(stderr, "runtime/cgo: pthread_key_create failed\n");
abort();
}
......@@ -142,7 +142,10 @@ threadentry(void *v)
ts = *(ThreadStart*)v;
free(v);
pthread_setspecific(k1, (void*)ts.g);
if (pthread_setspecific(k1, (void*)ts.g) != 0) {
fprintf(stderr, "runtime/cgo: pthread_setspecific failed\n");
abort();
}
crosscall_386(ts.fn);
return nil;
......
......@@ -35,7 +35,7 @@ inittls(void)
*/
ntofree = 0;
for(;;) {
if(pthread_key_create(&k, nil) < 0) {
if(pthread_key_create(&k, nil) != 0) {
fprintf(stderr, "runtime/cgo: pthread_key_create failed\n");
abort();
}
......@@ -113,7 +113,10 @@ threadentry(void *v)
ts = *(ThreadStart*)v;
free(v);
pthread_setspecific(k1, (void*)ts.g);
if (pthread_setspecific(k1, (void*)ts.g) != 0) {
fprintf(stderr, "runtime/cgo: pthread_setspecific failed\n");
abort();
}
crosscall_amd64(ts.fn);
return nil;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment