Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
lockerror.c
Go to the documentation of this file.
1/*
2 lockerror.c - error declarations for all locks (mutex, rwlocks, cond vars)
3
4 Copyright (C)
5 2010, Christian Thaeter <ct@pipapo.org>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
14
20#include "lib/lockerror.h"
21
22#include <errno.h>
23
24/* fatal errors (EINVAL usually) */
25LUMIERA_ERROR_DEFINE (LOCK_ACQUIRE, "locking failed");
26LUMIERA_ERROR_DEFINE (LOCK_RELEASE, "unlocking failed");
27LUMIERA_ERROR_DEFINE (LOCK_DESTROY, "lock destroy failed");
28
29/* runtime errors */
30LUMIERA_ERROR_DEFINE (LOCK_INVAL, "lock initialisation error");
31LUMIERA_ERROR_DEFINE (LOCK_BUSY, "already locked");
32LUMIERA_ERROR_DEFINE (LOCK_DEADLK, "already locked by this thread");
33LUMIERA_ERROR_DEFINE (LOCK_PERM, "not locked by this thread");
34LUMIERA_ERROR_DEFINE (LOCK_TIMEOUT, "timeout");
35LUMIERA_ERROR_DEFINE (LOCK_AGAIN, "too much recursive locks");
36
37
38
39void
40lumiera_lockerror_set (int err, struct nobug_flag* flag, const struct nobug_context ctx)
41{
42 switch (err)
43 {
44 case 0:
45 break;
46 case ETIMEDOUT:
47 lumiera_error_set(LUMIERA_ERROR_LOCK_TIMEOUT, ctx.func);
48 // no implicit logging, since timeout can be intentional
49 break;
50 case EINVAL:
51 LUMIERA_ERROR_SET_ALERT(NOBUG_FLAG_RAW(flag), LOCK_INVAL, ctx.func);
52 break;
53 case EBUSY:
54 LUMIERA_ERROR_SET(NOBUG_FLAG_RAW(flag), LOCK_BUSY, ctx.func);
55 break;
56 case EDEADLK:
57 LUMIERA_ERROR_SET(NOBUG_FLAG_RAW(flag), LOCK_DEADLK, ctx.func);
58 break;
59 case EPERM:
60 LUMIERA_ERROR_SET_ALERT(NOBUG_FLAG_RAW(flag), LOCK_PERM, ctx.func);
61 break;
62 case EAGAIN:
63 LUMIERA_ERROR_SET_WARNING(NOBUG_FLAG_RAW(flag), LOCK_AGAIN, ctx.func);
64 break;
65 default:
66 LUMIERA_ERROR_SET_CRITICAL(NOBUG_FLAG_RAW(flag), UNKNOWN, ctx.func);
67 break;
68 }
69}
70
71
72/*
73// Local Variables:
74// mode: C
75// c-file-style: "gnu"
76// indent-tabs-mode: nil
77// End:
78*/
lumiera_err lumiera_error_set(lumiera_err nerr, const char *extra)
Set error state for the current thread.
Definition error-state.c:96
#define LUMIERA_ERROR_SET_CRITICAL(flag, err, extra)
Helper macro to raise an error for the current thread.
Definition error.h:112
#define LUMIERA_ERROR_SET_ALERT(flag, err, extra)
Helper macro to raise an error for the current thread.
Definition error.h:97
#define LUMIERA_ERROR_SET(flag, err, extra)
Helper macro to raise an error for the current thread.
Definition error.h:82
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition error.h:71
#define LUMIERA_ERROR_SET_WARNING(flag, err, extra)
Helper macro to raise an error for the current thread.
Definition error.h:127
void lumiera_lockerror_set(int err, struct nobug_flag *flag, const struct nobug_context ctx)
Translate pthread error code into lumiera error.
Definition lockerror.c:40
definitions and declarations for error-handling on low-level locking