Lumiera  0.pre.03
»edit your freedom«
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) Lumiera.org
5  2010, Christian Thaeter <ct@pipapo.org>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
29 #include "lib/lockerror.h"
30 
31 #include <errno.h>
32 
33 /* fatal errors (EINVAL usually) */
34 LUMIERA_ERROR_DEFINE (LOCK_ACQUIRE, "locking failed");
35 LUMIERA_ERROR_DEFINE (LOCK_RELEASE, "unlocking failed");
36 LUMIERA_ERROR_DEFINE (LOCK_DESTROY, "lock destroy failed");
37 
38 /* runtime errors */
39 LUMIERA_ERROR_DEFINE (LOCK_INVAL, "lock initialisation error");
40 LUMIERA_ERROR_DEFINE (LOCK_BUSY, "already locked");
41 LUMIERA_ERROR_DEFINE (LOCK_DEADLK, "already locked by this thread");
42 LUMIERA_ERROR_DEFINE (LOCK_PERM, "not locked by this thread");
43 LUMIERA_ERROR_DEFINE (LOCK_TIMEOUT, "timeout");
44 LUMIERA_ERROR_DEFINE (LOCK_AGAIN, "too much recursive locks");
45 
46 
47 
48 void
49 lumiera_lockerror_set (int err, struct nobug_flag* flag, const struct nobug_context ctx)
50 {
51  switch (err)
52  {
53  case 0:
54  break;
55  case ETIMEDOUT:
56  lumiera_error_set(LUMIERA_ERROR_LOCK_TIMEOUT, ctx.func);
57  // no implicit logging, since timeout can be intentional
58  break;
59  case EINVAL:
60  LUMIERA_ERROR_SET_ALERT(NOBUG_FLAG_RAW(flag), LOCK_INVAL, ctx.func);
61  break;
62  case EBUSY:
63  LUMIERA_ERROR_SET(NOBUG_FLAG_RAW(flag), LOCK_BUSY, ctx.func);
64  break;
65  case EDEADLK:
66  LUMIERA_ERROR_SET(NOBUG_FLAG_RAW(flag), LOCK_DEADLK, ctx.func);
67  break;
68  case EPERM:
69  LUMIERA_ERROR_SET_ALERT(NOBUG_FLAG_RAW(flag), LOCK_PERM, ctx.func);
70  break;
71  case EAGAIN:
72  LUMIERA_ERROR_SET_WARNING(NOBUG_FLAG_RAW(flag), LOCK_AGAIN, ctx.func);
73  break;
74  default:
75  LUMIERA_ERROR_SET_CRITICAL(NOBUG_FLAG_RAW(flag), UNKNOWN, ctx.func);
76  break;
77  }
78 }
79 
80 
81 /*
82 // Local Variables:
83 // mode: C
84 // c-file-style: "gnu"
85 // indent-tabs-mode: nil
86 // End:
87 */
#define LUMIERA_ERROR_SET(flag, err, extra)
Helper macro to raise an error for the current thread.
Definition: error.h:91
#define LUMIERA_ERROR_SET_WARNING(flag, err, extra)
Helper macro to raise an error for the current thread.
Definition: error.h:136
#define LUMIERA_ERROR_SET_ALERT(flag, err, extra)
Helper macro to raise an error for the current thread.
Definition: error.h:106
definitions and declarations for error-handling on low-level locking
#define LUMIERA_ERROR_SET_CRITICAL(flag, err, extra)
Helper macro to raise an error for the current thread.
Definition: error.h:121
lumiera_err lumiera_error_set(lumiera_err nerr, const char *extra)
Set error state for the current thread.
Definition: error-state.c:105
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:49
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition: error.h:80