[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 { |
---|
| 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 | |
---|
| 21 | // this isn't a valid receive routine since int is not a message type |
---|
| 22 | Allocation receive( derived_actor & receiver, int i ) with( receiver ) { |
---|
| 23 | mutex(sout) sout | i; |
---|
| 24 | counter++; |
---|
| 25 | if ( counter == 2 ) return Finished; |
---|
| 26 | return Nodelete; |
---|
| 27 | } |
---|
| 28 | |
---|
[757099e] | 29 | Allocation receive( derived_actor & receiver, d_msg & msg ) { |
---|
| 30 | return receive( receiver, msg.num ); |
---|
| 31 | } |
---|
| 32 | |
---|
[418882a] | 33 | struct derived_actor2 { |
---|
[757099e] | 34 | struct nested { int i; }; // testing nested before inline |
---|
[418882a] | 35 | inline actor; |
---|
| 36 | }; |
---|
| 37 | |
---|
[757099e] | 38 | Allocation receive( derived_actor2 & receiver, d_msg & msg ) { |
---|
| 39 | mutex(sout) sout | msg.num; |
---|
| 40 | return Finished; |
---|
| 41 | } |
---|
| 42 | |
---|
[4933f18] | 43 | struct derived_actor3 { inline actor; }; |
---|
| 44 | struct derived_actor4 { inline derived_actor3; }; |
---|
[418882a] | 45 | struct d_msg2 { |
---|
| 46 | inline message; |
---|
| 47 | int num; |
---|
| 48 | }; |
---|
| 49 | |
---|
| 50 | Allocation receive( derived_actor3 & receiver, d_msg & msg ) { |
---|
| 51 | mutex(sout) sout | msg.num; |
---|
| 52 | if ( msg.num == -1 ) return Nodelete; |
---|
| 53 | return Finished; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | Allocation receive( derived_actor3 & receiver, d_msg2 & msg ) { |
---|
| 57 | mutex(sout) sout | msg.num; |
---|
| 58 | return Finished; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | size_t Processors = 3; |
---|
| 62 | |
---|
| 63 | int main( int argc, char * argv[] ) { |
---|
| 64 | printf("start\n"); |
---|
| 65 | |
---|
| 66 | processor p[Processors - 1]; |
---|
| 67 | |
---|
| 68 | printf("basic test\n"); |
---|
| 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; |
---|
[809e058] | 74 | a << b << c; |
---|
[418882a] | 75 | stop_actor_system(); |
---|
| 76 | |
---|
| 77 | printf("same message and different actors test\n"); |
---|
| 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; |
---|
[809e058] | 82 | d_ac2_0 << d_ac2_msg; |
---|
| 83 | d_ac2_1 << d_ac2_msg; |
---|
[418882a] | 84 | stop_actor_system(); |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | { |
---|
| 88 | printf("same message and different actor types test\n"); |
---|
| 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; |
---|
[809e058] | 95 | d_ac3_0 << d_ac23_msg; |
---|
| 96 | d_ac2_2 << d_ac23_msg; |
---|
[418882a] | 97 | stop_actor_system(); |
---|
| 98 | } // RAII to clean up executor |
---|
| 99 | |
---|
| 100 | { |
---|
| 101 | printf("different message types, one actor test\n"); |
---|
| 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; |
---|
[809e058] | 109 | a3 << b1 << c2; |
---|
[418882a] | 110 | stop_actor_system(); |
---|
| 111 | } // RAII to clean up executor |
---|
| 112 | |
---|
[4933f18] | 113 | { |
---|
| 114 | printf("nested inheritance actor test\n"); |
---|
| 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 | |
---|
[418882a] | 126 | printf("end\n"); |
---|
| 127 | return 0; |
---|
| 128 | } |
---|