Changeset 4728 for pjproject/trunk/pjlib/src/pjlib-test/thread.c
- Timestamp:
- Feb 4, 2014 10:13:56 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pjlib-test/thread.c
r3553 r4728 1 1 /* $Id$ */ 2 /* 2 /* 3 3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 4 4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> … … 16 16 * You should have received a copy of the GNU General Public License 17 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 19 */ 20 20 #include "test.h" … … 31 31 * - whether thread timeslicing works, and threads have equal 32 32 * time-slice proportion. 33 * 33 * 34 34 * APIs tested: 35 35 * - pj_thread_create() … … 78 78 79 79 id = *pcounter; 80 PJ_UNUSED_ARG(id); /* Warning about unused var if TRACE__ is disabled */ 80 81 TRACE__((THIS_FILE, " thread %d running..", id)); 81 82 … … 121 122 pj_status_t rc; 122 123 pj_uint32_t counter = 0; 123 124 124 125 PJ_LOG(3,(THIS_FILE, "..%s", title)); 125 126 126 127 pool = pj_pool_create(mem, NULL, 4000, 4000, NULL); 127 128 if (!pool) … … 153 154 return -1015; 154 155 } 155 156 156 157 rc = pj_thread_resume(thread); 157 158 if (rc != PJ_SUCCESS) { … … 160 161 } 161 162 } 162 163 163 164 PJ_LOG(3,(THIS_FILE, "..waiting for thread to quit..")); 164 165 … … 174 175 return -1025; 175 176 } 176 177 177 178 PJ_LOG(3,(THIS_FILE, "...%s success", title)); 178 179 return PJ_SUCCESS; … … 203 204 for (i=0; i<NUM_THREADS; ++i) { 204 205 counter[i] = i; 205 rc = pj_thread_create(pool, "thread", (pj_thread_proc*)&thread_proc, 206 &counter[i], 207 PJ_THREAD_DEFAULT_STACK_SIZE, 208 PJ_THREAD_SUSPENDED, 206 rc = pj_thread_create(pool, "thread", (pj_thread_proc*)&thread_proc, 207 &counter[i], 208 PJ_THREAD_DEFAULT_STACK_SIZE, 209 PJ_THREAD_SUSPENDED, 209 210 &thread[i]); 210 211 if (rc!=PJ_SUCCESS) { … … 224 225 for (i=0; i<NUM_THREADS; ++i) { 225 226 if (counter[i] > i) { 226 PJ_LOG(3,(THIS_FILE, "....ERROR! Thread %d-th is not suspended!", 227 PJ_LOG(3,(THIS_FILE, "....ERROR! Thread %d-th is not suspended!", 227 228 i)); 228 229 return -30; … … 240 241 } 241 242 242 /* Main thread sleeps for some time to allow threads to run. 243 /* Main thread sleeps for some time to allow threads to run. 243 244 * The longer we sleep, the more accurate the calculation will be, 244 245 * but it'll make user waits for longer for the test to finish. … … 253 254 /* Wait until all threads quit, then destroy. */ 254 255 for (i=0; i<NUM_THREADS; ++i) { 255 TRACE__((THIS_FILE, " Main thread joining thread %d [%p]..", 256 TRACE__((THIS_FILE, " Main thread joining thread %d [%p]..", 256 257 i, thread[i])); 257 258 rc = pj_thread_join(thread[i]); … … 292 293 diff = (highest-lowest)*100 / ((highest+lowest)/2); 293 294 if ( diff >= 50) { 294 PJ_LOG(3,(THIS_FILE, 295 PJ_LOG(3,(THIS_FILE, 295 296 "...ERROR: thread didn't have equal timeslice!")); 296 PJ_LOG(3,(THIS_FILE, 297 PJ_LOG(3,(THIS_FILE, 297 298 ".....lowest counter=%u, highest counter=%u, diff=%u%%", 298 299 lowest, highest, diff)); 299 300 return -80; 300 301 } else { 301 PJ_LOG(3,(THIS_FILE, 302 PJ_LOG(3,(THIS_FILE, 302 303 "...info: timeslice diff between lowest & highest=%u%%", 303 304 diff)); … … 315 316 if (rc != PJ_SUCCESS) 316 317 return rc; 317 318 318 319 rc = simple_thread("suspended thread test", PJ_THREAD_SUSPENDED); 319 320 if (rc != PJ_SUCCESS) 320 321 return rc; 321 322 322 323 rc = timeslice_test(); 323 324 if (rc != PJ_SUCCESS) … … 329 330 #else 330 331 /* To prevent warning about "translation unit is empty" 331 * when this test is disabled. 332 * when this test is disabled. 332 333 */ 333 334 int dummy_thread_test;
Note: See TracChangeset
for help on using the changeset viewer.