source: doc/theses/andrew_beach_MMath/code/resume-fixup-other-r.cfa @ b041f11

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationpthread-emulationqualifiedEnum
Last change on this file since b041f11 was f79ee0d, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

update exception benchmarks

  • Property mode set to 100644
File size: 1.2 KB
Line 
1// Resume Across Other Handler
2#include <clock.hfa>
3#include <exception.hfa>
4#include <fstream.hfa>
5#include <stdlib.hfa>                                                                   // strto
6
7exception fixup_exception {
8        int & fixup;
9};
10vtable(fixup_exception) fixup_vt;
11exception not_raised_exception {
12        int & fixup;
13};
14
15unsigned int frames;                                                                    // use global because of gcc thunk problem
16
17void nounwind_other(unsigned int dummy) {
18        if (frames) {
19                frames -= 1;
20                try {
21                        nounwind_other(42);
22                } catchResume (not_raised_exception * ex) {
23                        ex->fixup = frames + 42;                                        // use local scope => lexical link
24                }
25        } else {
26                int fixup = dummy;
27                throwResume (fixup_exception){&fixup_vt, fixup}; // change bad fixup
28        }
29}
30
31int main(int argc, char * argv[]) {
32        unsigned int times = 1;
33        unsigned int total_frames = 1;
34        if (1 < argc) {
35                times = strto(argv[1], 0p, 10);
36        }
37        if (2 < argc) {
38                total_frames = strto(argv[2], 0p, 10);
39        }
40        frames = total_frames;
41
42        Time start_time = timeHiRes();
43        for (int count = 0 ; count < times ; ++count) {
44                try {
45                        nounwind_other(42);
46                } catchResume (fixup_exception * ex) {
47                        ex->fixup = total_frames + 42;
48                }
49        }
50        Time end_time = timeHiRes();
51        sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
52}
Note: See TracBrowser for help on using the repository browser.