Changeset 2 for pjproject/main/pjlib/src/pj/os_core_unix.c
- Timestamp:
- Nov 1, 2005 4:42:51 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/main/pjlib/src/pj/os_core_unix.c
r1 r2 175 175 #if PJ_HAS_THREADS 176 176 char stack_ptr; 177 pj_status_t rc; 177 178 pj_thread_t *thread = (pj_thread_t *)desc; 178 179 pj_str_t thread_name = pj_str((char*)cstr_thread_name); … … 191 192 192 193 /* Initialize and set the thread entry. */ 193 pj_memset(desc, 0, sizeof( pj_thread_desc));194 pj_memset(desc, 0, sizeof(struct pj_thread_t)); 194 195 thread->thread = pthread_self(); 195 196 … … 199 200 pj_sprintf(thread->obj_name, "thr%p", (void*)thread->thread); 200 201 201 pj_thread_local_set(thread_tls_id, thread); 202 rc = pj_thread_local_set(thread_tls_id, thread); 203 if (rc != PJ_SUCCESS) 204 return rc; 202 205 203 206 #if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0 … … 214 217 pj_thread_t *thread = (pj_thread_t*)desc; 215 218 *ptr_thread = thread; 216 return SUCCESS;219 return PJ_SUCCESS; 217 220 #endif 218 221 } … … 231 234 return rc; 232 235 } 233 return pj_thread_register("thr%p", ( pj_uint8_t*)&main_thread, &dummy);236 return pj_thread_register("thr%p", (long*)&main_thread, &dummy); 234 237 #else 235 238 PJ_LOG(2,(THIS_FILE, "Thread init error. Threading is not enabled!")); … … 248 251 pj_thread_t *rec = param; 249 252 void *result; 253 pj_status_t rc; 250 254 251 255 #if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0 … … 254 258 255 259 /* Set current thread id. */ 256 pj_thread_local_set(thread_tls_id, rec); 260 rc = pj_thread_local_set(thread_tls_id, rec); 261 if (rc != PJ_SUCCESS) { 262 pj_assert(!"Thread TLS ID is not set (pj_init() error?)"); 263 } 257 264 258 265 /* Check if suspension is required. */ … … 660 667 * pj_thread_local_set() 661 668 */ 662 PJ_DEF( void) pj_thread_local_set(long index, void *value)669 PJ_DEF(pj_status_t) pj_thread_local_set(long index, void *value) 663 670 { 664 671 //Can't check stack because this function is called in the … … 666 673 //PJ_CHECK_STACK(); 667 674 #if PJ_HAS_THREADS 668 pthread_setspecific(index, value); 675 int rc=pthread_setspecific(index, value); 676 return rc==0 ? PJ_SUCCESS : PJ_RETURN_OS_ERROR(rc); 669 677 #else 670 678 pj_assert(index >= 0 && index < MAX_THREADS); 671 679 tls[index] = value; 680 return PJ_SUCCESS; 672 681 #endif 673 682 } … … 706 715 { 707 716 #if PJ_HAS_THREADS 708 PJ_UNUSED_ARG(type); 709 710 PJ_CHECK_STACK(); 717 pthread_mutexattr_t attr; 718 int rc; 719 720 PJ_CHECK_STACK(); 721 722 pthread_mutexattr_init(&attr); 711 723 712 724 if (type == PJ_MUTEX_SIMPLE) { 713 pthread_mutex_t the_mutex = PTHREAD_MUTEX_INITIALIZER; 714 mutex->mutex = the_mutex; 725 #if defined(PJ_LINUX) && PJ_LINUX!=0 726 rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_FAST_NP); 727 #else 728 rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); 729 #endif 715 730 } else { 716 pthread_mutex_t the_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; 717 mutex->mutex = the_mutex; 731 #if defined(PJ_LINUX) && PJ_LINUX!=0 732 rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); 733 #else 734 rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); 735 #endif 736 } 737 738 if (rc != 0) { 739 return PJ_RETURN_OS_ERROR(rc); 740 } 741 742 rc = pthread_mutex_init(&mutex->mutex, &attr); 743 if (rc != 0) { 744 return PJ_RETURN_OS_ERROR(rc); 718 745 } 719 746
Note: See TracChangeset
for help on using the changeset viewer.