Changeset 651078ecf9be6d0bb9c2323023ebb7fbd7f0d145

Show
Ignore:
Timestamp:
12/18/06 22:40:12 (2 years ago)
Author:
Clément Stenac <zorglub@videolan.org>
git-committer:
Clément Stenac <zorglub@videolan.org> 1166478012 +0000
git-parent:

[965e95ec654de6c1f1067086e0f1e7da74a6ecad]

git-author:
Clément Stenac <zorglub@videolan.org> 1166478012 +0000
Message:

Added initial support for TLS (Thread Local Storage) variables

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/vlc_threads.h

    rfbf4c80 r651078e  
    140140    vlc_object_t * p_this; 
    141141} vlc_cond_t; 
     142typedef struct 
     143{ 
     144} vlc_threadvar_t; 
    142145 
    143146#elif defined( ST_INIT_IN_ST_H ) 
     
    153156    vlc_object_t * p_this; 
    154157} vlc_cond_t; 
     158typedef struct 
     159{ 
     160} vlc_threadvar_t; 
    155161 
    156162#elif defined( WIN32 ) || defined( UNDER_CE ) 
     
    183189} vlc_cond_t; 
    184190 
     191typedef struct 
     192{ 
     193    DWORD   handle; 
     194} vlc_threadvar_t; 
     195 
    185196#elif defined( HAVE_KERNEL_SCHEDULER_H ) 
    186197/* This is the BeOS implementation of the vlc threads, note that the mutex is 
     
    206217} vlc_cond_t; 
    207218 
     219typedef struct 
     220{ 
     221} vlc_threadvar_t; 
     222 
     223 
    208224#elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) 
    209225typedef pthread_t       vlc_thread_t; 
     
    218234    vlc_object_t * p_this; 
    219235} vlc_cond_t; 
     236 
     237typedef struct 
     238{ 
     239    pthread_key_t handle; 
     240} vlc_threadvar_t; 
    220241 
    221242#elif defined( HAVE_CTHREADS_H ) 
     
    245266} vlc_cond_t; 
    246267 
    247 #endif 
    248  
     268typedef struct 
     269
     270    cthread_key_t handle; 
     271} vlc_threadvar_t; 
     272 
     273#endif 
     274 
  • include/vlc_threads_funcs.h

    r4475aed r651078e  
    3939VLC_EXPORT( int,  __vlc_cond_init,     ( vlc_object_t *, vlc_cond_t * ) ); 
    4040VLC_EXPORT( int,  __vlc_cond_destroy,  ( const char *, int, vlc_cond_t * ) ); 
     41VLC_EXPORT( int, __vlc_threadvar_create, (vlc_object_t *, vlc_threadvar_t * ) ); 
    4142VLC_EXPORT( int,  __vlc_thread_create, ( vlc_object_t *, const char *, int, const char *, void * ( * ) ( void * ), int, vlc_bool_t ) ); 
    4243VLC_EXPORT( int,  __vlc_thread_set_priority, ( vlc_object_t *, const char *, int, int ) ); 
     
    549550 
    550551/***************************************************************************** 
     552 * vlc_threadvar_create: create a thread-local variable 
     553 *****************************************************************************/ 
     554#define vlc_threadvar_create( PTHIS, P_TLS )                                 \ 
     555   __vlc_threadvar_create( PTHIS, P_TLS ) 
     556 
     557/***************************************************************************** 
     558 * vlc_threadvar_set: create: set the value of a thread-local variable 
     559 *****************************************************************************/ 
     560#define vlc_threadvar_set( P_TLS , P_VAL )                                   \ 
     561   __vlc_threadvar_set( __FILE__, __LINE__, P_TLS, P_VAL ) 
     562 
     563static inline int __vlc_threadvar_set( char* psz_file, int line, 
     564                                        vlc_threadvar_t * p_tls, void *p_value ) 
     565{ 
     566    int i_ret; 
     567 
     568#if defined( PTH_INIT_IN_PTH_H ) || \ 
     569    defined( ST_INIT_IN_ST_H ) || defined( HAVE_KERNEL_SCHEDULER_H ) 
     570    return -1; 
     571 
     572#elif defined( UNDER_CE ) || defined( WIN32 ) 
     573    i_ret = ( TlsSetValue( &p_tls->handle, p_value ) != 0 ); 
     574 
     575#elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) 
     576    i_ret = pthread_setspecific( p_tls->handle, p_value ); 
     577 
     578#elif defined( HAVE_CTHREADS_H ) 
     579    i_ret = cthread_setspecific( p_tls->handle, p_value ); 
     580#endif 
     581 
     582    return i_ret; 
     583} 
     584 
     585/***************************************************************************** 
     586 * vlc_threadvar_get: create: get the value of a thread-local variable 
     587 *****************************************************************************/ 
     588#define vlc_threadvar_get( P_TLS )                                         \ 
     589   __vlc_threadvar_get( __FILE__, __LINE__, P_TLS ) 
     590 
     591static inline void* __vlc_threadvar_get( char* psz_file, int line, 
     592                                         vlc_threadvar_t * p_tls ) 
     593{ 
     594    void* p_ret; 
     595 
     596#if defined( PTH_INIT_IN_PTH_H ) || \ 
     597    defined( ST_INIT_IN_ST_H ) || defined( HAVE_KERNEL_SCHEDULER_H ) 
     598    return NULL; 
     599 
     600#elif defined( UNDER_CE ) || defined( WIN32 ) 
     601    p_ret = TlsGetValue( &p_tls->handle ); 
     602 
     603#elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) 
     604    p_ret = pthread_getspecific( p_tls->handle ); 
     605 
     606#elif defined( HAVE_CTHREADS_H ) 
     607    if ( !cthread_getspecific( p_tls->handle, &p_ret ) ) 
     608    { 
     609        p_ret = NULL; 
     610    } 
     611#endif 
     612 
     613    return p_ret; 
     614} 
     615 
     616/***************************************************************************** 
    551617 * vlc_thread_create: create a thread 
    552618 *****************************************************************************/ 
  • src/misc/threads.c

    r1e4db90 r651078e  
    502502 
    503503/***************************************************************************** 
     504 * vlc_tls_create: create a thread-local variable 
     505 *****************************************************************************/ 
     506int __vlc_threadvar_create( vlc_object_t *p_this, vlc_threadvar_t *p_tls ) 
     507{ 
     508#if defined( PTH_INIT_IN_PTH_H ) 
     509#elif defined( HAVE_KERNEL_SCHEDULER_H ) 
     510#elif defined( ST_INIT_IN_ST_H ) 
     511    msg_Err( p_this, "TLS not implemented" ); 
     512    return VLC_EGENERIC; 
     513 
     514#elif defined( UNDER_CE ) || defined( WIN32 ) 
     515#elif defined( WIN32 ) 
     516    p_tls->handle = TlsAlloc(); 
     517    if( p_tls->handle == 0xFFFFFFFF ) 
     518    { 
     519        return VLC_EGENERIC; 
     520    } 
     521 
     522    msg_Err( p_this, "TLS not implemented" ); 
     523    return VLC_EGENERIC; 
     524 
     525#elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) 
     526    return pthread_key_create( &p_tls->handle, NULL ); 
     527 
     528#elif defined( HAVE_CTHREADS_H ) 
     529    return cthread_keycreate( &p_tls-handle ); 
     530#endif 
     531} 
     532 
     533/***************************************************************************** 
    504534 * vlc_thread_create: create a thread, inner version 
    505535 ***************************************************************************** 
  • test/NativeLibvlcTest.py

    racf462d r651078e  
    44 
    55class NativeLibvlcTestCase( unittest.TestCase ): 
     6    def testTls( self ): 
     7        """[Thread] Set TLS""" 
     8        native_libvlc_test.threadvar_test() 
    69    def test1Exception( self ): 
    710        """[LibVLC] Checks libvlc_exception""" 
  • test/native/init.c

    r266fb28 r651078e  
    2525   DEF_METHOD( bsearch_member_test, "Test Bsearch with structure" ) 
    2626   DEF_METHOD( dict_test, "Test dictionnaries" ) 
     27   DEF_METHOD( threadvar_test, "Test TLS" ) 
    2728   { NULL, NULL, 0, NULL } 
    2829}; 
  • test/native/tests.h

    r266fb28 r651078e  
    66PyObject *playlist_test( PyObject *self, PyObject *args ); 
    77PyObject *vlm_test( PyObject *self, PyObject *args ); 
     8 
     9PyObject *threadvar_test( PyObject *self, PyObject *args ); 
    810 
    911/* Stats */ 
  • test/setup.py

    racf462d r651078e  
    4343                sources = ['native/init.c', 'native/url.c', 'native/i18n.c', 
    4444                'native/stats.c', 'native/libvlc.c', 'native/profiles.c', 
    45                 'native/algo.c'], 
     45                'native/algo.c', 'native/threads.c'], 
    4646                include_dirs = ['../include', '../', '/usr/win32/include' ], 
    4747                extra_objects = [ '../src/.libs/libvlc.so', '../src/.libs/libvlc-control.so' ],