2 * The UCW Library -- Transactions
4 * (c) 2008 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;
27 void trans_init(void); // Called automatically on trans_open() if needed
28 void trans_cleanup(void); // Free memory occupied by the transaction system pools
30 struct trans *trans_open_rp(struct respool *rp);
31 static inline struct trans *trans_open(void)
33 return trans_open_rp(NULL);
35 struct trans *trans_get_current(void);
36 void trans_commit(void);
37 void trans_rollback(void);
38 void trans_dump(void);
40 struct mempool *trans_get_pool(void);
41 struct mempool *trans_get_exc_pool(void);
46 const char *id; // Hierarchic identifier of the exception
47 const char *msg; // Error message to present to the user
48 void *object; // Object on which the exception happened
49 struct trans *trans; // Transaction in which it happened (set by trans_throw*)
50 // More data specific for the particular `id' can follow
53 void trans_throw_exc(struct exception *x) NONRET;
54 void trans_throw(const char *id, void *object, const char *fmt, ...) FORMAT_CHECK(printf,3,4) NONRET;
55 void trans_vthrow(const char *id, void *object, const char *fmt, va_list args) NONRET;
57 struct exception *trans_current_exc(void);
59 #define TRANS_TRY do { \
60 struct trans *_t = trans_open(); \
61 if (!setjmp(_t->jmp)) \
64 #define TRANS_CATCH(x) \
69 struct exception *x UNUSED = trans_current_exc();