Ignore:
Timestamp:
May 10, 2006 7:24:40 PM (18 years ago)
Author:
bennylp
Message:

Merge-in RTEMS port patch by Phil Torre <ptorre@…>, alpha release.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pjlib-test/thread.c

    r351 r433  
    5353#define THIS_FILE   "thread_test" 
    5454 
    55 static int quit_flag=0; 
     55static volatile int quit_flag=0; 
     56 
     57#if 0 
     58#   define TRACE__(args)        PJ_LOG(3,args) 
     59#else 
     60#   define TRACE__(args) 
     61#endif 
     62 
    5663 
    5764/* 
     
    6673    pj_thread_desc desc; 
    6774    pj_thread_t *this_thread; 
     75    unsigned id = *pcounter; 
    6876    pj_status_t rc; 
     77 
     78    TRACE__((THIS_FILE, "     thread %d running..", id)); 
    6979 
    7080    rc = pj_thread_register("thread", desc, &this_thread); 
     
    91101        (*pcounter)++; 
    92102        //Must sleep if platform doesn't do time-slicing. 
    93         pj_thread_sleep(0); 
    94     } 
    95  
     103        //pj_thread_sleep(0); 
     104    } 
     105 
     106    TRACE__((THIS_FILE, "     thread %d quitting..", id)); 
    96107    return NULL; 
    97108} 
     
    115126    quit_flag = 0; 
    116127 
     128    TRACE__((THIS_FILE, "    Creating thread 0..")); 
    117129    rc = pj_thread_create(pool, "thread", (pj_thread_proc*)&thread_proc, 
    118130                          &counter, 
     
    126138    } 
    127139 
    128     pj_thread_sleep(500); 
     140    TRACE__((THIS_FILE, "    Main thread waiting..")); 
     141    pj_thread_sleep(1500); 
     142    TRACE__((THIS_FILE, "    Main thread resuming..")); 
    129143 
    130144    if (flags & PJ_THREAD_SUSPENDED) { 
     
    145159    PJ_LOG(3,(THIS_FILE, "..waiting for thread to quit..")); 
    146160 
    147     pj_thread_sleep(500); 
     161    pj_thread_sleep(1500); 
    148162 
    149163    quit_flag = 1; 
     
    176190    quit_flag = 0; 
    177191 
    178     pool = pj_pool_create(mem, NULL, 4096, 0, NULL); 
     192    pool = pj_pool_create(mem, NULL, 4000, 4000, NULL); 
    179193    if (!pool) 
    180194        return -10; 
     
    184198    /* Create all threads in suspended mode. */ 
    185199    for (i=0; i<NUM_THREADS; ++i) { 
    186         counter[i] = 0; 
     200        counter[i] = i; 
    187201        rc = pj_thread_create(pool, "thread", (pj_thread_proc*)&thread_proc,  
    188202                              &counter[i],  
     
    199213     * The purpose of this is to test whether all threads are suspended. 
    200214     */ 
     215    TRACE__((THIS_FILE, "    Main thread waiting..")); 
    201216    pj_thread_sleep(1000); 
     217    TRACE__((THIS_FILE, "    Main thread resuming..")); 
    202218 
    203219    /* Check that all counters are still zero. */ 
    204220    for (i=0; i<NUM_THREADS; ++i) { 
    205         if (counter[i] != 0) { 
     221        if (counter[i] > i) { 
    206222            PJ_LOG(3,(THIS_FILE, "....ERROR! Thread %d-th is not suspended!",  
    207223                      i)); 
     
    212228    /* Now resume all threads. */ 
    213229    for (i=0; i<NUM_THREADS; ++i) { 
     230        TRACE__((THIS_FILE, "    Resuming thread %d [%p]..", i, thread[i])); 
    214231        rc = pj_thread_resume(thread[i]); 
    215232        if (rc != PJ_SUCCESS) { 
     
    223240     * but it'll make user waits for longer for the test to finish. 
    224241     */ 
     242    TRACE__((THIS_FILE, "    Main thread waiting (5s)..")); 
    225243    pj_thread_sleep(5000); 
     244    TRACE__((THIS_FILE, "    Main thread resuming..")); 
    226245 
    227246    /* Signal all threads to quit. */ 
     
    230249    /* Wait until all threads quit, then destroy. */ 
    231250    for (i=0; i<NUM_THREADS; ++i) { 
     251        TRACE__((THIS_FILE, "    Main thread joining thread %d [%p]..",  
     252                            i, thread[i])); 
    232253        rc = pj_thread_join(thread[i]); 
    233254        if (rc != PJ_SUCCESS) { 
     
    235256            return -50; 
    236257        } 
     258        TRACE__((THIS_FILE, "    Destroying thread %d [%p]..", i, thread[i])); 
    237259        rc = pj_thread_destroy(thread[i]); 
    238260        if (rc != PJ_SUCCESS) { 
     
    241263        } 
    242264    } 
     265 
     266    TRACE__((THIS_FILE, "    Main thread calculating time slices..")); 
    243267 
    244268    /* Now examine the value of the counters. 
     
    264288    diff = (highest-lowest)*100 / ((highest+lowest)/2); 
    265289    if ( diff >= 50) { 
    266         PJ_LOG(3,(THIS_FILE, "...ERROR: thread didn't have equal timeslice!")); 
    267         PJ_LOG(3,(THIS_FILE, ".....lowest counter=%u, highest counter=%u, diff=%u%%", 
    268                              lowest, highest, diff)); 
     290        PJ_LOG(3,(THIS_FILE,  
     291                  "...ERROR: thread didn't have equal timeslice!")); 
     292        PJ_LOG(3,(THIS_FILE,  
     293                  ".....lowest counter=%u, highest counter=%u, diff=%u%%", 
     294                  lowest, highest, diff)); 
    269295        return -80; 
    270296    } else { 
     
    274300    } 
    275301 
     302    pj_pool_release(pool); 
    276303    return 0; 
    277304} 
Note: See TracChangeset for help on using the changeset viewer.