VLC 4.0.0-dev
Loading...
Searching...
No Matches
vlc_poll.h
Go to the documentation of this file.
1/*****************************************************************************
2 * vlc_poll.h : poll implementation for the VideoLAN client
3 *****************************************************************************
4 * Copyright (C) 1999, 2002 VLC authors and VideoLAN
5 * Copyright © 2007-2016 Rémi Denis-Courmont
6 *
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@via.ecp.fr>
9 * Gildas Bazin <gbazin@netcourrier.com>
10 * Christophe Massiot <massiot@via.ecp.fr>
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU Lesser General Public License as published by
14 * the Free Software Foundation; either version 2.1 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this program; if not, write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
26
27#ifndef VLC_POLL_H_
28#define VLC_POLL_H_
29
30#include <vlc_threads.h>
31
32/**
33 * \ingroup os
34 * \defgroup thread_poll Poll implementations
35 * @{
36 * \file
37 * Poll implementations
38 */
39
40#if defined (_WIN32)
41static inline int vlc_poll(struct pollfd *fds, unsigned nfds, int timeout)
42{
43 int val;
44
46 val = poll(fds, nfds, timeout);
47 if (val < 0)
49 return val;
50}
51# define poll(u,n,t) vlc_poll(u, n, t)
52
53#elif defined (__OS2__)
54static inline int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
55{
56 static int (*vlc_poll_os2)(struct pollfd *, unsigned, int) = NULL;
57
58 if (!vlc_poll_os2)
59 {
60 HMODULE hmod;
61 CHAR szFailed[CCHMAXPATH];
62
63 if (DosLoadModule(szFailed, sizeof(szFailed), "vlccore", &hmod))
64 return -1;
65
66 if (DosQueryProcAddr(hmod, 0, "_vlc_poll_os2", (PFN *)&vlc_poll_os2))
67 return -1;
68 }
69
70 return (*vlc_poll_os2)(fds, nfds, timeout);
71}
72# define poll(u,n,t) vlc_poll(u, n, t)
73
74#elif defined (__ANDROID__) /* pthreads subset without pthread_cancel() */
75static inline int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
76{
77 int val;
78
79 do
80 {
81 int ugly_timeout = ((unsigned)timeout >= 50) ? 50 : timeout;
82 if (timeout >= 0)
83 timeout -= ugly_timeout;
84
86 val = poll (fds, nfds, ugly_timeout);
87 }
88 while (val == 0 && timeout != 0);
89
90 return val;
91}
92
93# define poll(u,n,t) vlc_poll(u, n, t)
94
95#else /* POSIX threads */
96
97#endif
98
99/** @} */
100
101#endif /* !VLC_POLL_H_ */
void vlc_testcancel(void)
Issues an explicit deferred cancellation point.
Definition thread.c:189
Definition vlc_fixups.h:501
This file is a collection of common definitions and types.
int poll(struct pollfd *, unsigned, int)
Thread primitive declarations.