Changeset 1746fdda5a2bc062d52a3b8a30d9d1d6518e64b4
- Timestamp:
- 28/05/08 20:52:22
(5 months ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1212000742 +0300
- git-parent:
[94f55c6038a3f727f3de61099167a44dfd9f2cd6]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1212000737 +0300
- Message:
vlc_threadobj(): returns the object nesting the current thread
Also fix the threads entry point prototype on Windows.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r0d37c5b |
r1746fdd |
|
| 46 | 46 | int vlc_threads_init( void ); |
|---|
| 47 | 47 | void vlc_threads_end( void ); |
|---|
| | 48 | vlc_object_t *vlc_threadobj (void); |
|---|
| 48 | 49 | |
|---|
| 49 | 50 | /* |
|---|
| r2e7d3d7 |
r1746fdd |
|
| 86 | 86 | * Local structure lock |
|---|
| 87 | 87 | *****************************************************************************/ |
|---|
| 88 | | static vlc_mutex_t structure_lock; |
|---|
| | 88 | static vlc_mutex_t structure_lock; |
|---|
| | 89 | static vlc_threadvar_t thread_object; |
|---|
| 89 | 90 | |
|---|
| 90 | 91 | void *vlc_custom_create( vlc_object_t *p_this, size_t i_size, |
|---|
| r5143683 |
r1746fdd |
|
| 63 | 63 | } |
|---|
| 64 | 64 | |
|---|
| | 65 | /** |
|---|
| | 66 | * Object running the current thread |
|---|
| | 67 | */ |
|---|
| | 68 | static vlc_threadvar_t thread_object_key; |
|---|
| | 69 | |
|---|
| | 70 | vlc_object_t *vlc_threadobj (void) |
|---|
| | 71 | { |
|---|
| | 72 | return vlc_threadvar_get (&thread_object_key); |
|---|
| | 73 | } |
|---|
| 65 | 74 | |
|---|
| 66 | 75 | vlc_threadvar_t msg_context_global_key; |
|---|
| … | … | |
| 151 | 160 | |
|---|
| 152 | 161 | /* We should be safe now. Do all the initialization stuff we want. */ |
|---|
| | 162 | vlc_threadvar_create( &thread_object_key, NULL ); |
|---|
| 153 | 163 | vlc_threadvar_create( &msg_context_global_key, msg_StackDestroy ); |
|---|
| 154 | 164 | } |
|---|
| … | … | |
| 182 | 192 | vlc_object_release( p_root ); |
|---|
| 183 | 193 | vlc_threadvar_delete( &msg_context_global_key ); |
|---|
| | 194 | vlc_threadvar_delete( &thread_object_key ); |
|---|
| 184 | 195 | } |
|---|
| 185 | 196 | i_initializations--; |
|---|
| … | … | |
| 412 | 423 | } |
|---|
| 413 | 424 | |
|---|
| | 425 | struct vlc_thread_boot |
|---|
| | 426 | { |
|---|
| | 427 | void * (*entry) (void *); |
|---|
| | 428 | vlc_object_t *object; |
|---|
| | 429 | }; |
|---|
| | 430 | |
|---|
| | 431 | #if defined (LIBVLC_USE_PTHREAD) |
|---|
| | 432 | # define THREAD_RTYPE void * |
|---|
| | 433 | # define THREAD_RVAL NULL |
|---|
| | 434 | #elif defined (WIN32) |
|---|
| | 435 | # define THREAD_RTYPE __stdcall unsigned |
|---|
| | 436 | # define THREAD_RVAL 0 |
|---|
| | 437 | #endif |
|---|
| | 438 | |
|---|
| | 439 | static THREAD_RTYPE thread_entry (void *data) |
|---|
| | 440 | { |
|---|
| | 441 | vlc_object_t *obj = ((struct vlc_thread_boot *)data)->object; |
|---|
| | 442 | void *(*func) (void *) = ((struct vlc_thread_boot *)data)->entry; |
|---|
| | 443 | |
|---|
| | 444 | free (data); |
|---|
| | 445 | vlc_threadvar_set (&thread_object_key, obj); |
|---|
| | 446 | msg_Dbg (obj, "thread started"); |
|---|
| | 447 | func (obj); |
|---|
| | 448 | msg_Dbg (obj, "thread ended"); |
|---|
| | 449 | return THREAD_RVAL; |
|---|
| | 450 | } |
|---|
| | 451 | |
|---|
| 414 | 452 | /***************************************************************************** |
|---|
| 415 | 453 | * vlc_thread_create: create a thread, inner version |
|---|
| … | … | |
| 423 | 461 | { |
|---|
| 424 | 462 | int i_ret; |
|---|
| 425 | | void *p_data = (void *)p_this; |
|---|
| 426 | 463 | vlc_object_internals_t *p_priv = vlc_internals( p_this ); |
|---|
| 427 | 464 | |
|---|
| | 465 | struct vlc_thread_boot *boot = malloc (sizeof (*boot)); |
|---|
| | 466 | if (boot == NULL) |
|---|
| | 467 | return errno; |
|---|
| | 468 | boot->entry = func; |
|---|
| | 469 | boot->object = p_this; |
|---|
| | 470 | |
|---|
| 428 | 471 | vlc_mutex_lock( &p_this->object_lock ); |
|---|
| 429 | 472 | |
|---|
| 430 | 473 | #if defined( LIBVLC_USE_PTHREAD ) |
|---|
| 431 | | i_ret = pthread_create( &p_priv->thread_id, NULL, func, p_data ); |
|---|
| | 474 | i_ret = pthread_create( &p_priv->thread_id, NULL, thread_entry, boot ); |
|---|
| 432 | 475 | |
|---|
| 433 | 476 | #ifndef __APPLE__ |
|---|
| … | … | |
| 472 | 515 | * Knowledge Base, article 104641) */ |
|---|
| 473 | 516 | #if defined( UNDER_CE ) |
|---|
| 474 | | HANDLE hThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)func, |
|---|
| 475 | | (LPVOID)p_data, CREATE_SUSPENDED, |
|---|
| | 517 | HANDLE hThread = CreateThread( NULL, 0, thread_entry, |
|---|
| | 518 | (LPVOID)boot, CREATE_SUSPENDED, |
|---|
| 476 | 519 | NULL ); |
|---|
| 477 | 520 | #else |
|---|
| 478 | 521 | HANDLE hThread = (HANDLE)(uintptr_t) |
|---|
| 479 | | _beginthreadex( NULL, 0, (LPTHREAD_START_ROUTINE)func, |
|---|
| 480 | | (void *)p_data, CREATE_SUSPENDED, NULL ); |
|---|
| | 522 | _beginthreadex( NULL, 0, thread_entry, boot, |
|---|
| | 523 | CREATE_SUSPENDED, NULL ); |
|---|
| 481 | 524 | #endif |
|---|
| 482 | 525 | p_priv->thread_id = hThread; |
|---|
| … | … | |
| 496 | 539 | |
|---|
| 497 | 540 | #elif defined( HAVE_KERNEL_SCHEDULER_H ) |
|---|
| 498 | | p_priv->thread_id = spawn_thread( (thread_func)func, psz_name, |
|---|
| | 541 | p_priv->thread_id = spawn_thread( (thread_func)thread_entry, psz_name, |
|---|
| 499 | 542 | i_priority, p_data ); |
|---|
| 500 | 543 | i_ret = resume_thread( p_priv->thread_id ); |
|---|