From 50a501dbe89ec8f9a76540015890dd361f1ec8a1 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Wed, 10 May 2006 19:24:40 +0000 Subject: Merge-in RTEMS port patch by Phil Torre , alpha release. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@433 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pjlib-test/thread.c | 47 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'pjlib/src/pjlib-test/thread.c') diff --git a/pjlib/src/pjlib-test/thread.c b/pjlib/src/pjlib-test/thread.c index 72cb2ecd..866c7698 100644 --- a/pjlib/src/pjlib-test/thread.c +++ b/pjlib/src/pjlib-test/thread.c @@ -52,7 +52,14 @@ #define THIS_FILE "thread_test" -static int quit_flag=0; +static volatile int quit_flag=0; + +#if 0 +# define TRACE__(args) PJ_LOG(3,args) +#else +# define TRACE__(args) +#endif + /* * The thread's entry point. @@ -65,8 +72,11 @@ static void* thread_proc(pj_uint32_t *pcounter) /* Test that pj_thread_register() works. */ pj_thread_desc desc; pj_thread_t *this_thread; + unsigned id = *pcounter; pj_status_t rc; + TRACE__((THIS_FILE, " thread %d running..", id)); + rc = pj_thread_register("thread", desc, &this_thread); if (rc != PJ_SUCCESS) { app_perror("...error in pj_thread_register", rc); @@ -90,9 +100,10 @@ static void* thread_proc(pj_uint32_t *pcounter) for (;!quit_flag;) { (*pcounter)++; //Must sleep if platform doesn't do time-slicing. - pj_thread_sleep(0); + //pj_thread_sleep(0); } + TRACE__((THIS_FILE, " thread %d quitting..", id)); return NULL; } @@ -114,6 +125,7 @@ static int simple_thread(const char *title, unsigned flags) quit_flag = 0; + TRACE__((THIS_FILE, " Creating thread 0..")); rc = pj_thread_create(pool, "thread", (pj_thread_proc*)&thread_proc, &counter, PJ_THREAD_DEFAULT_STACK_SIZE, @@ -125,7 +137,9 @@ static int simple_thread(const char *title, unsigned flags) return -1010; } - pj_thread_sleep(500); + TRACE__((THIS_FILE, " Main thread waiting..")); + pj_thread_sleep(1500); + TRACE__((THIS_FILE, " Main thread resuming..")); if (flags & PJ_THREAD_SUSPENDED) { @@ -144,7 +158,7 @@ static int simple_thread(const char *title, unsigned flags) PJ_LOG(3,(THIS_FILE, "..waiting for thread to quit..")); - pj_thread_sleep(500); + pj_thread_sleep(1500); quit_flag = 1; pj_thread_join(thread); @@ -175,7 +189,7 @@ static int timeslice_test(void) quit_flag = 0; - pool = pj_pool_create(mem, NULL, 4096, 0, NULL); + pool = pj_pool_create(mem, NULL, 4000, 4000, NULL); if (!pool) return -10; @@ -183,7 +197,7 @@ static int timeslice_test(void) /* Create all threads in suspended mode. */ for (i=0; i i) { PJ_LOG(3,(THIS_FILE, "....ERROR! Thread %d-th is not suspended!", i)); return -30; @@ -211,6 +227,7 @@ static int timeslice_test(void) /* Now resume all threads. */ for (i=0; i= 50) { - PJ_LOG(3,(THIS_FILE, "...ERROR: thread didn't have equal timeslice!")); - PJ_LOG(3,(THIS_FILE, ".....lowest counter=%u, highest counter=%u, diff=%u%%", - lowest, highest, diff)); + PJ_LOG(3,(THIS_FILE, + "...ERROR: thread didn't have equal timeslice!")); + PJ_LOG(3,(THIS_FILE, + ".....lowest counter=%u, highest counter=%u, diff=%u%%", + lowest, highest, diff)); return -80; } else { PJ_LOG(3,(THIS_FILE, @@ -273,6 +299,7 @@ static int timeslice_test(void) diff)); } + pj_pool_release(pool); return 0; } -- cgit v1.2.3