From b232a4f9f05af1e56efd6fb48904851152449d98 Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Mon, 11 Jan 2010 22:40:53 +0100 Subject: [PATCH] errors for locking * add a 'unknown' error to the error system as fallback * lockerror.c|h define all errors which can happen due locking * lumiera_lockerror_set() translates posix errors to lumiera errors * remove stale errors from sectionlock.h --- src/lib/Makefile.am | 4 ++- src/lib/error.c | 1 + src/lib/error.h | 1 + src/lib/lockerror.c | 79 +++++++++++++++++++++++++++++++++++++++++++ src/lib/lockerror.h | 53 +++++++++++++++++++++++++++++ src/lib/sectionlock.h | 6 ---- 6 files changed, 137 insertions(+), 7 deletions(-) create mode 100644 src/lib/lockerror.c create mode 100644 src/lib/lockerror.h diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index b6f89847b..4ec446ac3 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -19,12 +19,13 @@ liblumiera_la_srcdir = $(top_srcdir)/src/lib lib_LTLIBRARIES += liblumiera.la liblumiera_la_CFLAGS = $(AM_CFLAGS) -std=gnu99 -Wall -Wextra -Werror -liblumiera_la_CXXFLAGS = $(AM_CXXFLAGS) -Wall -Wextra +liblumiera_la_CXXFLAGS = $(AM_CXXFLAGS) -Wall -Wextra -Werror liblumiera_la_SOURCES = \ $(liblumiera_la_srcdir)/error.c \ $(liblumiera_la_srcdir)/mpool.c \ $(liblumiera_la_srcdir)/exception.cpp \ + $(liblumiera_la_srcdir)/lockerror.c \ $(liblumiera_la_srcdir)/mutex.c \ $(liblumiera_la_srcdir)/recmutex.c \ $(liblumiera_la_srcdir)/rwlock.c \ @@ -54,6 +55,7 @@ noinst_HEADERS += \ $(liblumiera_la_srcdir)/error.h \ $(liblumiera_la_srcdir)/error.hpp \ $(liblumiera_la_srcdir)/mpool.h \ + $(liblumiera_la_srcdir)/lockerror.h \ $(liblumiera_la_srcdir)/mutex.h \ $(liblumiera_la_srcdir)/recmutex.h \ $(liblumiera_la_srcdir)/rwlock.h \ diff --git a/src/lib/error.c b/src/lib/error.c index caf2cf81b..840288c8d 100644 --- a/src/lib/error.c +++ b/src/lib/error.c @@ -34,6 +34,7 @@ */ LUMIERA_ERROR_DEFINE (ERRNO, "errno"); LUMIERA_ERROR_DEFINE (EERROR, "could not initialize error system"); +LUMIERA_ERROR_DEFINE (UNKNOWN, "unknown error"); /* Thread local storage */ diff --git a/src/lib/error.h b/src/lib/error.h index 100ad7c7b..308adf480 100644 --- a/src/lib/error.h +++ b/src/lib/error.h @@ -164,6 +164,7 @@ lumiera_error_peek (void); predefined errors */ LUMIERA_ERROR_DECLARE (ERRNO); +LUMIERA_ERROR_DECLARE (UNKNOWN); #ifdef __cplusplus } /* extern "C" */ diff --git a/src/lib/lockerror.c b/src/lib/lockerror.c new file mode 100644 index 000000000..6c53b8fbb --- /dev/null +++ b/src/lib/lockerror.c @@ -0,0 +1,79 @@ +/* + lockerror.c - error declarations for all locks (mutex, rwlocks, cond vars) + + Copyright (C) Lumiera.org + 2010, Christian Thaeter + + 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 "lib/lockerror.h" + +#include + +/* fatal errors (EINVAL usually) */ +LUMIERA_ERROR_DEFINE (LOCK_ACQUIRE, "locking failed"); +LUMIERA_ERROR_DEFINE (LOCK_RELEASE, "unlocking failed"); +LUMIERA_ERROR_DEFINE (LOCK_DESTROY, "lock destroy failed"); + +/* runtime errors */ +LUMIERA_ERROR_DEFINE (LOCK_INVAL, "lock initialization error"); +LUMIERA_ERROR_DEFINE (LOCK_BUSY, "already locked"); +LUMIERA_ERROR_DEFINE (LOCK_DEADLK, "already locked by this thread"); +LUMIERA_ERROR_DEFINE (LOCK_PERM, "not locked by this thread"); +LUMIERA_ERROR_DEFINE (LOCK_TIMEOUT, "timeout"); +LUMIERA_ERROR_DEFINE (LOCK_AGAIN, "too much recursive locks"); + + + +void +lumiera_lockerror_set (int err, struct nobug_flag* flag, const char* extra) +{ + switch (err) + { + case 0: + break; + case EINVAL: + LUMIERA_ERROR_SET_ALERT(NOBUG_FLAG_RAW(flag), LOCK_INVAL, extra); + break; + case EBUSY: + LUMIERA_ERROR_SET(NOBUG_FLAG_RAW(flag), LOCK_BUSY, extra); + break; + case EDEADLK: + LUMIERA_ERROR_SET(NOBUG_FLAG_RAW(flag), LOCK_DEADLK, extra); + break; + case EPERM: + LUMIERA_ERROR_SET_ALERT(NOBUG_FLAG_RAW(flag), LOCK_PERM, extra); + break; + case ETIMEDOUT: + LUMIERA_ERROR_SET(NOBUG_FLAG_RAW(flag), LOCK_TIMEOUT, extra); + break; + case EAGAIN: + LUMIERA_ERROR_SET_WARNING(NOBUG_FLAG_RAW(flag), LOCK_AGAIN, extra); + break; + default: + LUMIERA_ERROR_SET_CRITICAL(NOBUG_FLAG_RAW(flag), UNKNOWN, extra); + break; + } +} + + +/* +// Local Variables: +// mode: C +// c-file-style: "gnu" +// indent-tabs-mode: nil +// End: +*/ diff --git a/src/lib/lockerror.h b/src/lib/lockerror.h new file mode 100644 index 000000000..4916d8a57 --- /dev/null +++ b/src/lib/lockerror.h @@ -0,0 +1,53 @@ +/* + lockerror.h - error declarations for all locks (mutex, rwlocks, cond vars) + + Copyright (C) Lumiera.org + 2010, Christian Thaeter + + 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. +*/ + +#ifndef LUMIERA_LOCKERRORS_H +#define LUMIERA_LOCKERRORS_H + +#include "lib/error.h" + +/* fatal errors (EINVAL usually), we DIE on these, shall never ever happen on a correct program */ +LUMIERA_ERROR_DECLARE (LOCK_ACQUIRE); +LUMIERA_ERROR_DECLARE (LOCK_RELEASE); +LUMIERA_ERROR_DECLARE (LOCK_DESTROY); + +/* runtime errors */ +LUMIERA_ERROR_DECLARE (LOCK_INVAL); +LUMIERA_ERROR_DECLARE (LOCK_BUSY); +LUMIERA_ERROR_DECLARE (LOCK_DEADLK); +LUMIERA_ERROR_DECLARE (LOCK_PERM); +LUMIERA_ERROR_DECLARE (LOCK_TIMEOUT); +LUMIERA_ERROR_DECLARE (LOCK_AGAIN); + +/** + * Translate pthread error code into lumiera error + */ +void +lumiera_lockerror_set (int err, struct nobug_flag* flag, const char* extra); + +#endif +/* +// Local Variables: +// mode: C +// c-file-style: "gnu" +// indent-tabs-mode: nil +// End: +*/ diff --git a/src/lib/sectionlock.h b/src/lib/sectionlock.h index 42e719de7..808484007 100644 --- a/src/lib/sectionlock.h +++ b/src/lib/sectionlock.h @@ -22,15 +22,9 @@ #ifndef LUMIERA_SECTIONLOCK_H #define LUMIERA_SECTIONLOCK_H -#include "lib/error.h" - #include #include -LUMIERA_ERROR_DECLARE (LOCK_ACQUIRE); -LUMIERA_ERROR_DECLARE (LOCK_RELEASE); -LUMIERA_ERROR_DECLARE (LOCK_DESTROY); - typedef int (*lumiera_sectionlock_unlock_fn)(void*);