diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2019-05-27 10:19:43 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2019-05-27 10:19:43 +0200 |
commit | a2f5c26a8ac422e9318733fc4d30cef9eb96b3cb (patch) | |
tree | 5f36264b0e229c55a72843531f32fdf35687b149 /src/app/transactiontest/main.cc | |
parent | 6e43e8e9a59569b573628c84d68af26f284c8c4e (diff) |
Add transaction object with retry/abort functions
Diffstat (limited to 'src/app/transactiontest/main.cc')
-rw-r--r-- | src/app/transactiontest/main.cc | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/src/app/transactiontest/main.cc b/src/app/transactiontest/main.cc index e359e67..cb2d86e 100644 --- a/src/app/transactiontest/main.cc +++ b/src/app/transactiontest/main.cc @@ -8,37 +8,31 @@ #endif extern "C" { - void asm_save_toc(); - void asm_load_toc(); + void asm_save_all(); + void asm_load_all(); + void asm_load_mem(); } -volatile bool __attribute__((section(".text"))) have_state = false; uint16_t i = 0; -void restore_state() -{ - if (!have_state) { - return; - } - asm_load_toc(); -} - -void save_state() -{ - asm_save_toc(); - have_state = true; -} +class Transaction { + public: + inline Transaction() { asm_save_all(); } + inline ~Transaction() {} + inline void retry() { asm_load_all(); } + inline void abort() { asm_load_mem(); } +}; void loop(void) { gpio.led_toggle(1); - kout << dec << i << endl; - i++; - if (i == 5) { - save_state(); - } - if (i == 10) { - restore_state(); + { + Transaction tx; + kout << dec << i << endl; + i++; + if (!gpio.read(GPIO::p4_5)) { + tx.abort(); + } } } @@ -48,15 +42,11 @@ int main(void) gpio.setup(); kout.setup(); - restore_state(); + //restore_state(); gpio.led_on(0); + gpio.input(GPIO::p4_5, 1); kout << "Hello, World!" << endl; - kout << "Test, World!" << endl; - kout << dec << uptime.get_cycles() << endl; - kout << dec << uptime.get_cycles() << endl; - kout << dec << uptime.get_cycles() << endl; - kout << dec << uptime.get_cycles() << endl; arch.idle_loop(); |