| 1 |
// Copyright 2013 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 <stddef.h> |
| 6 |
|
| 7 |
#if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__) |
| 8 |
|
| 9 |
// Mingw seems not to have threads.h, so we use the _Thread_local keyword rather |
| 10 |
// than the thread_local macro. |
| 11 |
static _Thread_local int tls; |
| 12 |
|
| 13 |
const char * |
| 14 |
checkTLS() { |
| 15 |
return NULL; |
| 16 |
} |
| 17 |
|
| 18 |
void |
| 19 |
setTLS(int v) |
| 20 |
{ |
| 21 |
tls = v; |
| 22 |
} |
| 23 |
|
| 24 |
int |
| 25 |
getTLS() |
| 26 |
{ |
| 27 |
return tls; |
| 28 |
} |
| 29 |
|
| 30 |
#else |
| 31 |
|
| 32 |
const char * |
| 33 |
checkTLS() { |
| 34 |
return "_Thread_local requires C11 and not __STDC_NO_THREADS__"; |
| 35 |
} |
| 36 |
|
| 37 |
void |
| 38 |
setTLS(int v) { |
| 39 |
} |
| 40 |
|
| 41 |
int |
| 42 |
getTLS() |
| 43 |
{ |
| 44 |
return 0; |
| 45 |
} |
| 46 |
|
| 47 |
#endif |