Changeset c07b1d0c2b8d9ec8afb3e2d1052b71b98baf41b7
- Timestamp:
- 05/03/08 11:24:05
(4 months ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1209806645 +0300
- git-parent:
[4db976d9a6c11ddcc0ec438c836bdedf54137fa3]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1209806471 +0300
- Message:
Hide global object within the thread and object subsystem
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r4dc02f7 |
rc07b1d0 |
|
| 52 | 52 | |
|---|
| 53 | 53 | /***************************************************************************** |
|---|
| 54 | | * vlc_threads_init: initialize threads system |
|---|
| 55 | | *****************************************************************************/ |
|---|
| 56 | | #define vlc_threads_init( P_THIS ) \ |
|---|
| 57 | | __vlc_threads_init( VLC_OBJECT(P_THIS) ) |
|---|
| 58 | | |
|---|
| 59 | | /***************************************************************************** |
|---|
| 60 | | * vlc_threads_end: deinitialize threads system |
|---|
| 61 | | *****************************************************************************/ |
|---|
| 62 | | #define vlc_threads_end( P_THIS ) \ |
|---|
| 63 | | __vlc_threads_end( VLC_OBJECT(P_THIS) ) |
|---|
| 64 | | |
|---|
| 65 | | /***************************************************************************** |
|---|
| 66 | 54 | * vlc_mutex_init: initialize a mutex |
|---|
| 67 | 55 | *****************************************************************************/ |
|---|
| r50e969e |
rc07b1d0 |
|
| 99 | 99 | * The evil global variable. We handle it with care, don't worry. |
|---|
| 100 | 100 | *****************************************************************************/ |
|---|
| 101 | | static libvlc_global_data_t libvlc_global; |
|---|
| 102 | | static libvlc_global_data_t *p_libvlc_global = &libvlc_global; |
|---|
| 103 | 101 | static libvlc_int_t * p_static_vlc = NULL; |
|---|
| 104 | 102 | static volatile unsigned int i_instances = 0; |
|---|
| … | … | |
| 128 | 126 | |
|---|
| 129 | 127 | static void InitDeviceValues( libvlc_int_t * ); |
|---|
| 130 | | |
|---|
| 131 | | libvlc_global_data_t *vlc_global( void ) |
|---|
| 132 | | { |
|---|
| 133 | | return p_libvlc_global; |
|---|
| 134 | | } |
|---|
| 135 | 128 | |
|---|
| 136 | 129 | /***************************************************************************** |
|---|
| … | … | |
| 157 | 150 | /* vlc_threads_init *must* be the first internal call! No other call is |
|---|
| 158 | 151 | * allowed before the thread system has been initialized. */ |
|---|
| 159 | | if( vlc_threads_init( p_libvlc_global ) ) |
|---|
| | 152 | if (vlc_threads_init ()) |
|---|
| 160 | 153 | return NULL; |
|---|
| 161 | 154 | |
|---|
| | 155 | libvlc_global_data_t *p_libvlc_global = vlc_global(); |
|---|
| 162 | 156 | /* Now that the thread system is initialized, we don't have much, but |
|---|
| 163 | 157 | * at least we have variables */ |
|---|
| … | … | |
| 231 | 225 | const char *ppsz_argv[] ) |
|---|
| 232 | 226 | { |
|---|
| | 227 | libvlc_global_data_t *p_libvlc_global = vlc_global(); |
|---|
| 233 | 228 | char p_capabilities[200]; |
|---|
| 234 | 229 | char * p_tmp = NULL; |
|---|
| … | … | |
| 1109 | 1104 | * The number of initializations of the thread system is counted, we |
|---|
| 1110 | 1105 | * can call this each time */ |
|---|
| 1111 | | vlc_threads_end( p_libvlc_global ); |
|---|
| | 1106 | vlc_threads_end (); |
|---|
| 1112 | 1107 | |
|---|
| 1113 | 1108 | return VLC_SUCCESS; |
|---|
| … | … | |
| 1137 | 1132 | |
|---|
| 1138 | 1133 | #ifndef WIN32 |
|---|
| 1139 | | if( p_libvlc_global->b_daemon && b_block && !psz_module ) |
|---|
| | 1134 | if( vlc_global()->b_daemon && b_block && !psz_module ) |
|---|
| 1140 | 1135 | { |
|---|
| 1141 | 1136 | /* Daemon mode hack. |
|---|
| r0d7bc73 |
rc07b1d0 |
|
| 57 | 57 | * Threads subsystem |
|---|
| 58 | 58 | */ |
|---|
| 59 | | int __vlc_threads_init( vlc_object_t * ); |
|---|
| 60 | | int __vlc_threads_end( vlc_object_t * ); |
|---|
| | 59 | int vlc_threads_init( void ); |
|---|
| | 60 | void vlc_threads_end( void ); |
|---|
| 61 | 61 | |
|---|
| 62 | 62 | /** The global thread var for msg stack context |
|---|
| r23afa49 |
rc07b1d0 |
|
| 46 | 46 | *****************************************************************************/ |
|---|
| 47 | 47 | static volatile unsigned i_initializations = 0; |
|---|
| | 48 | |
|---|
| | 49 | #if defined( UNDER_CE ) |
|---|
| | 50 | #elif defined( WIN32 ) |
|---|
| | 51 | #elif defined( HAVE_KERNEL_SCHEDULER_H ) |
|---|
| | 52 | #elif defined( LIBVLC_USE_PTHREAD ) |
|---|
| | 53 | static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER; |
|---|
| | 54 | #endif |
|---|
| | 55 | |
|---|
| | 56 | /** |
|---|
| | 57 | * Global process-wide VLC object. |
|---|
| | 58 | * Contains inter-instance data, such as the module cache and global mutexes. |
|---|
| | 59 | */ |
|---|
| 48 | 60 | static vlc_object_t *p_root; |
|---|
| 49 | | |
|---|
| 50 | | #if defined( UNDER_CE ) |
|---|
| 51 | | #elif defined( WIN32 ) |
|---|
| 52 | | #elif defined( HAVE_KERNEL_SCHEDULER_H ) |
|---|
| 53 | | #elif defined( LIBVLC_USE_PTHREAD ) |
|---|
| 54 | | static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER; |
|---|
| 55 | | #endif |
|---|
| | 61 | static libvlc_global_data_t libvlc_global; |
|---|
| | 62 | |
|---|
| | 63 | libvlc_global_data_t *vlc_global( void ) |
|---|
| | 64 | { |
|---|
| | 65 | assert( i_initializations > 0 ); |
|---|
| | 66 | return &libvlc_global; |
|---|
| | 67 | } |
|---|
| | 68 | |
|---|
| 56 | 69 | |
|---|
| 57 | 70 | vlc_threadvar_t msg_context_global_key; |
|---|
| … | … | |
| 116 | 129 | * and thus do not guarantee the complete reentrancy. |
|---|
| 117 | 130 | *****************************************************************************/ |
|---|
| 118 | | int __vlc_threads_init( vlc_object_t *p_this ) |
|---|
| 119 | | { |
|---|
| 120 | | libvlc_global_data_t *p_libvlc_global = (libvlc_global_data_t *)p_this; |
|---|
| | 131 | int vlc_threads_init( void ) |
|---|
| | 132 | { |
|---|
| 121 | 133 | int i_ret = VLC_SUCCESS; |
|---|
| 122 | 134 | |
|---|
| … | … | |
| 133 | 145 | { |
|---|
| 134 | 146 | /* We should be safe now. Do all the initialization stuff we want. */ |
|---|
| 135 | | p_libvlc_global->b_ready = false; |
|---|
| 136 | | |
|---|
| 137 | | p_root = vlc_custom_create( VLC_OBJECT(p_libvlc_global), 0, |
|---|
| | 147 | libvlc_global.b_ready = false; |
|---|
| | 148 | |
|---|
| | 149 | p_root = vlc_custom_create( VLC_OBJECT(&libvlc_global), 0, |
|---|
| 138 | 150 | VLC_OBJECT_GLOBAL, "global" ); |
|---|
| 139 | 151 | if( p_root == NULL ) |
|---|
| … | … | |
| 164 | 176 | * FIXME: This function is far from being threadsafe. |
|---|
| 165 | 177 | *****************************************************************************/ |
|---|
| 166 | | int __vlc_threads_end( vlc_object_t *p_this ) |
|---|
| 167 | | { |
|---|
| 168 | | (void)p_this; |
|---|
| | 178 | void vlc_threads_end( void ) |
|---|
| | 179 | { |
|---|
| 169 | 180 | #if defined( UNDER_CE ) |
|---|
| 170 | 181 | #elif defined( WIN32 ) |
|---|
| … | … | |
| 184 | 195 | pthread_mutex_unlock( &once_mutex ); |
|---|
| 185 | 196 | #endif |
|---|
| 186 | | return VLC_SUCCESS; |
|---|
| 187 | 197 | } |
|---|
| 188 | 198 | |
|---|