comparison xrogue/daemon.c @ 238:e1cd27c5464f

arogue7, xrogue: improve the handling of the arguments to fuses. fuse() now expects a pointer as the argument to a fuse function. If this is one of the functions that takes int, fuse() follows the pointer and stores that value in the f_list slot, in the integer field of the argument union. When the fuse goes off, do_fuses() recognizes the function and passes it the integer field instead of the pointer. This has the disadvantage of hard-coding the functions that require int in daemon.c, but since the int is copied into f_list, it no longer has to be in static or global memory, which simplifies several files.
author John "Elwin" Edwards
date Fri, 11 Mar 2016 17:40:00 -0500
parents 7c1cb43f346e
children
comparison
equal deleted inserted replaced
237:2236ef808bcb 238:e1cd27c5464f
170 170
171 wire = f_slot(); 171 wire = f_slot();
172 if (wire != NULL) { 172 if (wire != NULL) {
173 wire->d_type = type; 173 wire->d_type = type;
174 wire->d_func = dfunc; 174 wire->d_func = dfunc;
175 wire->d_arg.vp = arg; 175 if (dfunc == changeclass || dfunc == res_strength)
176 wire->d_arg.i = *(int *) arg;
177 else
178 wire->d_arg.vp = arg;
176 wire->d_time = time; 179 wire->d_time = time;
177 fusecnt += 1; /* update count */ 180 fusecnt += 1; /* update count */
178 } 181 }
179 } 182 }
180 183
218 */ 221 */
219 222
220 void 223 void
221 do_fuses(int flag) 224 do_fuses(int flag)
222 { 225 {
223 struct delayed_action *wire; 226 struct delayed_action *wire;
224 int i; 227 int i;
225 228
226 /* 229 /*
227 * Step though the list 230 * Step though the list
228 */ 231 */
229 for (i = 0; i < MAXFUSES; i++) { 232 for (i = 0; i < MAXFUSES; i++) {
230 wire = &f_list[i]; 233 wire = &f_list[i];
231 /* 234 /*
232 * Decrementing counters and starting things we want. We also need 235 * Decrementing counters and starting things we want. We also need
233 * to remove the fuse from the list once it has gone off. 236 * to remove the fuse from the list once it has gone off.
234 */ 237 */
235 if(flag == wire->d_type && wire->d_time > 0 && 238 if(flag == wire->d_type && wire->d_time > 0 &&
236 --wire->d_time == 0) { 239 --wire->d_time == 0) {
237 wire->d_type = EMPTY; 240 wire->d_type = EMPTY;
238 if (wire->d_func != NULL) 241 if (*wire->d_func == changeclass || *wire->d_func == res_strength)
239 (*wire->d_func)(wire->d_arg.vp); 242 (*wire->d_func)(wire->d_arg.i);
240 fusecnt -= 1; 243 else if (wire->d_func != NULL)
241 } 244 (*wire->d_func)(wire->d_arg.vp);
242 } 245 fusecnt -= 1;
246 }
247 }
243 } 248 }
244 249
245 /* 250 /*
246 * activity: 251 * activity:
247 * Show wizard number of demaons and memory blocks used 252 * Show wizard number of demaons and memory blocks used