00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <pthread.h>
00023
00024 #include "lib/error.h"
00025
00032
00033
00034
00035 LUMIERA_ERROR_DEFINE (ERRNO, "errno");
00036
00037
00038
00039 static pthread_key_t lumiera_error_tls;
00040 static pthread_once_t lumiera_error_initialized = PTHREAD_ONCE_INIT;
00041
00042 static void
00043 lumiera_error_tls_init (void)
00044 {
00045 pthread_key_create (&lumiera_error_tls, NULL);
00046 }
00047
00048
00049 lumiera_err
00050 lumiera_error_set (lumiera_err nerr)
00051 {
00052 pthread_once (&lumiera_error_initialized, lumiera_error_tls_init);
00053
00054 lumiera_err err = pthread_getspecific (lumiera_error_tls);
00055 if (!err)
00056 pthread_setspecific (lumiera_error_tls, nerr);
00057
00058 return err;
00059 }
00060
00061
00062 lumiera_err
00063 lumiera_error (void)
00064 {
00065 pthread_once (&lumiera_error_initialized, lumiera_error_tls_init);
00066
00067 lumiera_err err = pthread_getspecific (lumiera_error_tls);
00068 if (err)
00069 pthread_setspecific (lumiera_error_tls, NULL);
00070 return err;
00071 }
00072
00073
00074 lumiera_err
00075 lumiera_error_peek (void)
00076 {
00077 pthread_once (&lumiera_error_initialized, lumiera_error_tls_init);
00078
00079 return pthread_getspecific (lumiera_error_tls);
00080 }