Removing traces of lock-free experiments..
[beacon-ss.git] / main.cpp
blob0a1f69fc623b6c996b294a859d61c61db0e9d5a8
2 #ifdef HAVE_CONFIG_H
3 #include <config.h>
4 #endif
6 #include <iostream>
7 #include <beacon/event_loop.hpp>
8 #include <boost/bind.hpp>
9 #include <beacon/reference_countable.hpp>
11 using namespace std;
12 using namespace beacon;
14 unsigned times_called = 0;
15 class inv : public invokable {
16 public:
18 inv() : invokable(0) {
21 void invoke() {
22 times_called++;
25 bool operator==(invokable const & other) {
26 return this == &other;
30 void function() {
31 times_called++;
34 int main(int argc, char * argv[]) {
36 event_loop el;
38 el.start();
40 inv in;
42 //fast
43 boost::function<void()> fn = invoke_with_no_future<void()>(el, &function, (void const *)(&function));
45 //slow - approx. 5x slower
46 //boost::function<beacon::future<void> *()> fn = invoke_with_future_pointer<void()>(el, &function, (void const *)(&function));
48 //slow as well - no leaks
49 //boost::function<beacon::scoped_future<void> ()> fn = invoke_with_future_object<void()>(el, &function, (void const *)(&function));
51 boost::xtime start, end, now;
52 boost::xtime_get(&start, boost::TIME_UTC);
54 for(int i = 0; i < 1000000; i++) {
55 //el.enqueue(new inv);
56 fn(); //this leaks when used with future pointer
57 //beacon::scoped_future<void> res(fn()); //this wraps the future pointer so that it doesn't leak
60 boost::xtime_get(&now, boost::TIME_UTC);
61 now.nsec += 1000;
62 boost::thread::sleep(now);
64 cout << "dequing ";
65 cout << el.dequeue((void const *)(&function)) << " calls" << endl;
67 el.join();
69 boost::xtime_get(&end, boost::TIME_UTC);
71 double diff = end.sec - start.sec + (end.nsec - start.nsec) / 1e9;
73 cout << "time: " << diff << std::endl;
74 cout << "times called: " << times_called << endl;
75 return EXIT_SUCCESS;