Changeset 463b756d19d348b4a8d39b293e370b18585a4ef4
- Timestamp:
- 23/04/08 20:53:10
(6 months ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1208976790 +0300
- git-parent:
[63baa1df69663f280e010d58e5fdc5f740e3a4c0]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1208976790 +0300
- Message:
Simplify threading code a bit
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r63baa1d |
r463b756 |
|
| 39 | 39 | #elif defined( WIN32 ) |
|---|
| 40 | 40 | # include <process.h> /* Win32 API */ |
|---|
| | 41 | # include <errno.h> |
|---|
| 41 | 42 | |
|---|
| 42 | 43 | #elif defined( HAVE_KERNEL_SCHEDULER_H ) /* BeOS */ |
|---|
| … | … | |
| 147 | 148 | } vlc_cond_t; |
|---|
| 148 | 149 | |
|---|
| 149 | | typedef struct |
|---|
| 150 | | { |
|---|
| 151 | | DWORD handle; |
|---|
| 152 | | } vlc_threadvar_t; |
|---|
| | 150 | typedef DWORD vlc_threadvar_t; |
|---|
| 153 | 151 | |
|---|
| 154 | 152 | #elif defined( HAVE_KERNEL_SCHEDULER_H ) |
|---|
| … | … | |
| 178 | 176 | #else |
|---|
| 179 | 177 | typedef pthread_t vlc_thread_t; |
|---|
| 180 | | typedef struct |
|---|
| 181 | | { |
|---|
| 182 | | pthread_mutex_t mutex; |
|---|
| 183 | | } vlc_mutex_t; |
|---|
| 184 | | typedef struct |
|---|
| 185 | | { |
|---|
| 186 | | pthread_cond_t cond; |
|---|
| 187 | | } vlc_cond_t; |
|---|
| 188 | | |
|---|
| 189 | | typedef struct |
|---|
| 190 | | { |
|---|
| 191 | | pthread_key_t handle; |
|---|
| 192 | | } vlc_threadvar_t; |
|---|
| | 178 | typedef pthread_mutex_t vlc_mutex_t; |
|---|
| | 179 | typedef pthread_cond_t vlc_cond_t; |
|---|
| | 180 | typedef pthread_key_t vlc_threadvar_t; |
|---|
| 193 | 181 | |
|---|
| 194 | 182 | #endif |
|---|
| r63baa1d |
r463b756 |
|
| 112 | 112 | #elif defined(LIBVLC_USE_PTHREAD) |
|---|
| 113 | 113 | # define vlc_assert_locked( m ) \ |
|---|
| 114 | | assert (pthread_mutex_lock (&((m)->mutex)) == EDEADLK) |
|---|
| 115 | | int val = pthread_mutex_lock( &p_mutex->mutex ); |
|---|
| | 114 | assert (pthread_mutex_lock (m) == EDEADLK) |
|---|
| | 115 | int val = pthread_mutex_lock( p_mutex ); |
|---|
| 116 | 116 | VLC_THREAD_ASSERT ("locking mutex"); |
|---|
| 117 | 117 | |
|---|
| … | … | |
| 149 | 149 | |
|---|
| 150 | 150 | #elif defined(LIBVLC_USE_PTHREAD) |
|---|
| 151 | | int val = pthread_mutex_unlock( &p_mutex->mutex ); |
|---|
| | 151 | int val = pthread_mutex_unlock( p_mutex ); |
|---|
| 152 | 152 | VLC_THREAD_ASSERT ("unlocking mutex"); |
|---|
| 153 | 153 | |
|---|
| … | … | |
| 249 | 249 | |
|---|
| 250 | 250 | #elif defined(LIBVLC_USE_PTHREAD) |
|---|
| 251 | | int val = pthread_cond_signal( &p_condvar->cond ); |
|---|
| | 251 | int val = pthread_cond_signal( p_condvar ); |
|---|
| 252 | 252 | VLC_THREAD_ASSERT ("signaling condition variable"); |
|---|
| 253 | 253 | |
|---|
| … | … | |
| 357 | 357 | |
|---|
| 358 | 358 | #elif defined(LIBVLC_USE_PTHREAD) |
|---|
| 359 | | int val = pthread_cond_wait( &p_condvar->cond, &p_mutex->mutex ); |
|---|
| | 359 | int val = pthread_cond_wait( p_condvar, p_mutex ); |
|---|
| 360 | 360 | VLC_THREAD_ASSERT ("waiting on condition"); |
|---|
| 361 | 361 | |
|---|
| … | … | |
| 490 | 490 | struct timespec ts = { d.quot, d.rem * 1000 }; |
|---|
| 491 | 491 | |
|---|
| 492 | | int val = pthread_cond_timedwait (&p_condvar->cond, &p_mutex->mutex, &ts); |
|---|
| | 492 | int val = pthread_cond_timedwait (p_condvar, p_mutex, &ts); |
|---|
| 493 | 493 | if (val == ETIMEDOUT) |
|---|
| 494 | 494 | return ETIMEDOUT; /* this error is perfectly normal */ |
|---|
| … | … | |
| 520 | 520 | |
|---|
| 521 | 521 | #if defined( HAVE_KERNEL_SCHEDULER_H ) |
|---|
| 522 | | return -1; |
|---|
| | 522 | i_ret = EINVAL; |
|---|
| 523 | 523 | |
|---|
| 524 | 524 | #elif defined( UNDER_CE ) || defined( WIN32 ) |
|---|
| 525 | | i_ret = ( TlsSetValue( p_tls->handle, p_value ) != 0 ); |
|---|
| | 525 | i_ret = TlsSetValue( *p_tls, p_value ) ? EINVAL : 0; |
|---|
| 526 | 526 | |
|---|
| 527 | 527 | #elif defined(LIBVLC_USE_PTHREAD) |
|---|
| 528 | | i_ret = pthread_setspecific( p_tls->handle, p_value ); |
|---|
| | 528 | i_ret = pthread_setspecific( *p_tls, p_value ); |
|---|
| 529 | 529 | |
|---|
| 530 | 530 | #endif |
|---|
| … | … | |
| 538 | 538 | static inline void* vlc_threadvar_get( vlc_threadvar_t * p_tls ) |
|---|
| 539 | 539 | { |
|---|
| 540 | | void* p_ret; |
|---|
| | 540 | void *p_ret; |
|---|
| 541 | 541 | |
|---|
| 542 | 542 | #if defined( HAVE_KERNEL_SCHEDULER_H ) |
|---|
| 543 | 543 | p_ret = NULL; |
|---|
| | 544 | |
|---|
| 544 | 545 | #elif defined( UNDER_CE ) || defined( WIN32 ) |
|---|
| 545 | | p_ret = TlsGetValue( p_tls->handle ); |
|---|
| | 546 | p_ret = TlsGetValue( *p_tls ); |
|---|
| 546 | 547 | |
|---|
| 547 | 548 | #elif defined(LIBVLC_USE_PTHREAD) |
|---|
| 548 | | p_ret = pthread_getspecific( p_tls->handle ); |
|---|
| | 549 | p_ret = pthread_getspecific( *p_tls ); |
|---|
| 549 | 550 | |
|---|
| 550 | 551 | #endif |
|---|
| r63baa1d |
r463b756 |
|
| 288 | 288 | |
|---|
| 289 | 289 | #elif defined( LIBVLC_USE_PTHREAD ) |
|---|
| | 290 | pthread_mutexattr_t attr; |
|---|
| | 291 | int i_result; |
|---|
| | 292 | |
|---|
| | 293 | pthread_mutexattr_init( &attr ); |
|---|
| | 294 | |
|---|
| 290 | 295 | # ifndef NDEBUG |
|---|
| 291 | | { |
|---|
| 292 | | /* Create error-checking mutex to detect problems more easily. */ |
|---|
| 293 | | pthread_mutexattr_t attr; |
|---|
| 294 | | int i_result; |
|---|
| 295 | | |
|---|
| 296 | | pthread_mutexattr_init( &attr ); |
|---|
| 297 | | # if defined(SYS_LINUX) |
|---|
| 298 | | pthread_mutexattr_setkind_np( &attr, PTHREAD_MUTEX_ERRORCHECK_NP ); |
|---|
| 299 | | # else |
|---|
| 300 | | pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_ERRORCHECK ); |
|---|
| 301 | | # endif |
|---|
| 302 | | |
|---|
| 303 | | i_result = pthread_mutex_init( &p_mutex->mutex, &attr ); |
|---|
| 304 | | pthread_mutexattr_destroy( &attr ); |
|---|
| 305 | | return( i_result ); |
|---|
| 306 | | } |
|---|
| 307 | | # endif /* NDEBUG */ |
|---|
| 308 | | return pthread_mutex_init( &p_mutex->mutex, NULL ); |
|---|
| 309 | | |
|---|
| | 296 | /* Create error-checking mutex to detect problems more easily. */ |
|---|
| | 297 | # if defined(SYS_LINUX) |
|---|
| | 298 | pthread_mutexattr_setkind_np( &attr, PTHREAD_MUTEX_ERRORCHECK_NP ); |
|---|
| | 299 | # else |
|---|
| | 300 | pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_ERRORCHECK ); |
|---|
| | 301 | # endif |
|---|
| | 302 | # endif |
|---|
| | 303 | i_result = pthread_mutex_init( p_mutex, &attr ); |
|---|
| | 304 | pthread_mutexattr_destroy( &attr ); |
|---|
| | 305 | return i_result; |
|---|
| 310 | 306 | #endif |
|---|
| 311 | 307 | } |
|---|
| … | … | |
| 334 | 330 | # endif |
|---|
| 335 | 331 | pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE ); |
|---|
| 336 | | i_result = pthread_mutex_init( &p_mutex->mutex, &attr ); |
|---|
| | 332 | i_result = pthread_mutex_init( p_mutex, &attr ); |
|---|
| 337 | 333 | pthread_mutexattr_destroy( &attr ); |
|---|
| 338 | 334 | return( i_result ); |
|---|
| … | … | |
| 368 | 364 | |
|---|
| 369 | 365 | #elif defined( LIBVLC_USE_PTHREAD ) |
|---|
| 370 | | int val = pthread_mutex_destroy( &p_mutex->mutex ); |
|---|
| | 366 | int val = pthread_mutex_destroy( p_mutex ); |
|---|
| 371 | 367 | VLC_THREAD_ASSERT ("destroying mutex"); |
|---|
| 372 | 368 | |
|---|
| … | … | |
| 459 | 455 | # endif |
|---|
| 460 | 456 | |
|---|
| 461 | | ret = pthread_cond_init (&p_condvar->cond, &attr); |
|---|
| | 457 | ret = pthread_cond_init (p_condvar, &attr); |
|---|
| 462 | 458 | pthread_condattr_destroy (&attr); |
|---|
| 463 | 459 | return ret; |
|---|
| … | … | |
| 494 | 490 | |
|---|
| 495 | 491 | #elif defined( LIBVLC_USE_PTHREAD ) |
|---|
| 496 | | int val = pthread_cond_destroy( &p_condvar->cond ); |
|---|
| | 492 | int val = pthread_cond_destroy( p_condvar ); |
|---|
| 497 | 493 | VLC_THREAD_ASSERT ("destroying condition"); |
|---|
| 498 | 494 | |
|---|
| … | … | |
| 511 | 507 | #elif defined( UNDER_CE ) || defined( WIN32 ) |
|---|
| 512 | 508 | #elif defined( WIN32 ) |
|---|
| 513 | | p_tls->handle = TlsAlloc(); |
|---|
| 514 | | i_ret = !( p_tls->handle == 0xFFFFFFFF ); |
|---|
| 515 | | |
|---|
| 516 | | #elif defined( LIBVLC_USE_PTHREAD ) |
|---|
| 517 | | i_ret = pthread_key_create( &p_tls->handle, NULL ); |
|---|
| | 509 | *p_tls = TlsAlloc(); |
|---|
| | 510 | i_ret = (*p_tls == INVALID_HANDLE_VALUE) ? EAGAIN : 0; |
|---|
| | 511 | |
|---|
| | 512 | #elif defined( LIBVLC_USE_PTHREAD ) |
|---|
| | 513 | i_ret = pthread_key_create( p_tls, NULL ); |
|---|
| 518 | 514 | #endif |
|---|
| 519 | 515 | return i_ret; |
|---|