LUMIERA.clone/src/lib/error.c

72 lines
1.7 KiB
C
Raw Normal View History

/*
2008-03-10 06:09:44 +01:00
error.c - Lumiera Error handling
Copyright (C) Lumiera.org
2008, Christian Thaeter <ct@pipapo.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <pthread.h>
#include "lib/error.h"
/**
* @file
* C Error handling in Lumiera.
*/
/*
predefined errors
*/
2008-03-10 06:09:44 +01:00
LUMIERA_ERROR_DEFINE (ERRNO, "errno");
/* Thread local storage */
2008-03-10 06:09:44 +01:00
static pthread_key_t lumiera_error_tls;
static pthread_once_t lumiera_error_initialized = PTHREAD_ONCE_INIT;
static void
2008-03-10 06:09:44 +01:00
lumiera_error_tls_init (void)
{
2008-03-10 06:09:44 +01:00
pthread_key_create (&lumiera_error_tls, NULL);
}
2008-07-20 16:11:08 +02:00
2008-08-06 09:38:33 +02:00
lumiera_err
lumiera_error_set (lumiera_err nerr)
{
2008-03-10 06:09:44 +01:00
pthread_once (&lumiera_error_initialized, lumiera_error_tls_init);
2008-08-06 09:38:33 +02:00
lumiera_err err = pthread_getspecific (lumiera_error_tls);
if (!err)
2008-03-10 06:09:44 +01:00
pthread_setspecific (lumiera_error_tls, nerr);
return err;
}
2008-08-06 09:38:33 +02:00
lumiera_err
2008-03-10 06:09:44 +01:00
lumiera_error ()
{
2008-03-10 06:09:44 +01:00
pthread_once (&lumiera_error_initialized, lumiera_error_tls_init);
2008-08-06 09:38:33 +02:00
lumiera_err err = pthread_getspecific (lumiera_error_tls);
if (err)
2008-03-10 06:09:44 +01:00
pthread_setspecific (lumiera_error_tls, NULL);
return err;
}