2005-02-14 02:49:59 +00:00
|
|
|
#include <lladd/compensations.h>
|
2005-02-16 02:13:54 +00:00
|
|
|
|
2005-03-10 03:19:04 +00:00
|
|
|
int ___compensation_count___ = 0;
|
|
|
|
|
2005-02-14 02:49:59 +00:00
|
|
|
#include <assert.h>
|
2005-02-28 00:00:17 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
static pthread_key_t error_key;
|
2005-02-14 02:49:59 +00:00
|
|
|
|
|
|
|
void compensations_init () {
|
|
|
|
int ret = pthread_key_create(&error_key, NULL);
|
|
|
|
assert(!ret);
|
2005-03-10 03:19:04 +00:00
|
|
|
pthread_setspecific(error_key, NULL);
|
2005-02-14 02:49:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void compensations_deinit() {
|
2005-02-28 00:00:17 +00:00
|
|
|
int ret = pthread_key_delete(error_key);
|
|
|
|
assert(!ret);
|
2005-02-14 02:49:59 +00:00
|
|
|
}
|
|
|
|
|
2006-03-20 23:11:46 +00:00
|
|
|
long compensation_error() {
|
|
|
|
long error = (long) pthread_getspecific(error_key);
|
2005-02-14 02:49:59 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void compensation_clear_error() {
|
|
|
|
compensation_set_error(0);
|
|
|
|
}
|
|
|
|
|
2006-03-20 23:11:46 +00:00
|
|
|
void compensation_set_error(long error) {
|
2005-02-28 00:00:17 +00:00
|
|
|
int ret = pthread_setspecific(error_key, (void *)error);
|
|
|
|
if(ret) {
|
|
|
|
printf("Unhandled error: %s\n", strerror(ret));
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
assert(!ret);
|
2005-02-14 02:49:59 +00:00
|
|
|
}
|