@@ -67,25 +67,29 @@ typedef struct {
6767 int product ;
6868} msg_type_2 ;
6969
70- static inline int random_int (int const min , int const max ) {
70+ static inline int random_int (int const min , int const max )
71+ {
7172 return min + rand () / (RAND_MAX / (max - min + 1 ) + 1 );
7273}
7374
74- static inline void fill_msg_type_1 (msg_type_1 msg [const static 1 ]) {
75- msg -> a = random_int (0 , 10 );
76- msg -> b = random_int (0 , 10 );
75+ static inline void fill_msg_type_1 (msg_type_1 msg [const static 1 ])
76+ {
77+ msg -> a = random_int (0 , 10 );
78+ msg -> b = random_int (0 , 10 );
7779 msg -> sum = msg -> a + msg -> b ;
7880}
7981
80- static inline void fill_msg_type_2 (msg_type_2 to [const static 1 ],
81- msg_type_1 const from [const static 1 ]) {
82- to -> x = from -> a ;
83- to -> y = from -> b ;
84- to -> sum = from -> sum ;
82+ static inline void fill_msg_type_2 (msg_type_2 to [const static 1 ],
83+ msg_type_1 const from [const static 1 ])
84+ {
85+ to -> x = from -> a ;
86+ to -> y = from -> b ;
87+ to -> sum = from -> sum ;
8588 to -> product = (from -> a * from -> b );
8689}
8790
88- static void * producer_fn (void * args ) {
91+ static void * producer_fn (void * args )
92+ {
8993 th_struct * data = (th_struct * )args ;
9094
9195 x9_inbox * const destination = x9_select_inbox_from_node (data -> node , "ibx_1" );
@@ -99,7 +103,8 @@ static void* producer_fn(void* args) {
99103 return 0 ;
100104}
101105
102- static void * producer_consumer_fn (void * args ) {
106+ static void * producer_consumer_fn (void * args )
107+ {
103108 th_struct * data = (th_struct * )args ;
104109
105110 x9_inbox * const inbox = x9_select_inbox_from_node (data -> node , "ibx_1" );
@@ -122,7 +127,8 @@ static void* producer_consumer_fn(void* args) {
122127 return 0 ;
123128}
124129
125- static void * consumer_fn (void * args ) {
130+ static void * consumer_fn (void * args )
131+ {
126132 th_struct * data = (th_struct * )args ;
127133
128134 x9_inbox * const inbox = x9_select_inbox_from_node (data -> node , "ibx_2" );
@@ -139,41 +145,42 @@ static void* consumer_fn(void* args) {
139145 return 0 ;
140146}
141147
142- int main (void ) {
148+ int main (void )
149+ {
143150 /* Seed random generator */
144151 srand ((uint32_t )time (0 ));
145152
146153 /* Create inboxes */
147154 x9_inbox * const inbox_msg_type_1 =
148- x9_create_inbox (4 , "ibx_1" , sizeof (msg_type_1 ));
155+ x9_create_inbox (4 , "ibx_1" , sizeof (msg_type_1 ));
149156
150157 x9_inbox * const inbox_msg_type_2 =
151- x9_create_inbox (4 , "ibx_2" , sizeof (msg_type_2 ));
158+ x9_create_inbox (4 , "ibx_2" , sizeof (msg_type_2 ));
152159
153160 /* Using asserts to simplify code for presentation purpose. */
154161 assert (x9_inbox_is_valid (inbox_msg_type_1 ));
155162 assert (x9_inbox_is_valid (inbox_msg_type_2 ));
156163
157164 /* Create node */
158165 x9_node * const node =
159- x9_create_node ("my_node" , 2 , inbox_msg_type_1 , inbox_msg_type_2 );
166+ x9_create_node ("my_node" , 2 , inbox_msg_type_1 , inbox_msg_type_2 );
160167
161168 /* Assert - Same reason as above. */
162169 assert (x9_node_is_valid (node ));
163170
164171 /* Producers */
165- pthread_t producer_th_1 = {0 };
172+ pthread_t producer_th_1 = {0 };
166173 th_struct producer_1_struct = {.node = node };
167174
168- pthread_t producer_th_2 = {0 };
175+ pthread_t producer_th_2 = {0 };
169176 th_struct producer_2_struct = {.node = node };
170177
171178 /* Producer/Consumer */
172179 pthread_t producer_consumer_th = {0 };
173- th_struct prod_cons_struct = {.node = node };
180+ th_struct prod_cons_struct = {.node = node };
174181
175182 /* Consumer */
176- pthread_t consumer_th = {0 };
183+ pthread_t consumer_th = {0 };
177184 th_struct consumer_struct = {.node = node };
178185
179186 /* Launch threads */
0 commit comments