From d8c423da72506f8688a609c2a3bd9caf5f5bd93a Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 30 Aug 2008 19:24:59 +0200 Subject: [PATCH] First bones of the transaction system's skeleton. --- ucw/Makefile | 6 +++-- ucw/trans.h | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 ucw/trans.h diff --git a/ucw/Makefile b/ucw/Makefile index 174e51b2..f7835977 100644 --- a/ucw/Makefile +++ b/ucw/Makefile @@ -33,7 +33,8 @@ LIBUCW_MODS= \ string str-esc str-split str-match str-imatch str-hex \ bbuf gary \ getopt \ - strtonum + strtonum \ + trans LIBUCW_MAIN_INCLUDES= \ lib.h log.h threads.h \ @@ -59,7 +60,8 @@ LIBUCW_MAIN_INCLUDES= \ qache.h \ kmp.h kmp-search.h binsearch.h \ partmap.h \ - strtonum.h + strtonum.h \ + trans.h ifdef CONFIG_UCW_THREADS # Some modules require threading diff --git a/ucw/trans.h b/ucw/trans.h new file mode 100644 index 00000000..7ba8e6ff --- /dev/null +++ b/ucw/trans.h @@ -0,0 +1,75 @@ +/* + * The UCW Library -- Transactions + * + * (c) 2008 Martin Mares + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. + */ + +#ifndef _UCW_TRANS_H +#define _UCW_TRANS_H + +#include "ucw/clists.h" +#include "ucw/mempool.h" + +#include + +/* Resource pools */ + +struct respool { + clist resources; + struct mempool *mp; // If set, resources are allocated from the mempool, otherwise by xmalloc() +}; + +struct resource { + cnode n; + struct res_class *rclass; + void *priv; // Private to the class +}; + +struct res_class { + const char *name; + void (*undo)(struct res *t); + void (*dump)(struct res *t); +}; + +struct respool *rp_new(void); +void rp_delete(struct respool *rp); +void rp_dump(struct respool *rp); + +struct resource *res_alloc(struct respool *rp); +void res_fix(struct resource *r); +void res_undo(struct resource *r); +void res_dump(struct resource *r); + +static inline struct resource * +res_new(struct respool *rp, struct res_class *rc, void *priv) +{ + struct resource *r = res_alloc(rp); + r->rclass = rc; + r->priv = priv; + return r; +} + +/* Transactions */ + +struct trans { + struct trans *prev; + struct mempool_state trans_pool_state; + struct respool res_pool; + jmp_buf jmp; +}; + +void trans_init(void); // Called automatically on trans_open() if needed +void trans_cleanup(void); // Free memory occupied by the transaction system pools + +struct trans *trans_open(void); +struct trans *trans_get_current(void); +void trans_commit(void); +void trans_rollback(void); +void trans_dump(void); + +/* Exceptions */ + +#endif -- 2.39.2