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
This commit is contained in:
parent
f1efdc06e3
commit
b232a4f9f0
6 changed files with 137 additions and 7 deletions
|
|
@ -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 \
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -164,6 +164,7 @@ lumiera_error_peek (void);
|
|||
predefined errors
|
||||
*/
|
||||
LUMIERA_ERROR_DECLARE (ERRNO);
|
||||
LUMIERA_ERROR_DECLARE (UNKNOWN);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
|
|
|||
79
src/lib/lockerror.c
Normal file
79
src/lib/lockerror.c
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
lockerror.c - error declarations for all locks (mutex, rwlocks, cond vars)
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2010, 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 "lib/lockerror.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/* 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:
|
||||
*/
|
||||
53
src/lib/lockerror.h
Normal file
53
src/lib/lockerror.h
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
lockerror.h - error declarations for all locks (mutex, rwlocks, cond vars)
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2010, 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.
|
||||
*/
|
||||
|
||||
#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:
|
||||
*/
|
||||
|
|
@ -22,15 +22,9 @@
|
|||
#ifndef LUMIERA_SECTIONLOCK_H
|
||||
#define LUMIERA_SECTIONLOCK_H
|
||||
|
||||
#include "lib/error.h"
|
||||
|
||||
#include <pthread.h>
|
||||
#include <nobug.h>
|
||||
|
||||
LUMIERA_ERROR_DECLARE (LOCK_ACQUIRE);
|
||||
LUMIERA_ERROR_DECLARE (LOCK_RELEASE);
|
||||
LUMIERA_ERROR_DECLARE (LOCK_DESTROY);
|
||||
|
||||
|
||||
typedef int (*lumiera_sectionlock_unlock_fn)(void*);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue