2 * The UCW Library -- Transactions
4 * (c) 2008--2011 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
13 #include "ucw/mempool.h"
20 struct trans *prev_trans;
21 struct mempool_state *trans_pool_state;
22 struct respool *rpool;
23 struct respool *prev_rpool;
24 struct exception *thrown_exc;
28 void trans_init(void); // Called automatically on trans_open() if needed
29 void trans_cleanup(void); // Free memory occupied by the transaction system pools
31 struct trans *trans_open(void);
32 struct trans *trans_get_current(void);
33 void trans_commit(void);
34 void trans_rollback(void);
35 void trans_fold(void);
36 void trans_dump(void);
38 struct mempool *trans_get_pool(void);
43 const char *id; // Hierarchic identifier of the exception
44 const char *msg; // Error message to present to the user
45 void *object; // Object on which the exception happened
46 // More data specific for the particular `id' can follow
49 void trans_throw_exc(struct exception *x) NONRET;
50 void trans_throw(const char *id, void *object, const char *fmt, ...) FORMAT_CHECK(printf,3,4) NONRET;
51 void trans_vthrow(const char *id, void *object, const char *fmt, va_list args) NONRET;
52 void trans_caught(void);
54 struct exception *trans_current_exc(void);
56 #define TRANS_TRY do { \
57 struct trans *_t = trans_open(); \
58 if (!setjmp(_t->jmp)) \
61 #define TRANS_CATCH(x) \
66 struct exception *x UNUSED = trans_current_exc();