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
463b756d
Commit
463b756d
authored
Apr 23, 2008
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify threading code a bit
parent
63baa1df
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
54 deletions
+39
-54
include/vlc_threads.h
include/vlc_threads.h
+5
-17
include/vlc_threads_funcs.h
include/vlc_threads_funcs.h
+13
-12
src/misc/threads.c
src/misc/threads.c
+21
-25
No files found.
include/vlc_threads.h
View file @
463b756d
...
...
@@ -38,6 +38,7 @@
/* WinCE API */
#elif defined( WIN32 )
# include <process.h>
/* Win32 API */
# include <errno.h>
#elif defined( HAVE_KERNEL_SCHEDULER_H )
/* BeOS */
# include <kernel/OS.h>
...
...
@@ -146,10 +147,7 @@ typedef struct
int
i_win9x_cv
;
}
vlc_cond_t
;
typedef
struct
{
DWORD
handle
;
}
vlc_threadvar_t
;
typedef
DWORD
vlc_threadvar_t
;
#elif defined( HAVE_KERNEL_SCHEDULER_H )
/* This is the BeOS implementation of the vlc threads, note that the mutex is
...
...
@@ -177,19 +175,9 @@ typedef struct
#else
typedef
pthread_t
vlc_thread_t
;
typedef
struct
{
pthread_mutex_t
mutex
;
}
vlc_mutex_t
;
typedef
struct
{
pthread_cond_t
cond
;
}
vlc_cond_t
;
typedef
struct
{
pthread_key_t
handle
;
}
vlc_threadvar_t
;
typedef
pthread_mutex_t
vlc_mutex_t
;
typedef
pthread_cond_t
vlc_cond_t
;
typedef
pthread_key_t
vlc_threadvar_t
;
#endif
...
...
include/vlc_threads_funcs.h
View file @
463b756d
...
...
@@ -111,8 +111,8 @@ static inline void __vlc_mutex_lock( const char * psz_file, int i_line,
#elif defined(LIBVLC_USE_PTHREAD)
# define vlc_assert_locked( m ) \
assert (pthread_mutex_lock (
&((m)->mutex)
) == EDEADLK)
int
val
=
pthread_mutex_lock
(
&
p_mutex
->
mutex
);
assert (pthread_mutex_lock (
m
) == EDEADLK)
int
val
=
pthread_mutex_lock
(
p_
mutex
);
VLC_THREAD_ASSERT
(
"locking mutex"
);
#endif
...
...
@@ -148,7 +148,7 @@ static inline void __vlc_mutex_unlock( const char * psz_file, int i_line,
release_sem
(
p_mutex
->
lock
);
#elif defined(LIBVLC_USE_PTHREAD)
int
val
=
pthread_mutex_unlock
(
&
p_mutex
->
mutex
);
int
val
=
pthread_mutex_unlock
(
p_
mutex
);
VLC_THREAD_ASSERT
(
"unlocking mutex"
);
#endif
...
...
@@ -248,7 +248,7 @@ static inline void __vlc_cond_signal( const char * psz_file, int i_line,
}
#elif defined(LIBVLC_USE_PTHREAD)
int
val
=
pthread_cond_signal
(
&
p_condvar
->
cond
);
int
val
=
pthread_cond_signal
(
p_condvar
);
VLC_THREAD_ASSERT
(
"signaling condition variable"
);
#endif
...
...
@@ -356,7 +356,7 @@ static inline void __vlc_cond_wait( const char * psz_file, int i_line,
vlc_mutex_lock
(
p_mutex
);
#elif defined(LIBVLC_USE_PTHREAD)
int
val
=
pthread_cond_wait
(
&
p_condvar
->
cond
,
&
p_mutex
->
mutex
);
int
val
=
pthread_cond_wait
(
p_condvar
,
p_
mutex
);
VLC_THREAD_ASSERT
(
"waiting on condition"
);
#endif
...
...
@@ -489,7 +489,7 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
lldiv_t
d
=
lldiv
(
deadline
,
1000000
);
struct
timespec
ts
=
{
d
.
quot
,
d
.
rem
*
1000
};
int
val
=
pthread_cond_timedwait
(
&
p_condvar
->
cond
,
&
p_mutex
->
mutex
,
&
ts
);
int
val
=
pthread_cond_timedwait
(
p_condvar
,
p_
mutex
,
&
ts
);
if
(
val
==
ETIMEDOUT
)
return
ETIMEDOUT
;
/* this error is perfectly normal */
VLC_THREAD_ASSERT
(
"timed-waiting on condition"
);
...
...
@@ -519,13 +519,13 @@ static inline int vlc_threadvar_set( vlc_threadvar_t * p_tls, void *p_value )
int
i_ret
;
#if defined( HAVE_KERNEL_SCHEDULER_H )
return
-
1
;
i_ret
=
EINVAL
;
#elif defined( UNDER_CE ) || defined( WIN32 )
i_ret
=
(
TlsSetValue
(
p_tls
->
handle
,
p_value
)
!=
0
)
;
i_ret
=
TlsSetValue
(
*
p_tls
,
p_value
)
?
EINVAL
:
0
;
#elif defined(LIBVLC_USE_PTHREAD)
i_ret
=
pthread_setspecific
(
p_tls
->
handle
,
p_value
);
i_ret
=
pthread_setspecific
(
*
p_tls
,
p_value
);
#endif
...
...
@@ -537,15 +537,16 @@ static inline int vlc_threadvar_set( vlc_threadvar_t * p_tls, void *p_value )
*****************************************************************************/
static
inline
void
*
vlc_threadvar_get
(
vlc_threadvar_t
*
p_tls
)
{
void
*
p_ret
;
void
*
p_ret
;
#if defined( HAVE_KERNEL_SCHEDULER_H )
p_ret
=
NULL
;
#elif defined( UNDER_CE ) || defined( WIN32 )
p_ret
=
TlsGetValue
(
p_tls
->
handle
);
p_ret
=
TlsGetValue
(
*
p_tls
);
#elif defined(LIBVLC_USE_PTHREAD)
p_ret
=
pthread_getspecific
(
p_tls
->
handle
);
p_ret
=
pthread_getspecific
(
*
p_tls
);
#endif
...
...
src/misc/threads.c
View file @
463b756d
...
...
@@ -287,26 +287,22 @@ int __vlc_mutex_init( vlc_mutex_t *p_mutex )
return
B_OK
;
#elif defined( LIBVLC_USE_PTHREAD )
# ifndef NDEBUG
{
/* Create error-checking mutex to detect problems more easily. */
pthread_mutexattr_t
attr
;
int
i_result
;
pthread_mutexattr_init
(
&
attr
);
# if defined(SYS_LINUX)
pthread_mutexattr_setkind_np
(
&
attr
,
PTHREAD_MUTEX_ERRORCHECK_NP
);
# else
pthread_mutexattr_settype
(
&
attr
,
PTHREAD_MUTEX_ERRORCHECK
);
# endif
pthread_mutexattr_t
attr
;
int
i_result
;
i_result
=
pthread_mutex_init
(
&
p_mutex
->
mutex
,
&
attr
);
pthread_mutexattr_destroy
(
&
attr
);
return
(
i_result
);
}
# endif
/* NDEBUG */
return
pthread_mutex_init
(
&
p_mutex
->
mutex
,
NULL
);
pthread_mutexattr_init
(
&
attr
);
# ifndef NDEBUG
/* Create error-checking mutex to detect problems more easily. */
# if defined(SYS_LINUX)
pthread_mutexattr_setkind_np
(
&
attr
,
PTHREAD_MUTEX_ERRORCHECK_NP
);
# else
pthread_mutexattr_settype
(
&
attr
,
PTHREAD_MUTEX_ERRORCHECK
);
# endif
# endif
i_result
=
pthread_mutex_init
(
p_mutex
,
&
attr
);
pthread_mutexattr_destroy
(
&
attr
);
return
i_result
;
#endif
}
...
...
@@ -333,7 +329,7 @@ int __vlc_mutex_init_recursive( vlc_mutex_t *p_mutex )
# endif
# endif
pthread_mutexattr_settype
(
&
attr
,
PTHREAD_MUTEX_RECURSIVE
);
i_result
=
pthread_mutex_init
(
&
p_mutex
->
mutex
,
&
attr
);
i_result
=
pthread_mutex_init
(
p_
mutex
,
&
attr
);
pthread_mutexattr_destroy
(
&
attr
);
return
(
i_result
);
#else
...
...
@@ -367,7 +363,7 @@ void __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mute
p_mutex
->
init
=
0
;
#elif defined( LIBVLC_USE_PTHREAD )
int
val
=
pthread_mutex_destroy
(
&
p_mutex
->
mutex
);
int
val
=
pthread_mutex_destroy
(
p_
mutex
);
VLC_THREAD_ASSERT
(
"destroying mutex"
);
#endif
...
...
@@ -458,7 +454,7 @@ int __vlc_cond_init( vlc_cond_t *p_condvar )
pthread_condattr_setclock
(
&
attr
,
CLOCK_MONOTONIC
);
# endif
ret
=
pthread_cond_init
(
&
p_condvar
->
cond
,
&
attr
);
ret
=
pthread_cond_init
(
p_condvar
,
&
attr
);
pthread_condattr_destroy
(
&
attr
);
return
ret
;
...
...
@@ -493,7 +489,7 @@ void __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condva
p_condvar
->
init
=
0
;
#elif defined( LIBVLC_USE_PTHREAD )
int
val
=
pthread_cond_destroy
(
&
p_condvar
->
cond
);
int
val
=
pthread_cond_destroy
(
p_condvar
);
VLC_THREAD_ASSERT
(
"destroying condition"
);
#endif
...
...
@@ -510,11 +506,11 @@ int __vlc_threadvar_create( vlc_threadvar_t *p_tls )
# error Unimplemented!
#elif defined( UNDER_CE ) || defined( WIN32 )
#elif defined( WIN32 )
p_tls
->
handle
=
TlsAlloc
();
i_ret
=
!
(
p_tls
->
handle
==
0xFFFFFFFF
)
;
*
p_tls
=
TlsAlloc
();
i_ret
=
(
*
p_tls
==
INVALID_HANDLE_VALUE
)
?
EAGAIN
:
0
;
#elif defined( LIBVLC_USE_PTHREAD )
i_ret
=
pthread_key_create
(
&
p_tls
->
handle
,
NULL
);
i_ret
=
pthread_key_create
(
p_tls
,
NULL
);
#endif
return
i_ret
;
}
...
...
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