Commit 59f77831 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

threads: reorder code

(No functional changes)
parent 74337dd2
...@@ -34,6 +34,10 @@ ...@@ -34,6 +34,10 @@
* *
*/ */
VLC_API int vlc_savecancel(void);
VLC_API void vlc_restorecancel(int state);
VLC_API void vlc_testcancel(void);
#if defined (_WIN32) #if defined (_WIN32)
# include <process.h> # include <process.h>
# ifndef ETIMEDOUT # ifndef ETIMEDOUT
...@@ -73,6 +77,25 @@ typedef struct vlc_timer *vlc_timer_t; ...@@ -73,6 +77,25 @@ typedef struct vlc_timer *vlc_timer_t;
# define VLC_THREAD_PRIORITY_OUTPUT THREAD_PRIORITY_ABOVE_NORMAL # define VLC_THREAD_PRIORITY_OUTPUT THREAD_PRIORITY_ABOVE_NORMAL
# define VLC_THREAD_PRIORITY_HIGHEST THREAD_PRIORITY_TIME_CRITICAL # define VLC_THREAD_PRIORITY_HIGHEST THREAD_PRIORITY_TIME_CRITICAL
static inline int vlc_poll(struct pollfd *fds, unsigned nfds, int timeout)
{
int val;
do
{
int ugly_timeout = ((unsigned)timeout >= 50) ? 50 : timeout;
if (timeout >= 0)
timeout -= ugly_timeout;
vlc_testcancel ();
val = poll (fds, nfds, ugly_timeout);
}
while (val == 0 && timeout != 0);
return val;
}
# define poll(u,n,t) vlc_poll(u, n, t)
#elif defined (__OS2__) #elif defined (__OS2__)
# include <errno.h> # include <errno.h>
...@@ -113,6 +136,26 @@ typedef struct vlc_timer *vlc_timer_t; ...@@ -113,6 +136,26 @@ typedef struct vlc_timer *vlc_timer_t;
# define pthread_sigmask sigprocmask # define pthread_sigmask sigprocmask
static inline int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
{
static int (*vlc_poll_os2)(struct pollfd *, unsigned, int) = NULL;
if (!vlc_poll_os2)
{
HMODULE hmod;
CHAR szFailed[CCHMAXPATH];
if (DosLoadModule(szFailed, sizeof(szFailed), "vlccore", &hmod))
return -1;
if (DosQueryProcAddr(hmod, 0, "_vlc_poll_os2", (PFN *)&vlc_poll_os2))
return -1;
}
return (*vlc_poll_os2)(fds, nfds, timeout);
}
# define poll(u,n,t) vlc_poll(u, n, t)
#elif defined (__ANDROID__) /* pthreads subset without pthread_cancel() */ #elif defined (__ANDROID__) /* pthreads subset without pthread_cancel() */
# include <unistd.h> # include <unistd.h>
# include <pthread.h> # include <pthread.h>
...@@ -141,6 +184,26 @@ typedef struct vlc_timer *vlc_timer_t; ...@@ -141,6 +184,26 @@ typedef struct vlc_timer *vlc_timer_t;
# define VLC_THREAD_PRIORITY_OUTPUT 0 # define VLC_THREAD_PRIORITY_OUTPUT 0
# define VLC_THREAD_PRIORITY_HIGHEST 0 # define VLC_THREAD_PRIORITY_HIGHEST 0
static inline int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
{
int val;
do
{
int ugly_timeout = ((unsigned)timeout >= 50) ? 50 : timeout;
if (timeout >= 0)
timeout -= ugly_timeout;
vlc_testcancel ();
val = poll (fds, nfds, ugly_timeout);
}
while (val == 0 && timeout != 0);
return val;
}
# define poll(u,n,t) vlc_poll(u, n, t)
#elif defined (__APPLE__) #elif defined (__APPLE__)
# define _APPLE_C_SOURCE 1 /* Proper pthread semantics on OSX */ # define _APPLE_C_SOURCE 1 /* Proper pthread semantics on OSX */
# include <unistd.h> # include <unistd.h>
...@@ -150,7 +213,6 @@ typedef struct vlc_timer *vlc_timer_t; ...@@ -150,7 +213,6 @@ typedef struct vlc_timer *vlc_timer_t;
# include <mach/task.h> # include <mach/task.h>
# define LIBVLC_USE_PTHREAD 1 # define LIBVLC_USE_PTHREAD 1
# define LIBVLC_USE_PTHREAD_CLEANUP 1 # define LIBVLC_USE_PTHREAD_CLEANUP 1
# define LIBVLC_USE_PTHREAD_CANCEL 1
typedef pthread_t vlc_thread_t; typedef pthread_t vlc_thread_t;
typedef pthread_mutex_t vlc_mutex_t; typedef pthread_mutex_t vlc_mutex_t;
...@@ -180,7 +242,6 @@ typedef struct vlc_timer *vlc_timer_t; ...@@ -180,7 +242,6 @@ typedef struct vlc_timer *vlc_timer_t;
# include <semaphore.h> # include <semaphore.h>
# define LIBVLC_USE_PTHREAD 1 # define LIBVLC_USE_PTHREAD 1
# define LIBVLC_USE_PTHREAD_CLEANUP 1 # define LIBVLC_USE_PTHREAD_CLEANUP 1
# define LIBVLC_USE_PTHREAD_CANCEL 1
typedef pthread_t vlc_thread_t; typedef pthread_t vlc_thread_t;
typedef pthread_mutex_t vlc_mutex_t; typedef pthread_mutex_t vlc_mutex_t;
...@@ -324,10 +385,6 @@ VLC_API unsigned vlc_timer_getoverrun(vlc_timer_t) VLC_USED; ...@@ -324,10 +385,6 @@ VLC_API unsigned vlc_timer_getoverrun(vlc_timer_t) VLC_USED;
VLC_API unsigned vlc_GetCPUCount(void); VLC_API unsigned vlc_GetCPUCount(void);
VLC_API int vlc_savecancel(void);
VLC_API void vlc_restorecancel(int state);
VLC_API void vlc_testcancel(void);
#if defined (LIBVLC_USE_PTHREAD_CLEANUP) #if defined (LIBVLC_USE_PTHREAD_CLEANUP)
/** /**
* Registers a new procedure to run if the thread is cancelled (or otherwise * Registers a new procedure to run if the thread is cancelled (or otherwise
...@@ -388,51 +445,6 @@ struct vlc_cleanup_t ...@@ -388,51 +445,6 @@ struct vlc_cleanup_t
#endif /* !LIBVLC_USE_PTHREAD_CLEANUP */ #endif /* !LIBVLC_USE_PTHREAD_CLEANUP */
#ifndef LIBVLC_USE_PTHREAD_CANCEL
/* poll() with cancellation */
# ifdef __OS2__
static inline int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
{
static int (*vlc_poll_os2)(struct pollfd *, unsigned, int) = NULL;
if (!vlc_poll_os2)
{
HMODULE hmod;
CHAR szFailed[CCHMAXPATH];
if (DosLoadModule(szFailed, sizeof(szFailed), "vlccore", &hmod))
return -1;
if (DosQueryProcAddr(hmod, 0, "_vlc_poll_os2", (PFN *)&vlc_poll_os2))
return -1;
}
return (*vlc_poll_os2)(fds, nfds, timeout);
}
# else
static inline int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
{
int val;
do
{
int ugly_timeout = ((unsigned)timeout >= 50) ? 50 : timeout;
if (timeout >= 0)
timeout -= ugly_timeout;
vlc_testcancel ();
val = poll (fds, nfds, ugly_timeout);
}
while (val == 0 && timeout != 0);
return val;
}
# endif
# define poll(u,n,t) vlc_poll(u, n, t)
#endif /* LIBVLC_USE_PTHREAD_CANCEL */
static inline void vlc_cleanup_lock (void *lock) static inline void vlc_cleanup_lock (void *lock)
{ {
vlc_mutex_unlock ((vlc_mutex_t *)lock); vlc_mutex_unlock ((vlc_mutex_t *)lock);
......
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