Revision 1074 branches/simulator/projects/simulator/simulator/core/robot.c

View differences:

robot.c
53 53
pthread_cond_t all_finished_cond;
54 54
int finished = 0;
55 55

  
56
int pausing = 0;
57
int paused = 0;
58

  
56 59
int robots_initialize(void)
57 60
{
58 61
	int i;
......
74 77
	return 0;
75 78
}
76 79

  
80
int robots_cleanup(void)
81
{
82
	robots_pause();
83
	//TODO: clean things up
84
	return 0;
85
}
86

  
87
void robots_pause(void)
88
{
89
	pausing = 1;
90
	while (!paused) usleep(10000);
91
}
92

  
93
void robots_resume(void)
94
{
95
	pausing = 0;
96
}
97

  
77 98
/**
78 99
 * Creates a new robot. Returns its id on
79 100
 * success, or a negative integer on failure.
......
287 308
			  err(errno, "error waiting on condition variable");
288 309
		}
289 310
		finished = 0;
311
		
312
		ret = pthread_mutex_unlock(&all_finished_mutex);
290 313

  
291
    //sleep to avoid 100% CPU usage
292
    usleep(10000);
314
		//sleep to avoid 100% CPU usage
315
		usleep(10000);
316
		while (pausing)
317
		{
318
			paused = 1;
319
			usleep(50000);
320
		}
321
		paused = 0;
293 322

  
294
		ret = pthread_mutex_unlock(&all_finished_mutex);
295 323
		if(ret)
296 324
		  fprintf(stderr, "hmmm, error unlocking. errno: %d", errno);
297 325

  
......
301 329
			{
302 330
				robot_update(i);
303 331

  
304
				printf("commit %d\n", i);
305 332
				commit(&robots[i],i,timeStep);
306 333
			}
307 334
		for (i = 0; i < robots_size; i++)
......
313 340
			  warn("error: could not kill resume robot proc.");
314 341
		}
315 342

  
316
		gui_refresh();
343
		if (timeStep % 5 == 0)
344
			gui_refresh();
317 345
	}
318 346
}
319 347

  

Also available in: Unified diff