the 'static int' is global for the program, so tsd_init can be used to check
if we should init the thread local storage. Then use YK_TSD_GET to check if we
already got an errno for this thread, if not allocate and set it.
if (tsd_init == 0) {
if ((rc = YK_TSD_INIT(errno_key, free)) == 0) {
- void *p = calloc(1, sizeof(int));
- if (!p) {
- tsd_init = -1;
- } else {
- YK_TSD_SET(errno_key, p);
- tsd_init = 1;
- }
+ tsd_init = 1;
} else {
tsd_init = -1;
}
}
+
+ if(YK_TSD_GET(int *, errno_key) == NULL) {
+ void *p = calloc(1, sizeof(int));
+ if (!p) {
+ tsd_init = -1;
+ } else {
+ YK_TSD_SET(errno_key, p);
+ }
+ }
if (tsd_init == 1) {
return YK_TSD_GET(int *, errno_key);
}
if (tsd_init == 0) {
if ((rc = YK_TSD_INIT(errno_key, free)) == 0) {
- void *p = calloc(1, sizeof(int));
- if (!p) {
- tsd_init = -1;
- } else {
- YK_TSD_SET(errno_key, p);
- tsd_init = 1;
- }
+ tsd_init = 1;
} else {
tsd_init = -1;
}
}
+
+ if(YK_TSD_GET(int *, errno_key) == NULL) {
+ void *p = calloc(1, sizeof(int));
+ if (!p) {
+ tsd_init = -1;
+ } else {
+ YK_TSD_SET(errno_key, p);
+ }
+ }
if (tsd_init == 1) {
return YK_TSD_GET(int *, errno_key);
}