diff --git a/src/apps/eric/Makefile b/src/apps/eric/Makefile new file mode 100644 index 0000000..01308f8 --- /dev/null +++ b/src/apps/eric/Makefile @@ -0,0 +1,5 @@ + +test: test.c + gcc -g -O2 -I ../../.. test.c -o test ../../../src/lladd/liblladd.a ../../../src/libdfa/librw.a -lc -lpthread -lm -lcheck + + diff --git a/src/apps/eric/test.c b/src/apps/eric/test.c new file mode 100644 index 0000000..f3580cf --- /dev/null +++ b/src/apps/eric/test.c @@ -0,0 +1,51 @@ +#include +#include +#include + +/* + Basic first program + + Transactionally stores one integer, which is the version number of the store. + New store gets version 1. Each rerun increments the version number. + If you delete logfile.txt and storefile.txt, it recreates them at version 1. +*/ + +int main(const int argc, const char **argv) { + int version = 1; + + Tinit(); + printf("Initialized\n"); + + // create/load the store + recordid rootEntry; + + int xid = Tbegin(); + if (TrecordType(xid, ROOT_RECORD) == UNINITIALIZED_RECORD) { + // new store, must create empty page + printf("Creating new store\n"); + rootEntry = Talloc(xid, sizeof(int)); + + assert(ROOT_RECORD.page == rootEntry.page); + assert(ROOT_RECORD.slot == rootEntry.slot); + + Tset(xid, rootEntry, &version); + Tcommit(xid); + } else { + // store is valid + printf("Reusing existing store\n"); + rootEntry = ROOT_RECORD; + rootEntry.size = sizeof(int); + + Tread(xid, rootEntry, &version); + version++; + printf("read valid\n"); + Tset(xid, rootEntry, &version); + Tcommit(xid); + } + printf("Version %d\n", version); + + // wrap up + + Tdeinit(); + return 0; +}