Changeset fb7f7d22b070fbe51775f102cc66bd84b04e44b4
- Timestamp:
- 05/10/08 22:22:19
(6 days ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1210450939 +0300
- git-parent:
[7793bdcbd3a77917c4dec40c737a8b04017430c5]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1210450933 +0300
- Message:
The TLS also needs to be cleaned up... should fix #1576
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r9a719ad |
rfb7f7d2 |
|
| 171 | 171 | VLC_EXPORT( int, __vlc_cond_init, ( vlc_cond_t * ) ); |
|---|
| 172 | 172 | VLC_EXPORT( void, __vlc_cond_destroy, ( const char *, int, vlc_cond_t * ) ); |
|---|
| 173 | | VLC_EXPORT( int, __vlc_threadvar_create, (vlc_threadvar_t * ) ); |
|---|
| | 173 | VLC_EXPORT( int, vlc_threadvar_create, (vlc_threadvar_t * , void (*) (void *) ) ); |
|---|
| | 174 | VLC_EXPORT( void, vlc_threadvar_delete, (vlc_threadvar_t *) ); |
|---|
| 174 | 175 | VLC_EXPORT( int, __vlc_thread_create, ( vlc_object_t *, const char *, int, const char *, void * ( * ) ( void * ), int, bool ) ); |
|---|
| 175 | 176 | VLC_EXPORT( int, __vlc_thread_set_priority, ( vlc_object_t *, const char *, int, int ) ); |
|---|
| … | … | |
| 435 | 436 | |
|---|
| 436 | 437 | /***************************************************************************** |
|---|
| 437 | | * vlc_threadvar_create: create a thread-local variable |
|---|
| 438 | | *****************************************************************************/ |
|---|
| 439 | | #define vlc_threadvar_create( PTHIS, P_TLS ) \ |
|---|
| 440 | | __vlc_threadvar_create( P_TLS ) |
|---|
| 441 | | |
|---|
| 442 | | /***************************************************************************** |
|---|
| 443 | 438 | * vlc_threadvar_set: create: set the value of a thread-local variable |
|---|
| 444 | 439 | *****************************************************************************/ |
|---|
| rcdd5175 |
rfb7f7d2 |
|
| 47 | 47 | void vlc_threads_end( void ); |
|---|
| 48 | 48 | |
|---|
| | 49 | /* |
|---|
| | 50 | * CPU capabilities |
|---|
| | 51 | */ |
|---|
| | 52 | extern uint32_t cpu_flags; |
|---|
| | 53 | uint32_t CPUCapabilities( void ); |
|---|
| | 54 | |
|---|
| | 55 | /* |
|---|
| | 56 | * Message/logging stuff |
|---|
| | 57 | */ |
|---|
| | 58 | |
|---|
| | 59 | typedef struct msg_queue_t |
|---|
| | 60 | { |
|---|
| | 61 | /** Message queue lock */ |
|---|
| | 62 | vlc_mutex_t lock; |
|---|
| | 63 | bool b_overflow; |
|---|
| | 64 | |
|---|
| | 65 | /* Message queue */ |
|---|
| | 66 | msg_item_t msg[VLC_MSG_QSIZE]; /**< message queue */ |
|---|
| | 67 | int i_start; |
|---|
| | 68 | int i_stop; |
|---|
| | 69 | |
|---|
| | 70 | /* Subscribers */ |
|---|
| | 71 | int i_sub; |
|---|
| | 72 | msg_subscription_t **pp_sub; |
|---|
| | 73 | |
|---|
| | 74 | /* Logfile for WinCE */ |
|---|
| | 75 | #ifdef UNDER_CE |
|---|
| | 76 | FILE *logfile; |
|---|
| | 77 | #endif |
|---|
| | 78 | } msg_queue_t; |
|---|
| | 79 | |
|---|
| | 80 | /** |
|---|
| | 81 | * Store all data required by messages interfaces. |
|---|
| | 82 | */ |
|---|
| | 83 | typedef struct msg_bank_t |
|---|
| | 84 | { |
|---|
| | 85 | vlc_mutex_t lock; |
|---|
| | 86 | msg_queue_t queue; |
|---|
| | 87 | } msg_bank_t; |
|---|
| | 88 | |
|---|
| | 89 | void msg_Create (libvlc_int_t *); |
|---|
| | 90 | void msg_Flush (libvlc_int_t *); |
|---|
| | 91 | void msg_Destroy (libvlc_int_t *); |
|---|
| | 92 | |
|---|
| | 93 | /** Internal message stack context */ |
|---|
| | 94 | typedef struct |
|---|
| | 95 | { |
|---|
| | 96 | int i_code; |
|---|
| | 97 | char * psz_message; |
|---|
| | 98 | } msg_context_t; |
|---|
| | 99 | |
|---|
| | 100 | void msg_StackSet ( int, const char*, ... ); |
|---|
| | 101 | void msg_StackAdd ( const char*, ... ); |
|---|
| | 102 | const char* msg_StackMsg ( void ); |
|---|
| 49 | 103 | /** The global thread var for msg stack context |
|---|
| 50 | 104 | * We store this as a static global variable so we don't need a vlc_object_t |
|---|
| … | … | |
| 53 | 107 | * the very beginning of the universe */ |
|---|
| 54 | 108 | extern vlc_threadvar_t msg_context_global_key; |
|---|
| 55 | | |
|---|
| 56 | | /* |
|---|
| 57 | | * CPU capabilities |
|---|
| 58 | | */ |
|---|
| 59 | | extern uint32_t cpu_flags; |
|---|
| 60 | | uint32_t CPUCapabilities( void ); |
|---|
| 61 | | |
|---|
| 62 | | /* |
|---|
| 63 | | * Message/logging stuff |
|---|
| 64 | | */ |
|---|
| 65 | | |
|---|
| 66 | | typedef struct msg_queue_t |
|---|
| 67 | | { |
|---|
| 68 | | /** Message queue lock */ |
|---|
| 69 | | vlc_mutex_t lock; |
|---|
| 70 | | bool b_overflow; |
|---|
| 71 | | |
|---|
| 72 | | /* Message queue */ |
|---|
| 73 | | msg_item_t msg[VLC_MSG_QSIZE]; /**< message queue */ |
|---|
| 74 | | int i_start; |
|---|
| 75 | | int i_stop; |
|---|
| 76 | | |
|---|
| 77 | | /* Subscribers */ |
|---|
| 78 | | int i_sub; |
|---|
| 79 | | msg_subscription_t **pp_sub; |
|---|
| 80 | | |
|---|
| 81 | | /* Logfile for WinCE */ |
|---|
| 82 | | #ifdef UNDER_CE |
|---|
| 83 | | FILE *logfile; |
|---|
| 84 | | #endif |
|---|
| 85 | | } msg_queue_t; |
|---|
| 86 | | |
|---|
| 87 | | /** |
|---|
| 88 | | * Store all data required by messages interfaces. |
|---|
| 89 | | */ |
|---|
| 90 | | typedef struct msg_bank_t |
|---|
| 91 | | { |
|---|
| 92 | | vlc_mutex_t lock; |
|---|
| 93 | | msg_queue_t queue; |
|---|
| 94 | | } msg_bank_t; |
|---|
| 95 | | |
|---|
| 96 | | void msg_Create (libvlc_int_t *); |
|---|
| 97 | | void msg_Flush (libvlc_int_t *); |
|---|
| 98 | | void msg_Destroy (libvlc_int_t *); |
|---|
| 99 | | |
|---|
| 100 | | /** Internal message stack context */ |
|---|
| 101 | | typedef struct |
|---|
| 102 | | { |
|---|
| 103 | | int i_code; |
|---|
| 104 | | char * psz_message; |
|---|
| 105 | | } msg_context_t; |
|---|
| 106 | | |
|---|
| 107 | | void msg_StackSet ( int, const char*, ... ); |
|---|
| 108 | | void msg_StackAdd ( const char*, ... ); |
|---|
| 109 | | const char* msg_StackMsg ( void ); |
|---|
| | 109 | void msg_StackDestroy (void *); |
|---|
| 110 | 110 | |
|---|
| 111 | 111 | /* |
|---|
| r62ba576 |
rfb7f7d2 |
|
| 456 | 456 | __vlc_thread_ready |
|---|
| 457 | 457 | __vlc_thread_set_priority |
|---|
| 458 | | __vlc_threadvar_create |
|---|
| | 458 | vlc_threadvar_create |
|---|
| | 459 | vlc_threadvar_delete |
|---|
| 459 | 460 | vlc_ureduce |
|---|
| 460 | 461 | vlc_vasprintf |
|---|
| r7793bdc |
rfb7f7d2 |
|
| 615 | 615 | } |
|---|
| 616 | 616 | |
|---|
| | 617 | void msg_StackDestroy (void *data) |
|---|
| | 618 | { |
|---|
| | 619 | msg_context_t *p_ctx = data; |
|---|
| | 620 | |
|---|
| | 621 | free (p_ctx->psz_message); |
|---|
| | 622 | free (p_ctx); |
|---|
| | 623 | } |
|---|
| | 624 | |
|---|
| 617 | 625 | void msg_StackSet( int i_code, const char *psz_message, ... ) |
|---|
| 618 | 626 | { |
|---|
| … | … | |
| 622 | 630 | if( p_ctx == NULL ) |
|---|
| 623 | 631 | return; |
|---|
| | 632 | free( p_ctx->psz_message ); |
|---|
| 624 | 633 | |
|---|
| 625 | 634 | va_start( ap, psz_message ); |
|---|
| 626 | | free( p_ctx->psz_message ); |
|---|
| 627 | | |
|---|
| 628 | 635 | if( vasprintf( &p_ctx->psz_message, psz_message, ap ) == -1 ) |
|---|
| 629 | 636 | p_ctx->psz_message = NULL; |
|---|
| r9a719ad |
rfb7f7d2 |
|
| 146 | 146 | |
|---|
| 147 | 147 | /* We should be safe now. Do all the initialization stuff we want. */ |
|---|
| 148 | | vlc_threadvar_create( p_root, &msg_context_global_key ); |
|---|
| | 148 | vlc_threadvar_create( &msg_context_global_key, msg_StackDestroy ); |
|---|
| 149 | 149 | } |
|---|
| 150 | 150 | i_initializations++; |
|---|
| … | … | |
| 174 | 174 | |
|---|
| 175 | 175 | if( i_initializations == 1 ) |
|---|
| | 176 | { |
|---|
| 176 | 177 | vlc_object_release( p_root ); |
|---|
| | 178 | vlc_threadvar_delete( &msg_context_global_key ); |
|---|
| | 179 | } |
|---|
| 177 | 180 | i_initializations--; |
|---|
| 178 | 181 | |
|---|
| … | … | |
| 375 | 378 | * vlc_tls_create: create a thread-local variable |
|---|
| 376 | 379 | *****************************************************************************/ |
|---|
| 377 | | int __vlc_threadvar_create( vlc_threadvar_t *p_tls ) |
|---|
| 378 | | { |
|---|
| 379 | | int i_ret = -1; |
|---|
| 380 | | |
|---|
| 381 | | #if defined( LIBVLC_USE_PTHREAD ) |
|---|
| 382 | | i_ret = pthread_key_create( p_tls, NULL ); |
|---|
| | 380 | int vlc_threadvar_create( vlc_threadvar_t *p_tls, void (*destr) (void *) ) |
|---|
| | 381 | { |
|---|
| | 382 | int i_ret; |
|---|
| | 383 | |
|---|
| | 384 | #if defined( LIBVLC_USE_PTHREAD ) |
|---|
| | 385 | i_ret = pthread_key_create( p_tls, destr ); |
|---|
| 383 | 386 | #elif defined( UNDER_CE ) |
|---|
| | 387 | i_ret = ENOSYS; |
|---|
| 384 | 388 | #elif defined( WIN32 ) |
|---|
| 385 | 389 | *p_tls = TlsAlloc(); |
|---|
| … | … | |
| 389 | 393 | #endif |
|---|
| 390 | 394 | return i_ret; |
|---|
| | 395 | } |
|---|
| | 396 | |
|---|
| | 397 | void vlc_threadvar_delete (vlc_threadvar_t *p_tls) |
|---|
| | 398 | { |
|---|
| | 399 | #if defined( LIBVLC_USE_PTHREAD ) |
|---|
| | 400 | pthread_key_delete (p_tls); |
|---|
| | 401 | #elif defined( UNDER_CE ) |
|---|
| | 402 | #elif defined( WIN32 ) |
|---|
| | 403 | TlsFree (*p_tls); |
|---|
| | 404 | #else |
|---|
| | 405 | # error Unimplemented! |
|---|
| | 406 | #endif |
|---|
| 391 | 407 | } |
|---|
| 392 | 408 | |
|---|