Changeset 1746fdda5a2bc062d52a3b8a30d9d1d6518e64b4

Show
Ignore:
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
  • src/libvlc.h

    r0d37c5b r1746fdd  
    4646int vlc_threads_init( void ); 
    4747void vlc_threads_end( void ); 
     48vlc_object_t *vlc_threadobj (void); 
    4849 
    4950/* 
  • src/misc/objects.c

    r2e7d3d7 r1746fdd  
    8686 * Local structure lock 
    8787 *****************************************************************************/ 
    88 static vlc_mutex_t    structure_lock; 
     88static vlc_mutex_t     structure_lock; 
     89static vlc_threadvar_t thread_object; 
    8990 
    9091void *vlc_custom_create( vlc_object_t *p_this, size_t i_size, 
  • src/misc/threads.c

    r5143683 r1746fdd  
    6363} 
    6464 
     65/** 
     66 * Object running the current thread 
     67 */ 
     68static vlc_threadvar_t thread_object_key; 
     69 
     70vlc_object_t *vlc_threadobj (void) 
     71{ 
     72    return vlc_threadvar_get (&thread_object_key); 
     73} 
    6574 
    6675vlc_threadvar_t msg_context_global_key; 
     
    151160 
    152161        /* We should be safe now. Do all the initialization stuff we want. */ 
     162        vlc_threadvar_create( &thread_object_key, NULL ); 
    153163        vlc_threadvar_create( &msg_context_global_key, msg_StackDestroy ); 
    154164    } 
     
    182192        vlc_object_release( p_root ); 
    183193        vlc_threadvar_delete( &msg_context_global_key ); 
     194        vlc_threadvar_delete( &thread_object_key ); 
    184195    } 
    185196    i_initializations--; 
     
    412423} 
    413424 
     425struct 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 
     439static 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 
    414452/***************************************************************************** 
    415453 * vlc_thread_create: create a thread, inner version 
     
    423461{ 
    424462    int i_ret; 
    425     void *p_data = (void *)p_this; 
    426463    vlc_object_internals_t *p_priv = vlc_internals( p_this ); 
    427464 
     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 
    428471    vlc_mutex_lock( &p_this->object_lock ); 
    429472 
    430473#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 ); 
    432475 
    433476#ifndef __APPLE__ 
     
    472515         * Knowledge Base, article 104641) */ 
    473516#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, 
    476519                                        NULL ); 
    477520#else 
    478521        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 ); 
    481524#endif 
    482525        p_priv->thread_id = hThread; 
     
    496539 
    497540#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, 
    499542                                      i_priority, p_data ); 
    500543    i_ret = resume_thread( p_priv->thread_id );