source:
doc/theses/andrew_beach_MMath/code/resume-detor.cfa@
d874f59
| Last change on this file since d874f59 was 54651005, checked in by , 4 years ago | |
|---|---|
|
|
| File size: 987 bytes | |
| Rev | Line | |
|---|---|---|
| [ea593a3] | 1 | // Throw Across Destructor |
| [ee23a8d] | 2 | #include <clock.hfa> |
| [ea593a3] | 3 | #include <exception.hfa> |
| [ee23a8d] | 4 | #include <fstream.hfa> |
| [ea593a3] | 5 | #include <stdlib.hfa> |
| 6 | ||
| 7 | EHM_EXCEPTION(empty_exception)(); | |
| 8 | ||
| 9 | EHM_VIRTUAL_TABLE(empty_exception, empty_vt); | |
| 10 | ||
| 11 | struct WithDestructor {}; | |
| 12 | ||
| 13 | void ^?{}(WithDestructor & this) { | |
| [54651005] | 14 | asm volatile ("# destructor body"); |
| [ea593a3] | 15 | } |
| 16 | ||
| 17 | void unwind_destructor(unsigned int frames) { | |
| [54651005] | 18 | if (frames) { |
| [ea593a3] | 19 | |
| [54651005] | 20 | WithDestructor object; |
| 21 | unwind_destructor(frames - 1); | |
| 22 | } else { | |
| 23 | throwResume (empty_exception){&empty_vt}; | |
| 24 | } | |
| [ea593a3] | 25 | } |
| 26 | ||
| 27 | int main(int argc, char * argv[]) { | |
| 28 | unsigned int times = 1; | |
| 29 | unsigned int total_frames = 1; | |
| [ee23a8d] | 30 | if (1 < argc) { |
| [ea593a3] | 31 | times = strtol(argv[1], 0p, 10); |
| 32 | } | |
| [ee23a8d] | 33 | if (2 < argc) { |
| [ea593a3] | 34 | total_frames = strtol(argv[2], 0p, 10); |
| 35 | } | |
| 36 | ||
| [ee23a8d] | 37 | Time start_time = timeHiRes(); |
| [54651005] | 38 | for (int count = 0 ; count < times ; ++count) { |
| 39 | try { | |
| 40 | unwind_destructor(total_frames); | |
| 41 | } catchResume (empty_exception *) { | |
| 42 | asm volatile ("# fixup block"); | |
| 43 | } | |
| 44 | } | |
| [ee23a8d] | 45 | Time end_time = timeHiRes(); |
| 46 | sout | "Run-Time (ns): " | (end_time - start_time)`ns; | |
| [ea593a3] | 47 | } |
Note:
See TracBrowser
for help on using the repository browser.