|
|
@@ -21,24 +21,22 @@
|
|
|
*
|
|
|
* @section DESCRIPTION
|
|
|
*
|
|
|
- * Mechanism for ensuring an object is destroyed from inside an error handler.
|
|
|
+ * Mechanism for ensuring an object is destroyed from inside an error handler
|
|
|
+ * or its jobs.
|
|
|
*/
|
|
|
|
|
|
#ifndef BADVPN_MISC_DEBUGERROR_H
|
|
|
#define BADVPN_MISC_DEBUGERROR_H
|
|
|
|
|
|
-#include <misc/dead.h>
|
|
|
#include <misc/debug.h>
|
|
|
+#include <system/BPending.h>
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
#define DEBUGERROR(de, call) \
|
|
|
{ \
|
|
|
- ASSERT(!(de)->error) \
|
|
|
- (de)->error = 1; \
|
|
|
- DEAD_ENTER((de)->dead) \
|
|
|
+ ASSERT(!BPending_IsSet(&(de)->job)) \
|
|
|
+ BPending_Set(&(de)->job); \
|
|
|
(call); \
|
|
|
- ASSERT(DEAD_KILLED) \
|
|
|
- DEAD_LEAVE((de)->dead); \
|
|
|
}
|
|
|
#else
|
|
|
#define DEBUGERROR(de, call) { (call); }
|
|
|
@@ -46,34 +44,39 @@
|
|
|
|
|
|
typedef struct {
|
|
|
#ifndef NDEBUG
|
|
|
- dead_t dead;
|
|
|
- int error;
|
|
|
+ BPending job;
|
|
|
#endif
|
|
|
} DebugError;
|
|
|
|
|
|
-static void DebugError_Init (DebugError *o);
|
|
|
+static void DebugError_Init (DebugError *o, BPendingGroup *pg);
|
|
|
static void DebugError_Free (DebugError *o);
|
|
|
static void DebugError_AssertNoError (DebugError *o);
|
|
|
|
|
|
-void DebugError_Init (DebugError *o)
|
|
|
+#ifndef NDEBUG
|
|
|
+static void _DebugError_job_handler (DebugError *o)
|
|
|
+{
|
|
|
+ ASSERT(0);
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
+void DebugError_Init (DebugError *o, BPendingGroup *pg)
|
|
|
{
|
|
|
#ifndef NDEBUG
|
|
|
- DEAD_INIT(o->dead);
|
|
|
- o->error = 0;
|
|
|
+ BPending_Init(&o->job, pg, (BPending_handler)_DebugError_job_handler, o);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
void DebugError_Free (DebugError *o)
|
|
|
{
|
|
|
#ifndef NDEBUG
|
|
|
- DEAD_KILL(o->dead);
|
|
|
+ BPending_Free(&o->job);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
void DebugError_AssertNoError (DebugError *o)
|
|
|
{
|
|
|
#ifndef NDEBUG
|
|
|
- ASSERT(!o->error)
|
|
|
+ ASSERT(!BPending_IsSet(&o->job))
|
|
|
#endif
|
|
|
}
|
|
|
|