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