Revision 1072
Switched to loop based suspending on the robots using simulator_do
now runs much better for the stupid template sample
libsim.c | ||
---|---|---|
8 | 8 |
#include <sys/ipc.h> |
9 | 9 |
#include <robot_shared.h> |
10 | 10 |
#include <string.h> |
11 |
#include <dragonfly_lib.h> |
|
11 | 12 |
|
12 |
#define TICK_USEC 100 |
|
13 |
|
|
14 | 13 |
RobotShared* shared_state; |
15 | 14 |
|
16 |
void tick(int sig) |
|
17 |
{ |
|
18 |
if(raise(SIGTSTP)<0) |
|
19 |
printf("could not kill self!\n"); |
|
20 |
} |
|
21 |
|
|
22 |
|
|
23 | 15 |
void dragonfly_init(int config) |
24 | 16 |
{ |
25 | 17 |
struct itimerval iv; |
... | ... | |
33 | 25 |
return; |
34 | 26 |
} |
35 | 27 |
|
36 |
|
|
37 |
//printf("hello. I am a robot w/ memory_id %s\n", getenv("memory_id")); |
|
38 | 28 |
|
39 |
|
|
40 |
iv.it_interval.tv_sec = 0; |
|
41 |
iv.it_interval.tv_usec = TICK_USEC; |
|
42 |
iv.it_value.tv_sec = 0; |
|
43 |
iv.it_value.tv_usec = TICK_USEC; |
|
44 |
|
|
45 |
signal(SIGVTALRM, tick); |
|
46 |
|
|
47 |
ret = setitimer(ITIMER_VIRTUAL, &iv, NULL); |
|
48 |
|
|
49 | 29 |
//printf("setitimer returned %d.\n waiting...\n", ret); |
50 | 30 |
fflush(stdout); |
51 | 31 |
|
... | ... | |
53 | 33 |
|
54 | 34 |
} |
55 | 35 |
|
36 |
void simulator_do() |
|
37 |
{ |
|
38 |
if(raise(SIGTSTP)<0) |
|
39 |
fprintf(stderr, "ERROR: could not kill self\n"); |
|
40 |
|
|
41 |
} |
Also available in: Unified diff