1 | #include <actor.hfa> |
---|
2 | #include <fstream.hfa> |
---|
3 | #include <stdlib.hfa> |
---|
4 | #include <string.h> |
---|
5 | #include <stdio.h> |
---|
6 | #include <mutex_stmt.hfa> |
---|
7 | |
---|
8 | struct dummy_actor { actor a; }; // this won't work since the actor isn't inlined |
---|
9 | |
---|
10 | struct derived_actor { |
---|
11 | inline actor; |
---|
12 | int counter; |
---|
13 | }; |
---|
14 | static inline void ?{}( derived_actor & this ) { ((actor &)this){}; this.counter = 0; } |
---|
15 | |
---|
16 | struct d_msg { |
---|
17 | inline message; |
---|
18 | int num; |
---|
19 | }; |
---|
20 | static inline void ?{}( d_msg & this ) { ((message &)this){}; } |
---|
21 | |
---|
22 | // this isn't a valid receive routine since int is not a message type |
---|
23 | Allocation receive( derived_actor & receiver, int i ) with( receiver ) { |
---|
24 | mutex(sout) sout | i; |
---|
25 | counter++; |
---|
26 | if ( counter == 2 ) return Finished; |
---|
27 | return Nodelete; |
---|
28 | } |
---|
29 | |
---|
30 | Allocation receive( derived_actor & receiver, d_msg & msg ) { |
---|
31 | return receive( receiver, msg.num ); |
---|
32 | } |
---|
33 | |
---|
34 | struct derived_actor2 { |
---|
35 | struct nested { int i; }; // testing nested before inline |
---|
36 | inline actor; |
---|
37 | }; |
---|
38 | static inline void ?{}( derived_actor2 & this ) { ((actor &)this){}; } |
---|
39 | |
---|
40 | Allocation receive( derived_actor2 & receiver, d_msg & msg ) { |
---|
41 | mutex(sout) sout | msg.num; |
---|
42 | return Finished; |
---|
43 | } |
---|
44 | |
---|
45 | struct derived_actor3 { |
---|
46 | inline actor; |
---|
47 | }; |
---|
48 | static inline void ?{}( derived_actor3 & this ) { ((actor &)this){}; } |
---|
49 | |
---|
50 | struct d_msg2 { |
---|
51 | inline message; |
---|
52 | int num; |
---|
53 | }; |
---|
54 | static inline void ?{}( d_msg2 & this ) { ((message &)this){}; } |
---|
55 | |
---|
56 | Allocation receive( derived_actor3 & receiver, d_msg & msg ) { |
---|
57 | mutex(sout) sout | msg.num; |
---|
58 | if ( msg.num == -1 ) return Nodelete; |
---|
59 | return Finished; |
---|
60 | } |
---|
61 | |
---|
62 | Allocation receive( derived_actor3 & receiver, d_msg2 & msg ) { |
---|
63 | mutex(sout) sout | msg.num; |
---|
64 | return Finished; |
---|
65 | } |
---|
66 | |
---|
67 | size_t Processors = 3; |
---|
68 | |
---|
69 | int main( int argc, char * argv[] ) { |
---|
70 | printf("start\n"); |
---|
71 | |
---|
72 | processor p[Processors - 1]; |
---|
73 | |
---|
74 | printf("basic test\n"); |
---|
75 | start_actor_system( Processors ); // test passing number of processors |
---|
76 | derived_actor a; |
---|
77 | d_msg b, c; |
---|
78 | b.num = 1; |
---|
79 | c.num = 2; |
---|
80 | a | b | c; |
---|
81 | stop_actor_system(); |
---|
82 | |
---|
83 | printf("same message and different actors test\n"); |
---|
84 | start_actor_system(); // let system detect # of processors |
---|
85 | derived_actor2 d_ac2_0, d_ac2_1; |
---|
86 | d_msg d_ac2_msg; |
---|
87 | d_ac2_msg.num = 3; |
---|
88 | d_ac2_0 | d_ac2_msg; |
---|
89 | d_ac2_1 | d_ac2_msg; |
---|
90 | stop_actor_system(); |
---|
91 | |
---|
92 | |
---|
93 | { |
---|
94 | printf("same message and different actor types test\n"); |
---|
95 | executor e{ 0, Processors, Processors == 1 ? 1 : Processors * 4, false }; |
---|
96 | start_actor_system( e ); // pass an explicit executor |
---|
97 | derived_actor2 d_ac2_2; |
---|
98 | derived_actor3 d_ac3_0; |
---|
99 | d_msg d_ac23_msg; |
---|
100 | d_ac23_msg.num = 4; |
---|
101 | d_ac3_0 | d_ac23_msg; |
---|
102 | d_ac2_2 | d_ac23_msg; |
---|
103 | stop_actor_system(); |
---|
104 | } // RAII to clean up executor |
---|
105 | |
---|
106 | { |
---|
107 | printf("different message types, one actor test\n"); |
---|
108 | executor e{ 1, Processors, Processors == 1 ? 1 : Processors * 4, true }; |
---|
109 | start_actor_system( Processors ); |
---|
110 | derived_actor3 a3; |
---|
111 | d_msg b1; |
---|
112 | d_msg2 c2; |
---|
113 | b1.num = -1; |
---|
114 | c2.num = 5; |
---|
115 | a3 | b1 | c2; |
---|
116 | stop_actor_system(); |
---|
117 | } // RAII to clean up executor |
---|
118 | |
---|
119 | printf("end\n"); |
---|
120 | return 0; |
---|
121 | } |
---|