Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-2-2
Commits
6ed74223
Commit
6ed74223
authored
Apr 23, 2008
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Win32: remove (now dead) old mutex/cv implementation
Should save a bunch of kilobytes of code.
parent
b648be13
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
250 deletions
+19
-250
include/vlc_threads.h
include/vlc_threads.h
+0
-8
include/vlc_threads_funcs.h
include/vlc_threads_funcs.h
+16
-190
src/misc/threads.c
src/misc/threads.c
+3
-52
No files found.
include/vlc_threads.h
View file @
6ed74223
...
...
@@ -130,21 +130,13 @@ typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL );
typedef
struct
{
/* WinNT/2K/XP implementation */
HANDLE
mutex
;
/* Win95/98/ME implementation */
CRITICAL_SECTION
csection
;
}
vlc_mutex_t
;
typedef
struct
{
volatile
int
i_waiting_threads
;
/* WinNT/2K/XP implementation */
HANDLE
event
;
/* Win95/98/ME implementation */
HANDLE
semaphore
;
CRITICAL_SECTION
csection
;
int
i_win9x_cv
;
}
vlc_cond_t
;
typedef
DWORD
vlc_threadvar_t
;
...
...
include/vlc_threads_funcs.h
View file @
6ed74223
...
...
@@ -101,10 +101,7 @@ static inline void __vlc_mutex_lock( const char * psz_file, int i_line,
#elif defined( WIN32 )
VLC_UNUSED
(
psz_file
);
VLC_UNUSED
(
i_line
);
if
(
p_mutex
->
mutex
)
WaitForSingleObject
(
p_mutex
->
mutex
,
INFINITE
);
else
EnterCriticalSection
(
&
p_mutex
->
csection
);
WaitForSingleObject
(
p_mutex
->
mutex
,
INFINITE
);
#elif defined( HAVE_KERNEL_SCHEDULER_H )
acquire_sem
(
p_mutex
->
lock
);
...
...
@@ -139,10 +136,7 @@ static inline void __vlc_mutex_unlock( const char * psz_file, int i_line,
#elif defined( WIN32 )
VLC_UNUSED
(
psz_file
);
VLC_UNUSED
(
i_line
);
if
(
p_mutex
->
mutex
)
ReleaseMutex
(
p_mutex
->
mutex
);
else
LeaveCriticalSection
(
&
p_mutex
->
csection
);
ReleaseMutex
(
p_mutex
->
mutex
);
#elif defined( HAVE_KERNEL_SCHEDULER_H )
release_sem
(
p_mutex
->
lock
);
...
...
@@ -175,55 +169,16 @@ static inline void __vlc_mutex_unlock( const char * psz_file, int i_line,
static
inline
void
__vlc_cond_signal
(
const
char
*
psz_file
,
int
i_line
,
vlc_cond_t
*
p_condvar
)
{
#if defined( UNDER_CE )
VLC_UNUSED
(
psz_file
);
VLC_UNUSED
(
i_line
);
PulseEvent
(
p_condvar
->
event
);
#elif defined( WIN32 )
#if defined( UNDER_CE ) || defined( WIN32 )
VLC_UNUSED
(
psz_file
);
VLC_UNUSED
(
i_line
);
/* Release one waiting thread if one is available. */
/* For this trick to work properly, the vlc_cond_signal must be surrounded
* by a mutex. This will prevent another thread from stealing the signal */
if
(
!
p_condvar
->
semaphore
)
{
/* PulseEvent() only works if none of the waiting threads is suspended.
* This is particularily problematic under a debug session.
* as documented in http://support.microsoft.com/kb/q173260/ */
PulseEvent
(
p_condvar
->
event
);
}
else
if
(
p_condvar
->
i_win9x_cv
==
1
)
{
/* Wait for the gate to be open */
WaitForSingleObject
(
p_condvar
->
event
,
INFINITE
);
if
(
p_condvar
->
i_waiting_threads
)
{
/* Using a semaphore exposes us to a race condition. It is
* possible for another thread to start waiting on the semaphore
* just after we signaled it and thus steal the signal.
* We have to prevent new threads from entering the cond_wait(). */
ResetEvent
(
p_condvar
->
event
);
/* A semaphore is used here because Win9x doesn't have
* SignalObjectAndWait() and thus a race condition exists
* during the time we release the mutex and the time we start
* waiting on the event (more precisely, the signal can sometimes
* be missed by the waiting thread if we use PulseEvent()). */
ReleaseSemaphore
(
p_condvar
->
semaphore
,
1
,
0
);
}
}
else
{
if
(
p_condvar
->
i_waiting_threads
)
{
ReleaseSemaphore
(
p_condvar
->
semaphore
,
1
,
0
);
/* Wait for the last thread to be awakened */
WaitForSingleObject
(
p_condvar
->
event
,
INFINITE
);
}
}
/* PulseEvent() only works if none of the waiting threads is suspended.
* This is particularily problematic under a debug session.
* as documented in http://support.microsoft.com/kb/q173260/ */
PulseEvent
(
p_condvar
->
event
);
#elif defined( HAVE_KERNEL_SCHEDULER_H )
while
(
p_condvar
->
thread
!=
-
1
)
...
...
@@ -275,71 +230,10 @@ static inline void __vlc_cond_wait( const char * psz_file, int i_line,
#elif defined( WIN32 )
VLC_UNUSED
(
psz_file
);
VLC_UNUSED
(
i_line
);
if
(
!
p_condvar
->
semaphore
)
{
/* Increase our wait count */
p_condvar
->
i_waiting_threads
++
;
if
(
p_mutex
->
mutex
)
{
SignalObjectAndWait
(
p_mutex
->
mutex
,
p_condvar
->
event
,
INFINITE
,
FALSE
);
}
else
{
LeaveCriticalSection
(
&
p_mutex
->
csection
);
WaitForSingleObject
(
p_condvar
->
event
,
INFINITE
);
}
p_condvar
->
i_waiting_threads
--
;
}
else
if
(
p_condvar
->
i_win9x_cv
==
1
)
{
int
i_waiting_threads
;
/* Wait for the gate to be open */
WaitForSingleObject
(
p_condvar
->
event
,
INFINITE
);
/* Increase our wait count */
p_condvar
->
i_waiting_threads
++
;
LeaveCriticalSection
(
&
p_mutex
->
csection
);
WaitForSingleObject
(
p_condvar
->
semaphore
,
INFINITE
);
/* Decrement and test must be atomic */
EnterCriticalSection
(
&
p_condvar
->
csection
);
/* Decrease our wait count */
i_waiting_threads
=
--
p_condvar
->
i_waiting_threads
;
LeaveCriticalSection
(
&
p_condvar
->
csection
);
/* Reopen the gate if we were the last waiting thread */
if
(
!
i_waiting_threads
)
SetEvent
(
p_condvar
->
event
);
}
else
{
int
i_waiting_threads
;
/* Increase our wait count */
p_condvar
->
i_waiting_threads
++
;
LeaveCriticalSection
(
&
p_mutex
->
csection
);
WaitForSingleObject
(
p_condvar
->
semaphore
,
INFINITE
);
/* Decrement and test must be atomic */
EnterCriticalSection
(
&
p_condvar
->
csection
);
/* Decrease our wait count */
i_waiting_threads
=
--
p_condvar
->
i_waiting_threads
;
LeaveCriticalSection
(
&
p_condvar
->
csection
);
/* Signal that the last waiting thread just went through */
if
(
!
i_waiting_threads
)
SetEvent
(
p_condvar
->
event
);
}
/* Increase our wait count */
p_condvar
->
i_waiting_threads
++
;
SignalObjectAndWait
(
p_mutex
->
mutex
,
p_condvar
->
event
,
INFINITE
,
FALSE
);
p_condvar
->
i_waiting_threads
--
;
/* Reacquire the mutex before returning. */
vlc_mutex_lock
(
p_mutex
);
...
...
@@ -403,79 +297,11 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
if
(
delay_ms
<
0
)
delay_ms
=
0
;
if
(
!
p_condvar
->
semaphore
)
{
/* Increase our wait count */
p_condvar
->
i_waiting_threads
++
;
if
(
p_mutex
->
mutex
)
{
result
=
SignalObjectAndWait
(
p_mutex
->
mutex
,
p_condvar
->
event
,
delay_ms
,
FALSE
);
}
else
{
LeaveCriticalSection
(
&
p_mutex
->
csection
);
result
=
WaitForSingleObject
(
p_condvar
->
event
,
delay_ms
);
}
p_condvar
->
i_waiting_threads
--
;
}
else
if
(
p_condvar
->
i_win9x_cv
==
1
)
{
int
i_waiting_threads
;
/* Wait for the gate to be open */
result
=
WaitForSingleObject
(
p_condvar
->
event
,
delay_ms
);
/* Increase our wait count */
p_condvar
->
i_waiting_threads
++
;
LeaveCriticalSection
(
&
p_mutex
->
csection
);
if
(
!
result
)
{
/* recaculate remaining delay */
delay_ms
=
(
deadline
-
mdate
())
/
1000
;
if
(
delay_ms
<
0
)
delay_ms
=
0
;
result
=
WaitForSingleObject
(
p_condvar
->
semaphore
,
delay_ms
);
}
/* Decrement and test must be atomic */
EnterCriticalSection
(
&
p_condvar
->
csection
);
/* Decrease our wait count */
i_waiting_threads
=
--
p_condvar
->
i_waiting_threads
;
LeaveCriticalSection
(
&
p_condvar
->
csection
);
/* Reopen the gate if we were the last waiting thread */
if
(
!
i_waiting_threads
)
SetEvent
(
p_condvar
->
event
);
}
else
{
int
i_waiting_threads
;
/* Increase our wait count */
p_condvar
->
i_waiting_threads
++
;
LeaveCriticalSection
(
&
p_mutex
->
csection
);
result
=
WaitForSingleObject
(
p_condvar
->
semaphore
,
delay_ms
);
/* Decrement and test must be atomic */
EnterCriticalSection
(
&
p_condvar
->
csection
);
/* Decrease our wait count */
i_waiting_threads
=
--
p_condvar
->
i_waiting_threads
;
LeaveCriticalSection
(
&
p_condvar
->
csection
);
/* Signal that the last waiting thread just went through */
if
(
!
i_waiting_threads
)
SetEvent
(
p_condvar
->
event
);
}
/* Increase our wait count */
p_condvar
->
i_waiting_threads
++
;
result
=
SignalObjectAndWait
(
p_mutex
->
mutex
,
p_condvar
->
event
,
delay_ms
,
FALSE
);
p_condvar
->
i_waiting_threads
--
;
/* Reacquire the mutex before returning. */
vlc_mutex_lock
(
p_mutex
);
...
...
src/misc/threads.c
View file @
6ed74223
...
...
@@ -50,17 +50,6 @@ static vlc_object_t *p_root;
#if defined( UNDER_CE )
#elif defined( WIN32 )
/*
** On Windows 9x/Me you can use a fast but incorrect condition variables
** implementation (more precisely there is a possibility for a race
** condition to happen).
** However it is possible to use slower alternatives which are more robust.
** Currently you can choose between implementation 0 (which is the
** fastest but slightly incorrect), 1 (default) and 2.
*/
static
int
i_win9x_cv
=
1
;
#elif defined( HAVE_KERNEL_SCHEDULER_H )
#elif defined( LIBVLC_USE_PTHREAD )
static
pthread_mutex_t
once_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
...
...
@@ -136,11 +125,6 @@ int __vlc_threads_init( vlc_object_t *p_this )
* hope nothing wrong happens. */
#if defined( UNDER_CE )
#elif defined( WIN32 )
if
(
IsDebuggerPresent
()
)
{
/* SignalObjectAndWait() is problematic under a debugger */
i_win9x_cv
=
1
;
}
#elif defined( HAVE_KERNEL_SCHEDULER_H )
#elif defined( LIBVLC_USE_PTHREAD )
pthread_mutex_lock
(
&
once_mutex
);
...
...
@@ -334,10 +318,7 @@ void __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mute
#elif defined( WIN32 )
VLC_UNUSED
(
psz_file
);
VLC_UNUSED
(
i_line
);
if
(
p_mutex
->
mutex
)
CloseHandle
(
p_mutex
->
mutex
);
else
DeleteCriticalSection
(
&
p_mutex
->
csection
);
CloseHandle
(
p_mutex
->
mutex
);
#elif defined( HAVE_KERNEL_SCHEDULER_H )
if
(
p_mutex
->
init
==
9999
)
...
...
@@ -357,31 +338,15 @@ void __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mute
*****************************************************************************/
int
__vlc_cond_init
(
vlc_cond_t
*
p_condvar
)
{
#if defined( UNDER_CE )
/* Initialize counter */
p_condvar
->
i_waiting_threads
=
0
;
/* Create an auto-reset event. */
p_condvar
->
event
=
CreateEvent
(
NULL
,
/* no security */
FALSE
,
/* auto-reset event */
FALSE
,
/* start non-signaled */
NULL
);
/* unnamed */
return
!
p_condvar
->
event
;
#elif defined( WIN32 )
#if defined( UNDER_CE ) || defined( WIN32 )
/* Initialize counter */
p_condvar
->
i_waiting_threads
=
0
;
/* Misc init */
p_condvar
->
i_win9x_cv
=
i_win9x_cv
;
/* Create an auto-reset event. */
p_condvar
->
event
=
CreateEvent
(
NULL
,
/* no security */
FALSE
,
/* auto-reset event */
FALSE
,
/* start non-signaled */
NULL
);
/* unnamed */
p_condvar
->
semaphore
=
NULL
;
return
!
p_condvar
->
event
;
#elif defined( HAVE_KERNEL_SCHEDULER_H )
...
...
@@ -428,25 +393,11 @@ int __vlc_cond_init( vlc_cond_t *p_condvar )
*****************************************************************************/
void
__vlc_cond_destroy
(
const
char
*
psz_file
,
int
i_line
,
vlc_cond_t
*
p_condvar
)
{
#if defined( UNDER_CE )
#if defined( UNDER_CE )
|| defined( WIN32 )
VLC_UNUSED
(
psz_file
);
VLC_UNUSED
(
i_line
);
CloseHandle
(
p_condvar
->
event
);
#elif defined( WIN32 )
VLC_UNUSED
(
psz_file
);
VLC_UNUSED
(
i_line
);
if
(
!
p_condvar
->
semaphore
)
CloseHandle
(
p_condvar
->
event
);
else
{
CloseHandle
(
p_condvar
->
event
);
CloseHandle
(
p_condvar
->
semaphore
);
}
if
(
p_condvar
->
semaphore
!=
NULL
)
DeleteCriticalSection
(
&
p_condvar
->
csection
);
#elif defined( HAVE_KERNEL_SCHEDULER_H )
p_condvar
->
init
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment