Commit 9a719ad0 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Win32 compile fixes

parent 707279b4
...@@ -443,6 +443,7 @@ typedef int ( * vlc_callback_t ) ( vlc_object_t *, /* variable's object */ ...@@ -443,6 +443,7 @@ typedef int ( * vlc_callback_t ) ( vlc_object_t *, /* variable's object */
# endif # endif
#endif #endif
#include "vlc_mtime.h"
#include "vlc_threads.h" #include "vlc_threads.h"
typedef struct vlc_object_internals_t vlc_object_internals_t; typedef struct vlc_object_internals_t vlc_object_internals_t;
...@@ -929,7 +930,6 @@ VLC_EXPORT( const char *, VLC_Changeset, ( void ) ); ...@@ -929,7 +930,6 @@ VLC_EXPORT( const char *, VLC_Changeset, ( void ) );
#include "vlc_messages.h" #include "vlc_messages.h"
#include "vlc_variables.h" #include "vlc_variables.h"
#include "vlc_objects.h" #include "vlc_objects.h"
#include "vlc_mtime.h"
#include "vlc_modules.h" #include "vlc_modules.h"
#include "vlc_main.h" #include "vlc_main.h"
#include "vlc_configuration.h" #include "vlc_configuration.h"
......
...@@ -119,16 +119,7 @@ typedef pthread_cond_t vlc_cond_t; ...@@ -119,16 +119,7 @@ typedef pthread_cond_t vlc_cond_t;
typedef pthread_key_t vlc_threadvar_t; typedef pthread_key_t vlc_threadvar_t;
#elif defined( WIN32 ) || defined( UNDER_CE ) #elif defined( WIN32 ) || defined( UNDER_CE )
typedef struct typedef HANDLE vlc_thread_t;
{
/* thread id */
DWORD id;
/*
** handle to created thread, needs be closed to dispose of it
** even after thread has exited
*/
HANDLE hThread;
} vlc_thread_t;
typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL ); typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL );
...@@ -211,12 +202,12 @@ static inline void __vlc_mutex_lock( const char * psz_file, int i_line, ...@@ -211,12 +202,12 @@ static inline void __vlc_mutex_lock( const char * psz_file, int i_line,
VLC_THREAD_ASSERT ("locking mutex"); VLC_THREAD_ASSERT ("locking mutex");
#elif defined( UNDER_CE ) #elif defined( UNDER_CE )
VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); (void)psz_file; (void)i_line;
EnterCriticalSection( &p_mutex->csection ); EnterCriticalSection( &p_mutex->csection );
#elif defined( WIN32 ) #elif defined( WIN32 )
VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); (void)psz_file; (void)i_line;
WaitForSingleObject( *p_mutex, INFINITE ); WaitForSingleObject( *p_mutex, INFINITE );
...@@ -244,12 +235,12 @@ static inline void __vlc_mutex_unlock( const char * psz_file, int i_line, ...@@ -244,12 +235,12 @@ static inline void __vlc_mutex_unlock( const char * psz_file, int i_line,
VLC_THREAD_ASSERT ("unlocking mutex"); VLC_THREAD_ASSERT ("unlocking mutex");
#elif defined( UNDER_CE ) #elif defined( UNDER_CE )
VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); (void)psz_file); (void)i_line;
LeaveCriticalSection( &p_mutex->csection ); LeaveCriticalSection( &p_mutex->csection );
#elif defined( WIN32 ) #elif defined( WIN32 )
VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); (void)psz_file; (void)i_line;
ReleaseMutex( *p_mutex ); ReleaseMutex( *p_mutex );
...@@ -285,7 +276,7 @@ static inline void __vlc_cond_signal( const char * psz_file, int i_line, ...@@ -285,7 +276,7 @@ static inline void __vlc_cond_signal( const char * psz_file, int i_line,
VLC_THREAD_ASSERT ("signaling condition variable"); VLC_THREAD_ASSERT ("signaling condition variable");
#elif defined( UNDER_CE ) || defined( WIN32 ) #elif defined( UNDER_CE ) || defined( WIN32 )
VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); (void)psz_file; (void)i_line;
/* Release one waiting thread if one is available. */ /* Release one waiting thread if one is available. */
/* For this trick to work properly, the vlc_cond_signal must be surrounded /* For this trick to work properly, the vlc_cond_signal must be surrounded
...@@ -343,7 +334,7 @@ static inline void __vlc_cond_wait( const char * psz_file, int i_line, ...@@ -343,7 +334,7 @@ static inline void __vlc_cond_wait( const char * psz_file, int i_line,
vlc_mutex_lock( p_mutex ); vlc_mutex_lock( p_mutex );
#elif defined( WIN32 ) #elif defined( WIN32 )
VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); (void)psz_file; (void)i_line;
/* Increase our wait count */ /* Increase our wait count */
p_condvar->i_waiting_threads++; p_condvar->i_waiting_threads++;
...@@ -392,7 +383,6 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line, ...@@ -392,7 +383,6 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
#elif defined( UNDER_CE ) #elif defined( UNDER_CE )
mtime_t delay_ms = (deadline - mdate())/1000; mtime_t delay_ms = (deadline - mdate())/1000;
DWORD result; DWORD result;
if( delay_ms < 0 ) if( delay_ms < 0 )
delay_ms = 0; delay_ms = 0;
...@@ -408,12 +398,11 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line, ...@@ -408,12 +398,11 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
if(result == WAIT_TIMEOUT) if(result == WAIT_TIMEOUT)
return ETIMEDOUT; /* this error is perfectly normal */ return ETIMEDOUT; /* this error is perfectly normal */
#elif defined( WIN32 ) (void)psz_file; (void)i_line;
VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
DWORD result;
#elif defined( WIN32 )
mtime_t delay_ms = (deadline - mdate())/1000; mtime_t delay_ms = (deadline - mdate())/1000;
DWORD result;
if( delay_ms < 0 ) if( delay_ms < 0 )
delay_ms = 0; delay_ms = 0;
...@@ -428,6 +417,8 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line, ...@@ -428,6 +417,8 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
if(result == WAIT_TIMEOUT) if(result == WAIT_TIMEOUT)
return ETIMEDOUT; /* this error is perfectly normal */ return ETIMEDOUT; /* this error is perfectly normal */
(void)psz_file; (void)i_line;
#elif defined( HAVE_KERNEL_SCHEDULER_H ) #elif defined( HAVE_KERNEL_SCHEDULER_H )
# error Unimplemented # error Unimplemented
......
...@@ -383,7 +383,7 @@ int __vlc_threadvar_create( vlc_threadvar_t *p_tls ) ...@@ -383,7 +383,7 @@ int __vlc_threadvar_create( vlc_threadvar_t *p_tls )
#elif defined( UNDER_CE ) #elif defined( UNDER_CE )
#elif defined( WIN32 ) #elif defined( WIN32 )
*p_tls = TlsAlloc(); *p_tls = TlsAlloc();
i_ret = (*p_tls == INVALID_HANDLE_VALUE) ? EAGAIN : 0; i_ret = (*p_tls == TLS_OUT_OF_INDEXES) ? EAGAIN : 0;
#else #else
# error Unimplemented! # error Unimplemented!
#endif #endif
...@@ -450,27 +450,23 @@ int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line ...@@ -450,27 +450,23 @@ int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line
* memory leaks and the signal functions not working (see Microsoft * memory leaks and the signal functions not working (see Microsoft
* Knowledge Base, article 104641) */ * Knowledge Base, article 104641) */
#if defined( UNDER_CE ) #if defined( UNDER_CE )
DWORD threadId;
HANDLE hThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)func, HANDLE hThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)func,
(LPVOID)p_data, CREATE_SUSPENDED, (LPVOID)p_data, CREATE_SUSPENDED,
&threadId ); NULL );
#else #else
unsigned threadId; HANDLE hThread = (HANDLE)(uintptr_t)
uintptr_t hThread = _beginthreadex( NULL, 0, _beginthreadex( NULL, 0, (LPTHREAD_START_ROUTINE)func,
(LPTHREAD_START_ROUTINE)func, (void *)p_data, CREATE_SUSPENDED, NULL );
(void*)p_data, CREATE_SUSPENDED,
&threadId );
#endif #endif
p_priv->thread_id.id = (DWORD)threadId; p_priv->thread_id = hThread;
p_priv->thread_id.hThread = (HANDLE)hThread; ResumeThread(hThread);
ResumeThread((HANDLE)hThread);
} }
i_ret = ( p_priv->thread_id.hThread ? 0 : 1 ); i_ret = ( p_priv->thread_id ? 0 : errno );
if( !i_ret && i_priority ) if( !i_ret && i_priority )
{ {
if( !SetThreadPriority(p_priv->thread_id.hThread, i_priority) ) if( !SetThreadPriority(p_priv->thread_id, i_priority) )
{ {
msg_Warn( p_this, "couldn't set a faster priority" ); msg_Warn( p_this, "couldn't set a faster priority" );
i_priority = 0; i_priority = 0;
...@@ -493,16 +489,9 @@ int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line ...@@ -493,16 +489,9 @@ int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line
} }
p_priv->b_thread = true; p_priv->b_thread = true;
msg_Dbg( p_this, "thread %lu (%s) created at priority %d (%s:%d)",
#if defined( WIN32 ) || defined( UNDER_CE ) (unsigned long)p_priv->thread_id, psz_name, i_priority,
msg_Dbg( p_this, "thread %u (%s) created at priority %d (%s:%d)",
(unsigned int)p_priv->thread_id.id, psz_name, i_priority,
psz_file, i_line );
#else
msg_Dbg( p_this, "thread %u (%s) created at priority %d (%s:%d)",
(unsigned int)p_priv->thread_id, psz_name, i_priority,
psz_file, i_line ); psz_file, i_line );
#endif
} }
else else
{ {
...@@ -560,9 +549,9 @@ int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file, ...@@ -560,9 +549,9 @@ int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file,
#elif defined( WIN32 ) || defined( UNDER_CE ) #elif defined( WIN32 ) || defined( UNDER_CE )
VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
if( !p_priv->thread_id.hThread ) if( !p_priv->thread_id )
p_priv->thread_id.hThread = GetCurrentThread(); p_priv->thread_id = GetCurrentThread();
if( !SetThreadPriority(p_priv->thread_id.hThread, i_priority) ) if( !SetThreadPriority(p_priv->thread_id, i_priority) )
{ {
msg_Warn( p_this, "couldn't set a faster priority" ); msg_Warn( p_this, "couldn't set a faster priority" );
return 1; return 1;
...@@ -610,25 +599,20 @@ void __vlc_thread_join( vlc_object_t *p_this, const char * psz_file, int i_line ...@@ -610,25 +599,20 @@ void __vlc_thread_join( vlc_object_t *p_this, const char * psz_file, int i_line
** to be on the safe side ** to be on the safe side
*/ */
if( ! DuplicateHandle(GetCurrentProcess(), if( ! DuplicateHandle(GetCurrentProcess(),
p_priv->thread_id.hThread, p_priv->thread_id,
GetCurrentProcess(), GetCurrentProcess(),
&hThread, &hThread,
0, 0,
FALSE, FALSE,
DUPLICATE_SAME_ACCESS) ) DUPLICATE_SAME_ACCESS) )
{ {
msg_Err( p_this, "thread_join(%u) failed at %s:%d (%u)",
(unsigned int)p_priv->thread_id.id,
psz_file, i_line, (unsigned int)GetLastError() );
p_priv->b_thread = false; p_priv->b_thread = false;
return; i_ret = GetLastError();
goto error;
} }
WaitForSingleObject( hThread, INFINITE ); WaitForSingleObject( hThread, INFINITE );
msg_Dbg( p_this, "thread %u joined (%s:%d)",
(unsigned int)p_priv->thread_id.id,
psz_file, i_line );
#if defined( UNDER_CE ) #if defined( UNDER_CE )
hmodule = GetModuleHandle( _T("COREDLL") ); hmodule = GetModuleHandle( _T("COREDLL") );
#else #else
...@@ -665,6 +649,7 @@ void __vlc_thread_join( vlc_object_t *p_this, const char * psz_file, int i_line ...@@ -665,6 +649,7 @@ void __vlc_thread_join( vlc_object_t *p_this, const char * psz_file, int i_line
(double)((user_time%(60*1000000))/1000000.0) ); (double)((user_time%(60*1000000))/1000000.0) );
} }
CloseHandle( hThread ); CloseHandle( hThread );
error:
#elif defined( HAVE_KERNEL_SCHEDULER_H ) #elif defined( HAVE_KERNEL_SCHEDULER_H )
int32_t exit_value; int32_t exit_value;
...@@ -675,12 +660,12 @@ void __vlc_thread_join( vlc_object_t *p_this, const char * psz_file, int i_line ...@@ -675,12 +660,12 @@ void __vlc_thread_join( vlc_object_t *p_this, const char * psz_file, int i_line
if( i_ret ) if( i_ret )
{ {
errno = i_ret; errno = i_ret;
msg_Err( p_this, "thread_join(%u) failed at %s:%d (%m)", msg_Err( p_this, "thread_join(%lu) failed at %s:%d (%m)",
(unsigned int)p_priv->thread_id, psz_file, i_line ); (unsigned long)p_priv->thread_id, psz_file, i_line );
} }
else else
msg_Dbg( p_this, "thread %u joined (%s:%d)", msg_Dbg( p_this, "thread %lu joined (%s:%d)",
(unsigned int)p_priv->thread_id, psz_file, i_line ); (unsigned long)p_priv->thread_id, psz_file, i_line );
p_priv->b_thread = false; p_priv->b_thread = false;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment