File: misc_thread.h

package info (click to toggle)
python-cffi 0.8.6-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 1,444 kB
  • sloc: python: 12,599; ansic: 6,343; asm: 116; makefile: 84; sh: 24
file content (23 lines) | stat: -rw-r--r-- 508 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <pthread.h>

/* This is only included if GCC doesn't support "__thread" global variables.
 * See USE__THREAD in _ffi_backend.c.
 */

static pthread_key_t cffi_tls_key;

static void init_errno(void)
{
    (void) pthread_key_create(&cffi_tls_key, NULL);
}

static void save_errno(void)
{
    intptr_t value = errno;
    (void) pthread_setspecific(cffi_tls_key, (void *)value);
}

static void restore_errno(void) {
    intptr_t value = (intptr_t)pthread_getspecific(cffi_tls_key);
    errno = value;
}