Changeset 5
- Timestamp:
- Nov 1, 2005 9:46:17 PM (19 years ago)
- Location:
- pjproject/main/pjlib
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/main/pjlib/include/pj/os.h
r4 r5 305 305 * @param atomic_var the atomic variable. 306 306 * @param value value to be set to the variable. 307 * 308 * @return the previous value of the variable. 309 */ 310 PJ_DECL(pj_atomic_value_t) pj_atomic_set(pj_atomic_t *atomic_var, 311 pj_atomic_value_t value); 307 */ 308 PJ_DECL(void) pj_atomic_set( pj_atomic_t *atomic_var, 309 pj_atomic_value_t value); 312 310 313 311 /** … … 324 322 * 325 323 * @param atomic_var the atomic variable. 326 * 327 * @return the result. 328 */ 329 PJ_DECL(pj_atomic_value_t) pj_atomic_inc(pj_atomic_t *atomic_var); 324 */ 325 PJ_DECL(void) pj_atomic_inc(pj_atomic_t *atomic_var); 330 326 331 327 /** … … 333 329 * 334 330 * @param atomic_var the atomic variable. 335 * 336 * @return the result. 337 */ 338 PJ_DECL(pj_atomic_value_t) pj_atomic_dec(pj_atomic_t *atomic_var); 331 */ 332 PJ_DECL(void) pj_atomic_dec(pj_atomic_t *atomic_var); 333 334 /** 335 * Add a value to an atomic type. 336 * 337 * @param atomic_var The atomic variable. 338 * @param value Value to be added. 339 */ 340 PJ_DECL(void) pj_atomic_add( pj_atomic_t *atomic_var, 341 pj_atomic_value_t value); 339 342 340 343 /** -
pjproject/main/pjlib/src/pj/os_core_linux_kernel.c
r4 r5 416 416 PJ_DEF(pj_status_t) pj_atomic_destroy( pj_atomic_t *var ) 417 417 { 418 return 0; 419 } 420 421 PJ_DEF(pj_atomic_value_t) pj_atomic_set(pj_atomic_t *var, 422 pj_atomic_value_t value) 423 { 424 pj_atomic_value_t oldval = atomic_read(&var->atom); 418 return PJ_SUCCESS; 419 } 420 421 PJ_DEF(void) pj_atomic_set(pj_atomic_t *var, pj_atomic_value_t value) 422 { 425 423 atomic_set(&var->atom, value); 426 return oldval;427 424 } 428 425 … … 432 429 } 433 430 434 PJ_DEF( pj_atomic_value_t) pj_atomic_inc(pj_atomic_t *var)431 PJ_DEF(void) pj_atomic_inc(pj_atomic_t *var) 435 432 { 436 433 atomic_inc(&var->atom); 437 return atomic_read(&var->atom); 438 } 439 440 PJ_DEF(pj_atomic_value_t) pj_atomic_dec(pj_atomic_t *var) 434 } 435 436 PJ_DEF(void) pj_atomic_dec(pj_atomic_t *var) 441 437 { 442 438 atomic_dec(&var->atom); 443 return atomic_read(&var->atom); 444 } 445 439 } 440 441 PJ_DEF(void) pj_atomic_add( pj_atomic_t *var, pj_atomic_value_t value ) 442 { 443 atomic_add(value, &var->atom); 444 } 446 445 447 446 -
pjproject/main/pjlib/src/pj/os_core_unix.c
r4 r5 527 527 * pj_atomic_set() 528 528 */ 529 PJ_DEF(pj_atomic_value_t) pj_atomic_set(pj_atomic_t *atomic_var, 530 pj_atomic_value_t value) 531 { 532 pj_atomic_value_t oldval; 533 534 PJ_CHECK_STACK(); 535 PJ_ASSERT_RETURN(atomic_var, 0); 529 PJ_DEF(void) pj_atomic_set(pj_atomic_t *atomic_var, pj_atomic_value_t value) 530 { 531 PJ_CHECK_STACK(); 536 532 537 533 #if PJ_HAS_THREADS 538 534 pj_mutex_lock( atomic_var->mutex ); 539 535 #endif 540 oldval = atomic_var->value;541 536 atomic_var->value = value; 542 537 #if PJ_HAS_THREADS 543 538 pj_mutex_unlock( atomic_var->mutex); 544 539 #endif 540 } 541 542 /* 543 * pj_atomic_get() 544 */ 545 PJ_DEF(pj_atomic_value_t) pj_atomic_get(pj_atomic_t *atomic_var) 546 { 547 pj_atomic_value_t oldval; 548 549 PJ_CHECK_STACK(); 550 551 #if PJ_HAS_THREADS 552 pj_mutex_lock( atomic_var->mutex ); 553 #endif 554 oldval = atomic_var->value; 555 #if PJ_HAS_THREADS 556 pj_mutex_unlock( atomic_var->mutex); 557 #endif 545 558 return oldval; 546 559 } 547 560 548 561 /* 549 * pj_atomic_get() 550 */ 551 PJ_DEF(pj_atomic_value_t) pj_atomic_get(pj_atomic_t *atomic_var) 552 { 553 pj_atomic_value_t oldval; 554 555 PJ_CHECK_STACK(); 556 PJ_ASSERT_RETURN(atomic_var, 0); 562 * pj_atomic_inc() 563 */ 564 PJ_DEF(void) pj_atomic_inc(pj_atomic_t *atomic_var) 565 { 566 PJ_CHECK_STACK(); 557 567 558 568 #if PJ_HAS_THREADS 559 569 pj_mutex_lock( atomic_var->mutex ); 560 570 #endif 561 oldval =atomic_var->value;571 ++atomic_var->value; 562 572 #if PJ_HAS_THREADS 563 573 pj_mutex_unlock( atomic_var->mutex); 564 574 #endif 565 return oldval; 566 } 567 568 /* 569 * pj_atomic_inc() 570 */ 571 PJ_DEF(pj_atomic_value_t) pj_atomic_inc(pj_atomic_t *atomic_var) 572 { 573 pj_atomic_value_t newval; 574 575 PJ_CHECK_STACK(); 576 PJ_ASSERT_RETURN(atomic_var, 0); 575 } 576 577 /* 578 * pj_atomic_dec() 579 */ 580 PJ_DEF(void) pj_atomic_dec(pj_atomic_t *atomic_var) 581 { 582 PJ_CHECK_STACK(); 577 583 578 584 #if PJ_HAS_THREADS 579 585 pj_mutex_lock( atomic_var->mutex ); 580 586 #endif 581 newval = ++atomic_var->value;587 --atomic_var->value; 582 588 #if PJ_HAS_THREADS 583 589 pj_mutex_unlock( atomic_var->mutex); 584 590 #endif 585 return newval; 586 } 587 588 /* 589 * pj_atomic_dec() 590 */ 591 PJ_DEF(pj_atomic_value_t) pj_atomic_dec(pj_atomic_t *atomic_var) 592 { 593 pj_atomic_value_t newval; 594 595 PJ_CHECK_STACK(); 596 PJ_ASSERT_RETURN(atomic_var, 0); 597 598 #if PJ_HAS_THREADS 599 pj_mutex_lock( atomic_var->mutex ); 600 #endif 601 newval = --atomic_var->value; 602 #if PJ_HAS_THREADS 603 pj_mutex_unlock( atomic_var->mutex); 604 #endif 605 return newval; 591 } 592 593 /* 594 * pj_atomic_add() 595 */ 596 PJ_DEF(void) pj_atomic_add( pj_atomic_t *atomic_var, pj_atomic_value_t value ) 597 { 598 #if PJ_HAS_THREADS 599 pj_mutex_lock(atomic_var->mutex); 600 #endif 601 602 atomic_var->value += value; 603 604 #if PJ_HAS_THREADS 605 pj_mutex_unlock(atomic_var->mutex); 606 #endif 606 607 } 607 608 -
pjproject/main/pjlib/src/pj/os_core_win32.c
r4 r5 496 496 * pj_atomic_set() 497 497 */ 498 PJ_DEF(long) pj_atomic_set(pj_atomic_t *atomic_var, long value) 498 PJ_DEF(void) pj_atomic_set( pj_atomic_t *atomic_var, pj_atomic_value_t value) 499 { 500 PJ_CHECK_STACK(); 501 502 InterlockedExchange(&atomic_var->value, value); 503 } 504 505 /* 506 * pj_atomic_get() 507 */ 508 PJ_DEF(pj_atomic_value_t) pj_atomic_get(pj_atomic_t *atomic_var) 499 509 { 500 510 PJ_CHECK_STACK(); 501 511 PJ_ASSERT_RETURN(atomic_var, 0); 502 512 503 return InterlockedExchange(&atomic_var->value, value);504 }505 506 /*507 * pj_atomic_get()508 */509 PJ_DEF(long) pj_atomic_get(pj_atomic_t *atomic_var)510 {511 PJ_CHECK_STACK();512 PJ_ASSERT_RETURN(atomic_var, 0);513 514 513 return atomic_var->value; 515 514 } … … 518 517 * pj_atomic_inc() 519 518 */ 520 PJ_DEF(long) pj_atomic_inc(pj_atomic_t *atomic_var) 521 { 522 PJ_CHECK_STACK(); 523 PJ_ASSERT_RETURN(atomic_var, 0); 519 PJ_DEF(void) pj_atomic_inc(pj_atomic_t *atomic_var) 520 { 521 PJ_CHECK_STACK(); 524 522 525 523 #if defined(PJ_WIN32_WINNT) && PJ_WIN32_WINNT >= 0x0400 526 returnInterlockedIncrement(&atomic_var->value);524 InterlockedIncrement(&atomic_var->value); 527 525 #else 528 526 # error Fix Me … … 533 531 * pj_atomic_dec() 534 532 */ 535 PJ_DEF(long) pj_atomic_dec(pj_atomic_t *atomic_var) 536 { 537 PJ_CHECK_STACK(); 538 PJ_ASSERT_RETURN(atomic_var, 0); 533 PJ_DEF(void) pj_atomic_dec(pj_atomic_t *atomic_var) 534 { 535 PJ_CHECK_STACK(); 539 536 540 537 #if defined(PJ_WIN32_WINNT) && PJ_WIN32_WINNT >= 0x0400 541 returnInterlockedDecrement(&atomic_var->value);538 InterlockedDecrement(&atomic_var->value); 542 539 #else 543 540 # error Fix me … … 545 542 } 546 543 547 544 /* 545 * pj_atomic_add() 546 */ 547 PJ_DEF(void) pj_atomic_add( pj_atomic_t *atomic_var, 548 pj_atomic_value_t value ) 549 { 550 InterlockedExchangeAdd( &atomic_var->value, value ); 551 } 552 553 548 554 /////////////////////////////////////////////////////////////////////////////// 549 555 /* -
pjproject/main/pjlib/src/pjlib-test/echo_clt.c
r4 r5 29 29 }; 30 30 31 static pj_sem_t *sem; 32 static pj_mutex_t *mutex; 33 static pj_size_t total_bw; 34 static unsigned total_poster; 35 static pj_time_val first_report; 31 static pj_atomic_t *totalBytes; 36 32 37 33 #define MSEC_PRINT_DURATION 1000 … … 62 58 struct client *client = arg; 63 59 pj_status_t last_recv_err = PJ_SUCCESS, last_send_err = PJ_SUCCESS; 64 65 pj_time_val last_report, next_report; 66 pj_size_t thread_total; 60 unsigned counter = 0; 67 61 68 62 rc = app_socket(PJ_AF_INET, client->sock_type, 0, -1, &sock); … … 90 84 pj_ntohs(addr.sin_port))); 91 85 92 pj_ create_random_string(send_buf, BUF_SIZE);93 thread_total = 0;86 pj_memset(send_buf, 'A', BUF_SIZE); 87 send_buf[BUF_SIZE-1]='\0'; 94 88 95 89 /* Give other thread chance to initialize themselves! */ 96 pj_thread_sleep(500); 97 98 pj_gettimeofday(&last_report); 99 next_report = first_report; 90 pj_thread_sleep(200); 100 91 101 92 //PJ_LOG(3,("", "...thread %p running", pj_thread_this())); … … 104 95 int rc; 105 96 pj_ssize_t bytes; 106 pj_time_val now; 97 98 ++counter; 107 99 108 100 /* Send a packet. */ … … 148 140 } 149 141 150 /* Accumulate total received. */151 thread_total = thread_total + bytes;152 153 /* Report current bandwidth on due. */154 pj_gettimeofday(&now);155 156 if (PJ_TIME_VAL_GTE(now, next_report)) {157 pj_uint32_t bw;158 pj_bool_t signal_parent = 0;159 pj_time_val duration;160 pj_uint32_t msec;161 162 duration = now;163 PJ_TIME_VAL_SUB(duration, last_report);164 msec = PJ_TIME_VAL_MSEC(duration);165 166 bw = thread_total * 1000 / msec;167 168 /* Post result to parent */169 pj_mutex_lock(mutex);170 total_bw += bw;171 total_poster++;172 //PJ_LOG(3,("", "...thread %p posting result", pj_thread_this()));173 if (total_poster >= ECHO_CLIENT_MAX_THREADS)174 signal_parent = 1;175 pj_mutex_unlock(mutex);176 177 thread_total = 0;178 last_report = now;179 next_report.sec++;180 181 if (signal_parent) {182 pj_sem_post(sem);183 }184 185 pj_thread_sleep(0);186 }187 188 142 if (bytes == 0) 189 143 continue; 190 144 191 145 if (pj_memcmp(send_buf, recv_buf, BUF_SIZE) != 0) { 192 //PJ_LOG(3,("", "...error: buffer has changed!")); 193 break; 194 } 146 recv_buf[BUF_SIZE-1] = '\0'; 147 PJ_LOG(3,("", "...error: buffer %u has changed!\n" 148 "send_buf=%s\n" 149 "recv_buf=%s\n", 150 counter, send_buf, recv_buf)); 151 //break; 152 } 153 154 /* Accumulate total received. */ 155 pj_atomic_add(totalBytes, bytes); 195 156 } 196 157 … … 206 167 struct client client; 207 168 int i; 169 pj_atomic_value_t last_received; 170 pj_timestamp last_report; 208 171 209 172 client.sock_type = sock_type; … … 213 176 pool = pj_pool_create( mem, NULL, 4000, 4000, NULL ); 214 177 215 rc = pj_sem_create(pool, NULL, 0, ECHO_CLIENT_MAX_THREADS+1, &sem); 216 if (rc != PJ_SUCCESS) { 217 PJ_LOG(3,("", "...error: unable to create semaphore", rc)); 218 return -10; 219 } 220 221 rc = pj_mutex_create_simple(pool, NULL, &mutex); 222 if (rc != PJ_SUCCESS) { 223 PJ_LOG(3,("", "...error: unable to create mutex", rc)); 224 return -20; 225 } 226 227 /* 228 rc = pj_atomic_create(pool, 0, &atom); 178 rc = pj_atomic_create(pool, 0, &totalBytes); 229 179 if (rc != PJ_SUCCESS) { 230 180 PJ_LOG(3,("", "...error: unable to create atomic variable", rc)); 231 181 return -30; 232 182 } 233 */234 183 235 184 PJ_LOG(3,("", "Echo client started")); … … 237 186 ECHO_SERVER_ADDRESS, ECHO_SERVER_START_PORT)); 238 187 PJ_LOG(3,("", " Press Ctrl-C to exit")); 239 240 pj_gettimeofday(&first_report);241 first_report.sec += 2;242 188 243 189 for (i=0; i<ECHO_CLIENT_MAX_THREADS; ++i) { … … 251 197 } 252 198 199 last_received = 0; 200 pj_get_timestamp(&last_report); 201 253 202 for (;;) { 254 pj_uint32_t bw; 255 256 pj_sem_wait(sem); 257 258 pj_mutex_lock(mutex); 259 bw = total_bw; 260 total_bw = 0; 261 total_poster = 0; 262 pj_mutex_unlock(mutex); 203 pj_timestamp now; 204 unsigned long received, cur_received; 205 unsigned msec; 206 pj_highprec_t bw; 207 pj_time_val elapsed; 208 unsigned bw32; 209 210 pj_thread_sleep(1000); 211 212 pj_get_timestamp(&now); 213 elapsed = pj_elapsed_time(&last_report, &now); 214 msec = PJ_TIME_VAL_MSEC(elapsed); 215 216 received = pj_atomic_get(totalBytes); 217 cur_received = received - last_received; 218 219 bw = cur_received; 220 pj_highprec_mul(bw, 1000); 221 pj_highprec_div(bw, msec); 222 223 bw32 = (unsigned)bw; 224 225 last_report = now; 226 last_received = received; 263 227 264 228 PJ_LOG(3,("", "...%d threads, total bandwidth: %d KB/s", 265 ECHO_CLIENT_MAX_THREADS, bw /1000));229 ECHO_CLIENT_MAX_THREADS, bw32/1000)); 266 230 } 267 231 -
pjproject/main/pjlib/src/pjlib-test/test.h
r4 r5 45 45 #define ECHO_SERVER_DURATION_MSEC (60*60*1000) 46 46 47 #define ECHO_CLIENT_MAX_THREADS 247 #define ECHO_CLIENT_MAX_THREADS 6 48 48 49 49 PJ_BEGIN_DECL
Note: See TracChangeset
for help on using the changeset viewer.