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/trans.h"
14 #include "ucw/respool.h"
15 #include "ucw/mempool.h"
22 struct ucwlib_context *c = ucwlib_thread_context();
24 c->trans_pool = mp_new(1024);
30 struct ucwlib_context *c = ucwlib_thread_context();
33 mp_delete(c->trans_pool);
36 c->current_trans = NULL;
40 trans_open_rp(struct respool *rp)
43 struct ucwlib_context *c = ucwlib_thread_context();
44 struct mempool *mp = c->trans_pool;
46 struct mempool_state *mst = mp_push(mp);
47 struct trans *t = mp_alloc(mp, sizeof(*t));
48 t->trans_pool_state = mst;
51 rp = rp_new("trans", mp);
53 t->prev_rpool = rp_switch(rp);
55 t->prev_trans = c->current_trans;
57 DBG("Opened transaction %p", t);
62 trans_get_current(void)
64 return ucwlib_thread_context() -> current_trans;
68 trans_close(struct trans *t)
70 struct ucwlib_context *c = ucwlib_thread_context();
71 rp_switch(t->prev_rpool);
72 c->current_trans = t->prev_trans;
73 mp_restore(c->trans_pool, t->trans_pool_state);
79 struct trans *t = trans_get_current();
80 DBG("Commiting transaction %p", t);
89 struct trans *t = trans_get_current();
90 DBG("Rolling back transaction %p", t);
99 struct trans *t = trans_get_current();
102 puts("No transaction open.");
107 printf("Transaction %p:\n", t);
118 res_malloc(64, NULL);