comparison packages/kernel/current/tests/stress_threads.c @ 28:18ee5a9c102e ecos-sw-1999-08-09

Merge from eCos master repository on 1999-08-09-17:04:48-BST
author jlarmour
date Mon, 09 Aug 1999 16:37:19 +0000
parents 306eee292492
children e97d78785e2d
comparison
equal deleted inserted replaced
27:2994722c9199 28:18ee5a9c102e
290 int is_dead = 0; 290 int is_dead = 0;
291 291
292 setup_death_alarm(0, &deathH, &death_alarm, &is_dead); 292 setup_death_alarm(0, &deathH, &death_alarm, &is_dead);
293 #endif /* DEATH_TIME_LIMIT */ 293 #endif /* DEATH_TIME_LIMIT */
294 294
295 printf("# Starting main\n");
296
297 for (;;) { 295 for (;;) {
298 int handler_id = -1; 296 int handler_id = -1;
299 int handler_pri = 0; 297 int handler_pri = 0;
300 298
301 cyg_mutex_lock(&free_handler_lock); { 299 cyg_mutex_lock(&free_handler_lock); {
351 /* client_program() -- an obnoxious client which makes a lot of requests */ 349 /* client_program() -- an obnoxious client which makes a lot of requests */
352 void client_program(cyg_addrword_t data) 350 void client_program(cyg_addrword_t data)
353 { 351 {
354 int delay; 352 int delay;
355 353
356 printf("# Starting client-%d\n", (int) data);
357
358 system_clockH = cyg_real_time_clock(); 354 system_clockH = cyg_real_time_clock();
359 cyg_clock_to_counter(system_clockH, &counterH); 355 cyg_clock_to_counter(system_clockH, &counterH);
360 356
361 for (;;) { 357 for (;;) {
362 delay = (rand() % 20); 358 delay = (rand() % 20);
363 359
364 /* now send a request to the server */ 360 /* now send a request to the server */
365 cyg_mutex_lock(&client_request_lock); { 361 cyg_mutex_lock(&client_request_lock); {
366 ++client_makes_request; 362 ++client_makes_request;
367 /* printf("client_makes_request %d\n", client_makes_request); */
368 } cyg_mutex_unlock(&client_request_lock); 363 } cyg_mutex_unlock(&client_request_lock);
369 364
370 cyg_thread_delay(10+delay); 365 cyg_thread_delay(10+delay);
371 /* cyg_thread_delay(0); */
372 } 366 }
373 } 367 }
374 368
375 /* listener_program() -- listens for a request and spawns a handler to 369 /* listener_program() -- listens for a request and spawns a handler to
376 take care of the request */ 370 take care of the request */
377 void listener_program(cyg_addrword_t data) 371 void listener_program(cyg_addrword_t data)
378 { 372 {
379 /* int message = (int) data; */ 373 /* int message = (int) data; */
380 int handler_slot; 374 int handler_slot;
381
382 printf("# Beginning execution; thread data is %d\n", (int) data);
383 375
384 for (;;) { 376 for (;;) {
385 int make_request = 0; 377 int make_request = 0;
386 cyg_mutex_lock(&client_request_lock); { 378 cyg_mutex_lock(&client_request_lock); {
387 if (client_makes_request > 0) { 379 if (client_makes_request > 0) {
391 } cyg_mutex_unlock(&client_request_lock); 383 } cyg_mutex_unlock(&client_request_lock);
392 384
393 if (make_request) { 385 if (make_request) {
394 int prio; 386 int prio;
395 char* name; 387 char* name;
396 /* printf("just got a request from a client (count = %d)\n", */
397 /* client_makes_request); */
398 388
399 handler_slot = get_handler_slot(listenerH[(int) data]); 389 handler_slot = get_handler_slot(listenerH[(int) data]);
400 prio = P_BASE_HANDLER+handler_slot; 390 prio = P_BASE_HANDLER+handler_slot;
401 391
402 name = &thread_name[prio][0]; 392 name = &thread_name[prio][0];
422 { 412 {
423 /* here is where we perform specific stressful tasks */ 413 /* here is where we perform specific stressful tasks */
424 perform_stressful_tasks(); 414 perform_stressful_tasks();
425 415
426 cyg_thread_delay(4 + (int) (0.5*log(1.0 + fabs((rand() % 1000000))))); 416 cyg_thread_delay(4 + (int) (0.5*log(1.0 + fabs((rand() % 1000000)))));
427 /* cyg_thread_delay(0); */
428 417
429 ++statistics.thread_exits; 418 ++statistics.thread_exits;
430 { 419 {
431 // Loop until the handler id and priority can be communicated to 420 // Loop until the handler id and priority can be communicated to
432 // the main_program. 421 // the main_program.
601 cyg_ucount32 stack_size, /* stack size, 0 = default */ 590 cyg_ucount32 stack_size, /* stack size, 0 = default */
602 cyg_handle_t *handle, /* returned thread handle */ 591 cyg_handle_t *handle, /* returned thread handle */
603 cyg_thread *thread /* put thread here */ 592 cyg_thread *thread /* put thread here */
604 ) 593 )
605 { 594 {
606 /*printf("Creating a thread -- priority is %lu\n", (unsigned long) sched_info);*/
607 /* fflush(stdout); */
608 ++statistics.thread_creations; 595 ++statistics.thread_creations;
609 cyg_thread_create(sched_info, entry, entry_data, name, 596 cyg_thread_create(sched_info, entry, entry_data, name,
610 stack_base, stack_size, handle, thread); 597 stack_base, stack_size, handle, thread);
611 598
612 CYG_ASSERT(cyg_thread_get_priority(*handle) == (cyg_priority_t) sched_info, 599 CYG_ASSERT(cyg_thread_get_priority(*handle) == (cyg_priority_t) sched_info,