2000-02-13 05:31:35 +01:00
|
|
|
/*****************************************************************************
|
2002-08-30 01:53:22 +02:00
|
|
|
* vlc_threads.h : threads implementation for the VideoLAN client
|
|
|
|
* This header provides portable declarations for mutexes & conditions
|
2000-03-03 08:03:34 +01:00
|
|
|
*****************************************************************************
|
LGPL
Re-license almost all of libVLC and libVLCcore to LGPLv2.1+
This move was authorized by the developers, either:
- by e-mail,
- by vote at the VideoLAN Dev Days 2011,
- on the license website,
- in a contract, oral or written.
No objection was raised, so far.
The developers agreeing are:
Justus Piater
Alexis Ballier
Alexander Bethke
Mohammed Adnène Trojette
Alex Converse
Alexey Sokolov
Alexis de Lattre
Andre Pang
Anthony Loiseau
Cyril Deguet
André Weber
Boris Dorès
Brieuc Jeunhomme
Benjamin Drung
Hugo Beauzée-Luyssen
Benoit Steiner
Benjamin Pracht
Bernie Purcell
Przemyslaw Fiala
Arnaud de Bossoreille de Ribou
Brad Smith
Nick Briggs
Christopher Rath
Christophe Courtaut
Christopher Mueller
Clement Chesnin
Andres Krapf
Damien Fouilleul
David Flynn
Sebastien Zwickert
Antoine Cellerier
Jérôme Decoodt
Jérome Decoodt
Dylan Yudaken
Eduard Babayan
Eugenio Jarosiewicz
Elliot Murphy
Eric Petit
Erwan Tulou
Etienne Membrives
Ludovic Fauvet
Fabio Ritrovato
Tobias Güntner
Jakub Wieczorek
Frédéric Crozat
Francois Cartegnie
Laurent Aimar
Florian G. Pflug
Felix Paul Kühne
Frank Enderle
Rafaël Carré
Simon Latapie
Gildas Bazin
Geoffroy Couprie
Julien / Gellule
Gildas Bazin
Arnaud Schauly
Toralf Niebuhr
Vicente Jimenez Aguilar
Derk-Jan Hartman
Henri Fallon
Ilkka Ollakka
Olivier Teulière
Rémi Duraffort
Jakob Leben
Jean-Baptiste Kempf
Jean-Paul Saman
Jean-Philippe Grimaldi
Jean-François Massol
Gaël Hendryckx
Jakob Leben
Jean-Marc Dressler
Jai Menon
Johan Bilien
Johann Ransay
Joris van Rooij
JP Dinger
Jean-Philippe André
Adrien Grand
Juha Jeronen
Juho Vähä-Herttua
Kaarlo Raiha
Kaarlo Raiha
Kamil Baldyga
Keary Griffin
Ken Self
KO Myung-Hun
Pierre Ynard
Filippo Carone
Loïc Minier
Luca Barbato
Lucas C. Villa Real
Lukas Durfina
Adrien Maglo
Marc Ariberti
Mark Lee
Mark Moriarty
Martin Storsjö
Christophe Massiot
Michel Kaempf
Marian Ďurkovič
Mirsal Ennaime
Carlo Calabrò
Damien Lucas
Naohiro Koriyama
Basos G
Pierre Baillet
Vincent Penquerc'h
Olivier Aubert
Pankaj Yadav
Paul Corke
Pierre d'Herbemont
Philippe Morin
Antoine Lejeune
Michael Ploujnikov
Jean-Marc Dressler
Michael Hanselmann
Rafaël Carré
Ramiro Polla
Rémi Denis-Courmont
Renaud Dartus
Richard Shepherd
Faustino Osuna
Arnaud Vallat
Rob Jonson
Robert Jedrzejczyk
Steve Lhomme
Rocky Bernstein
Romain Goyet
Rov Juvano
Sam Hocevar
Martin T. H. Sandsmark
Sebastian Birk
Sébastien Escudier
Vincent Seguin
Fabio Ritrovato
Sigmund Augdal Helberg
Casian Andrei
Srikanth Raju
Hannes Domani
Stéphane Borel
Stephan Krempel
Stephan Assmus
Tony Castley
Pavlov Konstantin
Eric Petit
Tanguy Krotoff
Dennis van Amerongen
Michel Lespinasse
Can Wu
Xavier Marchesini
Sébastien Toque
Christophe Mutricy
Yoann Peronneau
Yohann Martineau
Yuval Tze
Scott Caudle
Clément Stenac
It is possible, that some minor piece of code was badly tracked, for
some reasons (SVN, mainly) or that some small developers did not answer.
However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3",
and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and
the very vast majority of developers have agreed (> 99.99% of the code,
> 99% of developers), we are fine here.
2011-11-27 21:44:15 +01:00
|
|
|
* Copyright (C) 1999, 2002 VLC authors and VideoLAN
|
2008-07-06 19:55:17 +02:00
|
|
|
* Copyright © 2007-2008 Rémi Denis-Courmont
|
2000-03-03 08:03:34 +01:00
|
|
|
*
|
2000-03-09 13:30:15 +01:00
|
|
|
* Authors: Jean-Marc Dressler <polux@via.ecp.fr>
|
|
|
|
* Samuel Hocevar <sam@via.ecp.fr>
|
2002-04-28 00:11:22 +02:00
|
|
|
* Gildas Bazin <gbazin@netcourrier.com>
|
2002-08-30 01:53:22 +02:00
|
|
|
* Christophe Massiot <massiot@via.ecp.fr>
|
2000-03-03 08:03:34 +01:00
|
|
|
*
|
LGPL
Re-license almost all of libVLC and libVLCcore to LGPLv2.1+
This move was authorized by the developers, either:
- by e-mail,
- by vote at the VideoLAN Dev Days 2011,
- on the license website,
- in a contract, oral or written.
No objection was raised, so far.
The developers agreeing are:
Justus Piater
Alexis Ballier
Alexander Bethke
Mohammed Adnène Trojette
Alex Converse
Alexey Sokolov
Alexis de Lattre
Andre Pang
Anthony Loiseau
Cyril Deguet
André Weber
Boris Dorès
Brieuc Jeunhomme
Benjamin Drung
Hugo Beauzée-Luyssen
Benoit Steiner
Benjamin Pracht
Bernie Purcell
Przemyslaw Fiala
Arnaud de Bossoreille de Ribou
Brad Smith
Nick Briggs
Christopher Rath
Christophe Courtaut
Christopher Mueller
Clement Chesnin
Andres Krapf
Damien Fouilleul
David Flynn
Sebastien Zwickert
Antoine Cellerier
Jérôme Decoodt
Jérome Decoodt
Dylan Yudaken
Eduard Babayan
Eugenio Jarosiewicz
Elliot Murphy
Eric Petit
Erwan Tulou
Etienne Membrives
Ludovic Fauvet
Fabio Ritrovato
Tobias Güntner
Jakub Wieczorek
Frédéric Crozat
Francois Cartegnie
Laurent Aimar
Florian G. Pflug
Felix Paul Kühne
Frank Enderle
Rafaël Carré
Simon Latapie
Gildas Bazin
Geoffroy Couprie
Julien / Gellule
Gildas Bazin
Arnaud Schauly
Toralf Niebuhr
Vicente Jimenez Aguilar
Derk-Jan Hartman
Henri Fallon
Ilkka Ollakka
Olivier Teulière
Rémi Duraffort
Jakob Leben
Jean-Baptiste Kempf
Jean-Paul Saman
Jean-Philippe Grimaldi
Jean-François Massol
Gaël Hendryckx
Jakob Leben
Jean-Marc Dressler
Jai Menon
Johan Bilien
Johann Ransay
Joris van Rooij
JP Dinger
Jean-Philippe André
Adrien Grand
Juha Jeronen
Juho Vähä-Herttua
Kaarlo Raiha
Kaarlo Raiha
Kamil Baldyga
Keary Griffin
Ken Self
KO Myung-Hun
Pierre Ynard
Filippo Carone
Loïc Minier
Luca Barbato
Lucas C. Villa Real
Lukas Durfina
Adrien Maglo
Marc Ariberti
Mark Lee
Mark Moriarty
Martin Storsjö
Christophe Massiot
Michel Kaempf
Marian Ďurkovič
Mirsal Ennaime
Carlo Calabrò
Damien Lucas
Naohiro Koriyama
Basos G
Pierre Baillet
Vincent Penquerc'h
Olivier Aubert
Pankaj Yadav
Paul Corke
Pierre d'Herbemont
Philippe Morin
Antoine Lejeune
Michael Ploujnikov
Jean-Marc Dressler
Michael Hanselmann
Rafaël Carré
Ramiro Polla
Rémi Denis-Courmont
Renaud Dartus
Richard Shepherd
Faustino Osuna
Arnaud Vallat
Rob Jonson
Robert Jedrzejczyk
Steve Lhomme
Rocky Bernstein
Romain Goyet
Rov Juvano
Sam Hocevar
Martin T. H. Sandsmark
Sebastian Birk
Sébastien Escudier
Vincent Seguin
Fabio Ritrovato
Sigmund Augdal Helberg
Casian Andrei
Srikanth Raju
Hannes Domani
Stéphane Borel
Stephan Krempel
Stephan Assmus
Tony Castley
Pavlov Konstantin
Eric Petit
Tanguy Krotoff
Dennis van Amerongen
Michel Lespinasse
Can Wu
Xavier Marchesini
Sébastien Toque
Christophe Mutricy
Yoann Peronneau
Yohann Martineau
Yuval Tze
Scott Caudle
Clément Stenac
It is possible, that some minor piece of code was badly tracked, for
some reasons (SVN, mainly) or that some small developers did not answer.
However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3",
and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and
the very vast majority of developers have agreed (> 99.99% of the code,
> 99% of developers), we are fine here.
2011-11-27 21:44:15 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2.1 of the License, or
|
2000-03-03 08:03:34 +01:00
|
|
|
* (at your option) any later version.
|
2003-11-22 01:41:07 +01:00
|
|
|
*
|
2000-03-03 08:03:34 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
LGPL
Re-license almost all of libVLC and libVLCcore to LGPLv2.1+
This move was authorized by the developers, either:
- by e-mail,
- by vote at the VideoLAN Dev Days 2011,
- on the license website,
- in a contract, oral or written.
No objection was raised, so far.
The developers agreeing are:
Justus Piater
Alexis Ballier
Alexander Bethke
Mohammed Adnène Trojette
Alex Converse
Alexey Sokolov
Alexis de Lattre
Andre Pang
Anthony Loiseau
Cyril Deguet
André Weber
Boris Dorès
Brieuc Jeunhomme
Benjamin Drung
Hugo Beauzée-Luyssen
Benoit Steiner
Benjamin Pracht
Bernie Purcell
Przemyslaw Fiala
Arnaud de Bossoreille de Ribou
Brad Smith
Nick Briggs
Christopher Rath
Christophe Courtaut
Christopher Mueller
Clement Chesnin
Andres Krapf
Damien Fouilleul
David Flynn
Sebastien Zwickert
Antoine Cellerier
Jérôme Decoodt
Jérome Decoodt
Dylan Yudaken
Eduard Babayan
Eugenio Jarosiewicz
Elliot Murphy
Eric Petit
Erwan Tulou
Etienne Membrives
Ludovic Fauvet
Fabio Ritrovato
Tobias Güntner
Jakub Wieczorek
Frédéric Crozat
Francois Cartegnie
Laurent Aimar
Florian G. Pflug
Felix Paul Kühne
Frank Enderle
Rafaël Carré
Simon Latapie
Gildas Bazin
Geoffroy Couprie
Julien / Gellule
Gildas Bazin
Arnaud Schauly
Toralf Niebuhr
Vicente Jimenez Aguilar
Derk-Jan Hartman
Henri Fallon
Ilkka Ollakka
Olivier Teulière
Rémi Duraffort
Jakob Leben
Jean-Baptiste Kempf
Jean-Paul Saman
Jean-Philippe Grimaldi
Jean-François Massol
Gaël Hendryckx
Jakob Leben
Jean-Marc Dressler
Jai Menon
Johan Bilien
Johann Ransay
Joris van Rooij
JP Dinger
Jean-Philippe André
Adrien Grand
Juha Jeronen
Juho Vähä-Herttua
Kaarlo Raiha
Kaarlo Raiha
Kamil Baldyga
Keary Griffin
Ken Self
KO Myung-Hun
Pierre Ynard
Filippo Carone
Loïc Minier
Luca Barbato
Lucas C. Villa Real
Lukas Durfina
Adrien Maglo
Marc Ariberti
Mark Lee
Mark Moriarty
Martin Storsjö
Christophe Massiot
Michel Kaempf
Marian Ďurkovič
Mirsal Ennaime
Carlo Calabrò
Damien Lucas
Naohiro Koriyama
Basos G
Pierre Baillet
Vincent Penquerc'h
Olivier Aubert
Pankaj Yadav
Paul Corke
Pierre d'Herbemont
Philippe Morin
Antoine Lejeune
Michael Ploujnikov
Jean-Marc Dressler
Michael Hanselmann
Rafaël Carré
Ramiro Polla
Rémi Denis-Courmont
Renaud Dartus
Richard Shepherd
Faustino Osuna
Arnaud Vallat
Rob Jonson
Robert Jedrzejczyk
Steve Lhomme
Rocky Bernstein
Romain Goyet
Rov Juvano
Sam Hocevar
Martin T. H. Sandsmark
Sebastian Birk
Sébastien Escudier
Vincent Seguin
Fabio Ritrovato
Sigmund Augdal Helberg
Casian Andrei
Srikanth Raju
Hannes Domani
Stéphane Borel
Stephan Krempel
Stephan Assmus
Tony Castley
Pavlov Konstantin
Eric Petit
Tanguy Krotoff
Dennis van Amerongen
Michel Lespinasse
Can Wu
Xavier Marchesini
Sébastien Toque
Christophe Mutricy
Yoann Peronneau
Yohann Martineau
Yuval Tze
Scott Caudle
Clément Stenac
It is possible, that some minor piece of code was badly tracked, for
some reasons (SVN, mainly) or that some small developers did not answer.
However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3",
and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and
the very vast majority of developers have agreed (> 99.99% of the code,
> 99% of developers), we are fine here.
2011-11-27 21:44:15 +01:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
2000-03-03 08:03:34 +01:00
|
|
|
*
|
LGPL
Re-license almost all of libVLC and libVLCcore to LGPLv2.1+
This move was authorized by the developers, either:
- by e-mail,
- by vote at the VideoLAN Dev Days 2011,
- on the license website,
- in a contract, oral or written.
No objection was raised, so far.
The developers agreeing are:
Justus Piater
Alexis Ballier
Alexander Bethke
Mohammed Adnène Trojette
Alex Converse
Alexey Sokolov
Alexis de Lattre
Andre Pang
Anthony Loiseau
Cyril Deguet
André Weber
Boris Dorès
Brieuc Jeunhomme
Benjamin Drung
Hugo Beauzée-Luyssen
Benoit Steiner
Benjamin Pracht
Bernie Purcell
Przemyslaw Fiala
Arnaud de Bossoreille de Ribou
Brad Smith
Nick Briggs
Christopher Rath
Christophe Courtaut
Christopher Mueller
Clement Chesnin
Andres Krapf
Damien Fouilleul
David Flynn
Sebastien Zwickert
Antoine Cellerier
Jérôme Decoodt
Jérome Decoodt
Dylan Yudaken
Eduard Babayan
Eugenio Jarosiewicz
Elliot Murphy
Eric Petit
Erwan Tulou
Etienne Membrives
Ludovic Fauvet
Fabio Ritrovato
Tobias Güntner
Jakub Wieczorek
Frédéric Crozat
Francois Cartegnie
Laurent Aimar
Florian G. Pflug
Felix Paul Kühne
Frank Enderle
Rafaël Carré
Simon Latapie
Gildas Bazin
Geoffroy Couprie
Julien / Gellule
Gildas Bazin
Arnaud Schauly
Toralf Niebuhr
Vicente Jimenez Aguilar
Derk-Jan Hartman
Henri Fallon
Ilkka Ollakka
Olivier Teulière
Rémi Duraffort
Jakob Leben
Jean-Baptiste Kempf
Jean-Paul Saman
Jean-Philippe Grimaldi
Jean-François Massol
Gaël Hendryckx
Jakob Leben
Jean-Marc Dressler
Jai Menon
Johan Bilien
Johann Ransay
Joris van Rooij
JP Dinger
Jean-Philippe André
Adrien Grand
Juha Jeronen
Juho Vähä-Herttua
Kaarlo Raiha
Kaarlo Raiha
Kamil Baldyga
Keary Griffin
Ken Self
KO Myung-Hun
Pierre Ynard
Filippo Carone
Loïc Minier
Luca Barbato
Lucas C. Villa Real
Lukas Durfina
Adrien Maglo
Marc Ariberti
Mark Lee
Mark Moriarty
Martin Storsjö
Christophe Massiot
Michel Kaempf
Marian Ďurkovič
Mirsal Ennaime
Carlo Calabrò
Damien Lucas
Naohiro Koriyama
Basos G
Pierre Baillet
Vincent Penquerc'h
Olivier Aubert
Pankaj Yadav
Paul Corke
Pierre d'Herbemont
Philippe Morin
Antoine Lejeune
Michael Ploujnikov
Jean-Marc Dressler
Michael Hanselmann
Rafaël Carré
Ramiro Polla
Rémi Denis-Courmont
Renaud Dartus
Richard Shepherd
Faustino Osuna
Arnaud Vallat
Rob Jonson
Robert Jedrzejczyk
Steve Lhomme
Rocky Bernstein
Romain Goyet
Rov Juvano
Sam Hocevar
Martin T. H. Sandsmark
Sebastian Birk
Sébastien Escudier
Vincent Seguin
Fabio Ritrovato
Sigmund Augdal Helberg
Casian Andrei
Srikanth Raju
Hannes Domani
Stéphane Borel
Stephan Krempel
Stephan Assmus
Tony Castley
Pavlov Konstantin
Eric Petit
Tanguy Krotoff
Dennis van Amerongen
Michel Lespinasse
Can Wu
Xavier Marchesini
Sébastien Toque
Christophe Mutricy
Yoann Peronneau
Yohann Martineau
Yuval Tze
Scott Caudle
Clément Stenac
It is possible, that some minor piece of code was badly tracked, for
some reasons (SVN, mainly) or that some small developers did not answer.
However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3",
and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and
the very vast majority of developers have agreed (> 99.99% of the code,
> 99% of developers), we are fine here.
2011-11-27 21:44:15 +01:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
2000-02-13 05:31:35 +01:00
|
|
|
*****************************************************************************/
|
2000-03-03 08:03:34 +01:00
|
|
|
|
2008-08-11 18:13:10 +02:00
|
|
|
#ifndef VLC_THREADS_H_
|
|
|
|
#define VLC_THREADS_H_
|
Add facilities to report and enrich error messages.
The idea is that a given error should be reported only once to the user.
At the moment, for example, we can get:
- "no suitable access module" (printed by module_Need)
- "unable to create access" (printed by input/access)
- "unable to open stream" (printed by input/input)
- ...
The facilities provided here are:
* msg_StackSet( code, message ) : "throw" a new error
* msg_StackAdd( message ) : Append a message allowing to trace the message
* msg_StackMsg() : Retrieve the message
So, in the previous example, module_Need would msg_StackSet( code, "no
suitable access module"), then input/input would add "unable to create
access" and finally, input/input can print the "unable to open stream:
unable to create access: no suitable module" message.
The three functions are context-free, you don't need a vlc_object, so
that we can add verbose error reporting everywhere.
2006-12-22 22:14:11 +01:00
|
|
|
|
2008-08-11 17:31:57 +02:00
|
|
|
/**
|
2015-11-09 17:35:14 +01:00
|
|
|
* \ingroup os
|
|
|
|
* \defgroup thread Threads and synchronization primitives
|
|
|
|
* @{
|
2008-08-11 17:31:57 +02:00
|
|
|
* \file
|
2015-11-09 17:35:14 +01:00
|
|
|
* Thread primitive declarations
|
2008-08-11 17:31:57 +02:00
|
|
|
*/
|
|
|
|
|
2015-07-01 20:35:09 +02:00
|
|
|
/**
|
|
|
|
* Issues an explicit deferred cancellation point.
|
|
|
|
*
|
|
|
|
* This has no effects if thread cancellation is disabled.
|
|
|
|
* This can be called when there is a rather slow non-sleeping operation.
|
|
|
|
* This is also used to force a cancellation point in a function that would
|
|
|
|
* otherwise <em>not always</em> be a one (block_FifoGet() is an example).
|
|
|
|
*/
|
2015-05-09 14:19:26 +02:00
|
|
|
VLC_API void vlc_testcancel(void);
|
|
|
|
|
2013-06-05 15:41:18 +02:00
|
|
|
#if defined (_WIN32)
|
2012-10-13 10:55:51 +02:00
|
|
|
# include <process.h>
|
|
|
|
# ifndef ETIMEDOUT
|
|
|
|
# define ETIMEDOUT 10060 /* This is the value in winsock.h. */
|
|
|
|
# endif
|
2010-05-06 16:52:57 +02:00
|
|
|
|
2010-11-29 19:26:08 +01:00
|
|
|
typedef struct vlc_thread *vlc_thread_t;
|
2015-12-13 10:20:33 +01:00
|
|
|
#define VLC_THREAD_CANCELED NULL
|
2008-09-07 19:21:41 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2009-12-30 14:54:54 +01:00
|
|
|
bool dynamic;
|
|
|
|
union
|
|
|
|
{
|
2009-12-30 15:08:07 +01:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
bool locked;
|
|
|
|
unsigned long contention;
|
|
|
|
};
|
2009-12-30 14:54:54 +01:00
|
|
|
CRITICAL_SECTION mutex;
|
|
|
|
};
|
2008-10-05 10:19:00 +02:00
|
|
|
} vlc_mutex_t;
|
2009-12-30 15:08:07 +01:00
|
|
|
#define VLC_STATIC_MUTEX { false, { { false, 0 } } }
|
2010-02-08 17:46:02 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
2015-05-17 15:00:10 +02:00
|
|
|
HANDLE semaphore;
|
|
|
|
LONG waiters;
|
2010-02-08 17:46:02 +01:00
|
|
|
unsigned clock;
|
|
|
|
} vlc_cond_t;
|
2015-05-17 15:00:10 +02:00
|
|
|
#define VLC_STATIC_COND { NULL, 0, 0 }
|
2012-09-11 11:31:14 +02:00
|
|
|
typedef HANDLE vlc_sem_t;
|
|
|
|
#define LIBVLC_NEED_RWLOCK
|
2010-11-23 22:24:19 +01:00
|
|
|
typedef struct vlc_threadvar *vlc_threadvar_t;
|
2009-08-02 14:01:04 +02:00
|
|
|
typedef struct vlc_timer *vlc_timer_t;
|
2011-10-11 14:55:32 +02:00
|
|
|
|
2012-10-13 10:55:51 +02:00
|
|
|
# define VLC_THREAD_PRIORITY_LOW 0
|
|
|
|
# define VLC_THREAD_PRIORITY_INPUT THREAD_PRIORITY_ABOVE_NORMAL
|
|
|
|
# define VLC_THREAD_PRIORITY_AUDIO THREAD_PRIORITY_HIGHEST
|
|
|
|
# define VLC_THREAD_PRIORITY_VIDEO 0
|
|
|
|
# define VLC_THREAD_PRIORITY_OUTPUT THREAD_PRIORITY_ABOVE_NORMAL
|
|
|
|
# define VLC_THREAD_PRIORITY_HIGHEST THREAD_PRIORITY_TIME_CRITICAL
|
|
|
|
|
2015-05-09 14:19:26 +02:00
|
|
|
static inline int vlc_poll(struct pollfd *fds, unsigned nfds, int timeout)
|
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
2015-05-09 14:23:02 +02:00
|
|
|
vlc_testcancel();
|
|
|
|
val = poll(fds, nfds, timeout);
|
|
|
|
if (val < 0)
|
|
|
|
vlc_testcancel();
|
2015-05-09 14:19:26 +02:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
# define poll(u,n,t) vlc_poll(u, n, t)
|
|
|
|
|
2012-10-13 10:55:51 +02:00
|
|
|
#elif defined (__OS2__)
|
|
|
|
# include <errno.h>
|
2011-10-11 14:55:32 +02:00
|
|
|
|
2012-10-13 10:55:51 +02:00
|
|
|
typedef struct vlc_thread *vlc_thread_t;
|
2015-12-13 10:20:33 +01:00
|
|
|
#define VLC_THREAD_CANCELED NULL
|
2011-10-11 14:55:32 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
bool dynamic;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
bool locked;
|
|
|
|
unsigned long contention;
|
|
|
|
};
|
|
|
|
HMTX hmtx;
|
|
|
|
};
|
|
|
|
} vlc_mutex_t;
|
|
|
|
#define VLC_STATIC_MUTEX { false, { { false, 0 } } }
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
HEV hev;
|
2015-06-10 05:27:28 +02:00
|
|
|
unsigned waiters;
|
|
|
|
HEV hevAck;
|
|
|
|
unsigned signaled;
|
2011-10-11 14:55:32 +02:00
|
|
|
unsigned clock;
|
|
|
|
} vlc_cond_t;
|
2015-06-10 05:27:28 +02:00
|
|
|
#define VLC_STATIC_COND { NULLHANDLE, 0, NULLHANDLE, 0, 0 }
|
2012-09-11 11:31:14 +02:00
|
|
|
#define LIBVLC_NEED_SEMAPHORE
|
|
|
|
#define LIBVLC_NEED_RWLOCK
|
2011-10-11 14:55:32 +02:00
|
|
|
typedef struct vlc_threadvar *vlc_threadvar_t;
|
|
|
|
typedef struct vlc_timer *vlc_timer_t;
|
|
|
|
|
2012-10-13 10:55:51 +02:00
|
|
|
# define VLC_THREAD_PRIORITY_LOW 0
|
|
|
|
# define VLC_THREAD_PRIORITY_INPUT \
|
|
|
|
MAKESHORT(PRTYD_MAXIMUM / 2, PRTYC_REGULAR)
|
|
|
|
# define VLC_THREAD_PRIORITY_AUDIO MAKESHORT(PRTYD_MAXIMUM, PRTYC_REGULAR)
|
|
|
|
# define VLC_THREAD_PRIORITY_VIDEO 0
|
|
|
|
# define VLC_THREAD_PRIORITY_OUTPUT \
|
|
|
|
MAKESHORT(PRTYD_MAXIMUM / 2, PRTYC_REGULAR)
|
|
|
|
# define VLC_THREAD_PRIORITY_HIGHEST MAKESHORT(0, PRTYC_TIMECRITICAL)
|
|
|
|
|
|
|
|
# define pthread_sigmask sigprocmask
|
|
|
|
|
2015-05-09 14:19:26 +02:00
|
|
|
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)
|
|
|
|
|
2012-10-13 10:55:51 +02:00
|
|
|
#elif defined (__ANDROID__) /* pthreads subset without pthread_cancel() */
|
|
|
|
# include <unistd.h>
|
|
|
|
# include <pthread.h>
|
|
|
|
# include <poll.h>
|
|
|
|
# define LIBVLC_USE_PTHREAD_CLEANUP 1
|
|
|
|
# define LIBVLC_NEED_SEMAPHORE
|
|
|
|
# define LIBVLC_NEED_RWLOCK
|
|
|
|
|
|
|
|
typedef struct vlc_thread *vlc_thread_t;
|
2015-12-13 10:20:33 +01:00
|
|
|
#define VLC_THREAD_CANCELED NULL
|
2012-10-13 10:55:51 +02:00
|
|
|
typedef pthread_mutex_t vlc_mutex_t;
|
2015-07-01 20:35:09 +02:00
|
|
|
|
2012-10-13 10:55:51 +02:00
|
|
|
#define VLC_STATIC_MUTEX PTHREAD_MUTEX_INITIALIZER
|
2012-10-15 19:53:49 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
pthread_cond_t cond;
|
|
|
|
unsigned clock;
|
|
|
|
} vlc_cond_t;
|
|
|
|
#define VLC_STATIC_COND { PTHREAD_COND_INITIALIZER, CLOCK_REALTIME }
|
2012-10-13 10:55:51 +02:00
|
|
|
|
|
|
|
typedef pthread_key_t vlc_threadvar_t;
|
|
|
|
typedef struct vlc_timer *vlc_timer_t;
|
|
|
|
|
|
|
|
# define VLC_THREAD_PRIORITY_LOW 0
|
|
|
|
# define VLC_THREAD_PRIORITY_INPUT 0
|
|
|
|
# define VLC_THREAD_PRIORITY_AUDIO 0
|
|
|
|
# define VLC_THREAD_PRIORITY_VIDEO 0
|
|
|
|
# define VLC_THREAD_PRIORITY_OUTPUT 0
|
|
|
|
# define VLC_THREAD_PRIORITY_HIGHEST 0
|
|
|
|
|
2015-05-09 14:19:26 +02:00
|
|
|
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)
|
|
|
|
|
2012-10-13 10:55:51 +02:00
|
|
|
#elif defined (__APPLE__)
|
|
|
|
# define _APPLE_C_SOURCE 1 /* Proper pthread semantics on OSX */
|
|
|
|
# include <unistd.h>
|
|
|
|
# include <pthread.h>
|
|
|
|
/* Unnamed POSIX semaphores not supported on Mac OS X */
|
|
|
|
# include <mach/semaphore.h>
|
|
|
|
# include <mach/task.h>
|
|
|
|
# define LIBVLC_USE_PTHREAD 1
|
|
|
|
# define LIBVLC_USE_PTHREAD_CLEANUP 1
|
|
|
|
|
|
|
|
typedef pthread_t vlc_thread_t;
|
2015-12-13 10:20:33 +01:00
|
|
|
#define VLC_THREAD_CANCELED PTHREAD_CANCELED
|
2012-10-13 10:55:51 +02:00
|
|
|
typedef pthread_mutex_t vlc_mutex_t;
|
|
|
|
#define VLC_STATIC_MUTEX PTHREAD_MUTEX_INITIALIZER
|
2013-12-31 11:41:55 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
pthread_cond_t cond;
|
|
|
|
unsigned clock;
|
|
|
|
} vlc_cond_t;
|
|
|
|
#define VLC_STATIC_COND { PTHREAD_COND_INITIALIZER, 0 }
|
2012-10-13 10:55:51 +02:00
|
|
|
typedef semaphore_t vlc_sem_t;
|
|
|
|
typedef pthread_rwlock_t vlc_rwlock_t;
|
|
|
|
#define VLC_STATIC_RWLOCK PTHREAD_RWLOCK_INITIALIZER
|
|
|
|
typedef pthread_key_t vlc_threadvar_t;
|
|
|
|
typedef struct vlc_timer *vlc_timer_t;
|
|
|
|
|
|
|
|
# define VLC_THREAD_PRIORITY_LOW 0
|
|
|
|
# define VLC_THREAD_PRIORITY_INPUT 22
|
|
|
|
# define VLC_THREAD_PRIORITY_AUDIO 22
|
|
|
|
# define VLC_THREAD_PRIORITY_VIDEO 0
|
|
|
|
# define VLC_THREAD_PRIORITY_OUTPUT 22
|
|
|
|
# define VLC_THREAD_PRIORITY_HIGHEST 22
|
|
|
|
|
|
|
|
#else /* POSIX threads */
|
|
|
|
# include <unistd.h> /* _POSIX_SPIN_LOCKS */
|
|
|
|
# include <pthread.h>
|
|
|
|
# include <semaphore.h>
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether LibVLC threads are based on POSIX threads.
|
|
|
|
*/
|
2012-10-13 10:55:51 +02:00
|
|
|
# define LIBVLC_USE_PTHREAD 1
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether LibVLC thread cancellation is based on POSIX threads.
|
|
|
|
*/
|
2012-10-13 10:55:51 +02:00
|
|
|
# define LIBVLC_USE_PTHREAD_CLEANUP 1
|
|
|
|
|
2015-07-01 20:35:09 +02:00
|
|
|
/**
|
|
|
|
* Thread handle.
|
|
|
|
*/
|
2012-10-13 10:55:51 +02:00
|
|
|
typedef pthread_t vlc_thread_t;
|
2015-07-01 20:35:09 +02:00
|
|
|
|
2015-12-13 10:20:33 +01:00
|
|
|
/**
|
|
|
|
* Return value of a canceled thread.
|
|
|
|
*/
|
|
|
|
#define VLC_THREAD_CANCELED PTHREAD_CANCELED
|
|
|
|
|
2015-07-01 20:35:09 +02:00
|
|
|
/**
|
|
|
|
* Mutex.
|
|
|
|
*
|
|
|
|
* Storage space for a mutual exclusion lock.
|
|
|
|
*/
|
2012-10-13 10:55:51 +02:00
|
|
|
typedef pthread_mutex_t vlc_mutex_t;
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Static initializer for (static) mutex.
|
|
|
|
*/
|
2012-10-13 10:55:51 +02:00
|
|
|
#define VLC_STATIC_MUTEX PTHREAD_MUTEX_INITIALIZER
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Condition variable.
|
|
|
|
*
|
|
|
|
* Storage space for a thread condition variable.
|
|
|
|
*/
|
2012-10-13 10:55:51 +02:00
|
|
|
typedef pthread_cond_t vlc_cond_t;
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Static initializer for (static) condition variable.
|
|
|
|
*/
|
2012-10-13 10:55:51 +02:00
|
|
|
#define VLC_STATIC_COND PTHREAD_COND_INITIALIZER
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Semaphore.
|
|
|
|
*
|
|
|
|
* Storage space for a thread-safe semaphore.
|
|
|
|
*/
|
2012-10-13 10:55:51 +02:00
|
|
|
typedef sem_t vlc_sem_t;
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read/write lock.
|
|
|
|
*
|
|
|
|
* Storage space for a slim reader/writer lock.
|
|
|
|
*/
|
2012-10-13 10:55:51 +02:00
|
|
|
typedef pthread_rwlock_t vlc_rwlock_t;
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Static initializer for (static) read/write lock.
|
|
|
|
*/
|
2012-10-13 10:55:51 +02:00
|
|
|
#define VLC_STATIC_RWLOCK PTHREAD_RWLOCK_INITIALIZER
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Thread-local key handle.
|
|
|
|
*/
|
2012-10-13 10:55:51 +02:00
|
|
|
typedef pthread_key_t vlc_threadvar_t;
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Threaded timer handle.
|
|
|
|
*/
|
2012-10-13 10:55:51 +02:00
|
|
|
typedef struct vlc_timer *vlc_timer_t;
|
|
|
|
|
|
|
|
# define VLC_THREAD_PRIORITY_LOW 0
|
|
|
|
# define VLC_THREAD_PRIORITY_INPUT 10
|
|
|
|
# define VLC_THREAD_PRIORITY_AUDIO 5
|
|
|
|
# define VLC_THREAD_PRIORITY_VIDEO 0
|
|
|
|
# define VLC_THREAD_PRIORITY_OUTPUT 15
|
|
|
|
# define VLC_THREAD_PRIORITY_HIGHEST 20
|
|
|
|
|
2008-05-08 21:07:35 +02:00
|
|
|
#endif
|
|
|
|
|
2012-09-11 11:31:14 +02:00
|
|
|
#ifdef LIBVLC_NEED_SEMAPHORE
|
|
|
|
typedef struct vlc_sem
|
|
|
|
{
|
|
|
|
vlc_mutex_t lock;
|
|
|
|
vlc_cond_t wait;
|
|
|
|
unsigned value;
|
|
|
|
} vlc_sem_t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LIBVLC_NEED_RWLOCK
|
|
|
|
typedef struct vlc_rwlock
|
2012-09-10 17:21:38 +02:00
|
|
|
{
|
|
|
|
vlc_mutex_t mutex;
|
|
|
|
vlc_cond_t wait;
|
|
|
|
long state;
|
2012-09-11 11:31:14 +02:00
|
|
|
} vlc_rwlock_t;
|
2012-09-10 17:21:38 +02:00
|
|
|
# define VLC_STATIC_RWLOCK { VLC_STATIC_MUTEX, VLC_STATIC_COND, 0 }
|
|
|
|
#endif
|
|
|
|
|
2015-07-01 20:35:09 +02:00
|
|
|
/**
|
|
|
|
* Initializes a fast mutex.
|
|
|
|
*
|
|
|
|
* Recursive locking of a fast mutex is undefined behaviour. (In debug builds,
|
|
|
|
* recursive locking will cause an assertion failure.)
|
|
|
|
*/
|
|
|
|
VLC_API void vlc_mutex_init(vlc_mutex_t *);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a recursive mutex.
|
|
|
|
* \warning This is strongly discouraged. Please use normal mutexes.
|
|
|
|
*/
|
|
|
|
VLC_API void vlc_mutex_init_recursive(vlc_mutex_t *);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deinitializes a mutex.
|
|
|
|
*
|
|
|
|
* The mutex must not be locked, otherwise behaviour is undefined.
|
|
|
|
*/
|
|
|
|
VLC_API void vlc_mutex_destroy(vlc_mutex_t *);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Acquires a mutex.
|
|
|
|
*
|
|
|
|
* If needed, this waits for any other thread to release it.
|
|
|
|
*
|
|
|
|
* \warning Beware of deadlocks when locking multiple mutexes at the same time,
|
|
|
|
* or when using mutexes from callbacks.
|
|
|
|
*
|
|
|
|
* \note This function is not a cancellation-point.
|
|
|
|
*/
|
|
|
|
VLC_API void vlc_mutex_lock(vlc_mutex_t *);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tries to acquire a mutex.
|
|
|
|
*
|
|
|
|
* This function acquires the mutex if and only if it is not currently held by
|
|
|
|
* another thread. This function never sleeps and can be used in delay-critical
|
|
|
|
* code paths.
|
|
|
|
*
|
|
|
|
* \note This function is not a cancellation-point.
|
|
|
|
*
|
|
|
|
* \warning If this function fails, then the mutex is held... by another
|
|
|
|
* thread. The calling thread must deal with the error appropriately. That
|
|
|
|
* typically implies postponing the operations that would have required the
|
|
|
|
* mutex. If the thread cannot defer those operations, then it must use
|
|
|
|
* vlc_mutex_lock(). If in doubt, use vlc_mutex_lock() instead.
|
|
|
|
*
|
|
|
|
* @return 0 if the mutex could be acquired, an error code otherwise.
|
|
|
|
*/
|
2011-05-07 22:02:08 +02:00
|
|
|
VLC_API int vlc_mutex_trylock( vlc_mutex_t * ) VLC_USED;
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Releases a mutex.
|
|
|
|
*
|
|
|
|
* If the mutex is not held by the calling thread, the behaviour is undefined.
|
|
|
|
*/
|
|
|
|
VLC_API void vlc_mutex_unlock(vlc_mutex_t *);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a condition variable.
|
|
|
|
*/
|
|
|
|
VLC_API void vlc_cond_init(vlc_cond_t *);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a condition variable (wall clock).
|
|
|
|
*
|
|
|
|
* Contrary to vlc_cond_init(), the wall clock will be used as a reference for
|
|
|
|
* the vlc_cond_timedwait() time-out parameter.
|
|
|
|
*/
|
|
|
|
VLC_API void vlc_cond_init_daytime(vlc_cond_t *);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deinitializes a condition variable.
|
|
|
|
*
|
|
|
|
* No threads shall be waiting or signaling the condition, otherwise the
|
|
|
|
* behavior is undefined.
|
|
|
|
*/
|
|
|
|
VLC_API void vlc_cond_destroy(vlc_cond_t *);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wakes up one thread waiting on a condition variable.
|
|
|
|
*
|
|
|
|
* If any thread is currently waiting on the condition variable, at least one
|
|
|
|
* of those threads will be woken up. Otherwise, this function has no effects.
|
|
|
|
*/
|
2011-05-07 13:06:21 +02:00
|
|
|
VLC_API void vlc_cond_signal(vlc_cond_t *);
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wakes up all threads waiting on a condition variable.
|
|
|
|
*/
|
2011-05-07 13:06:21 +02:00
|
|
|
VLC_API void vlc_cond_broadcast(vlc_cond_t *);
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Waits on a condition variable.
|
|
|
|
*
|
|
|
|
* The calling thread will be suspended until another thread calls
|
|
|
|
* vlc_cond_signal() or vlc_cond_broadcast() on the same condition variable,
|
|
|
|
* the thread is cancelled with vlc_cancel(), or the system causes a
|
|
|
|
* <em>spurious</em> unsolicited wake-up.
|
|
|
|
*
|
|
|
|
* A mutex is needed to wait on a condition variable. It must <b>not</b> be
|
|
|
|
* a recursive mutex. Although it is possible to use the same mutex for
|
|
|
|
* multiple condition, it is not valid to use different mutexes for the same
|
|
|
|
* condition variable at the same time from different threads.
|
|
|
|
*
|
|
|
|
* The canonical way to use a condition variable to wait for event foobar is:
|
|
|
|
@code
|
|
|
|
vlc_mutex_lock(&lock);
|
|
|
|
mutex_cleanup_push(&lock); // release the mutex in case of cancellation
|
|
|
|
|
|
|
|
while (!foobar)
|
|
|
|
vlc_cond_wait(&wait, &lock);
|
|
|
|
|
|
|
|
// -- foobar is now true, do something about it here --
|
|
|
|
|
2015-07-07 20:47:32 +02:00
|
|
|
vlc_cleanup_pop();
|
|
|
|
vlc_mutex_unlock(&lock);
|
2015-07-01 20:35:09 +02:00
|
|
|
@endcode
|
|
|
|
*
|
|
|
|
* \note This function is a cancellation point. In case of thread cancellation,
|
|
|
|
* the mutex is always locked before cancellation proceeds.
|
|
|
|
*
|
|
|
|
* \param cond condition variable to wait on
|
|
|
|
* \param mutex mutex which is unlocked while waiting,
|
|
|
|
* then locked again when waking up.
|
|
|
|
*/
|
|
|
|
VLC_API void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t *mutex);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Waits on a condition variable up to a certain date.
|
|
|
|
*
|
|
|
|
* This works like vlc_cond_wait() but with an additional time-out.
|
|
|
|
*
|
|
|
|
* If the variable was initialized with vlc_cond_init(), the timeout has the
|
|
|
|
* same arbitrary origin as mdate(). If the variable was initialized with
|
|
|
|
* vlc_cond_init_daytime(), or was statically initialized with
|
|
|
|
* \ref VLC_STATIC_COND, the timeout is expressed from the Unix epoch (i.e.
|
|
|
|
* the wall clock).
|
|
|
|
*
|
|
|
|
* \param p_condvar condition variable to wait on
|
|
|
|
* \param p_mutex mutex which is unlocked while waiting,
|
|
|
|
* then locked again when waking up.
|
|
|
|
* \param deadline <b>absolute</b> timeout
|
|
|
|
*
|
|
|
|
* \return 0 if the condition was signaled, an error code in case of timeout.
|
|
|
|
*/
|
|
|
|
VLC_API int vlc_cond_timedwait(vlc_cond_t *cond, vlc_mutex_t *mutex,
|
|
|
|
mtime_t deadline);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a semaphore.
|
|
|
|
*
|
|
|
|
* @param count initial semaphore value (typically 0)
|
|
|
|
*/
|
|
|
|
VLC_API void vlc_sem_init(vlc_sem_t *, unsigned count);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deinitializes a semaphore.
|
|
|
|
*/
|
2011-05-07 13:06:21 +02:00
|
|
|
VLC_API void vlc_sem_destroy(vlc_sem_t *);
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Increments the value of a semaphore.
|
|
|
|
* @return 0 on success, EOVERFLOW in case of integer overflow.
|
|
|
|
*/
|
2011-05-07 13:06:21 +02:00
|
|
|
VLC_API int vlc_sem_post(vlc_sem_t *);
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Waits on a semaphore.
|
|
|
|
*
|
|
|
|
* This function atomically waits for the semaphore to become non-zero then
|
|
|
|
* decrements it, and returns. If the semaphore is non-zero on entry, it is
|
|
|
|
* immediately decremented.
|
|
|
|
*
|
|
|
|
* \note This function may be a point of cancellation.
|
|
|
|
*/
|
2011-05-07 13:06:21 +02:00
|
|
|
VLC_API void vlc_sem_wait(vlc_sem_t *);
|
|
|
|
|
2015-07-01 20:35:09 +02:00
|
|
|
/**
|
|
|
|
* Initializes a read/write lock.
|
|
|
|
*/
|
2011-05-07 13:06:21 +02:00
|
|
|
VLC_API void vlc_rwlock_init(vlc_rwlock_t *);
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys an initialized unused read/write lock.
|
|
|
|
*/
|
2011-05-07 13:06:21 +02:00
|
|
|
VLC_API void vlc_rwlock_destroy(vlc_rwlock_t *);
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Acquires a read/write lock for reading.
|
|
|
|
*
|
|
|
|
* \note Recursion is allowed.
|
|
|
|
* \note This function may be a point of cancellation.
|
|
|
|
*/
|
2011-05-07 13:06:21 +02:00
|
|
|
VLC_API void vlc_rwlock_rdlock(vlc_rwlock_t *);
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Acquires a read/write lock for writing. Recursion is not allowed.
|
|
|
|
* \note This function may be a point of cancellation.
|
|
|
|
*/
|
2011-05-07 13:06:21 +02:00
|
|
|
VLC_API void vlc_rwlock_wrlock(vlc_rwlock_t *);
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Releases a read/write lock.
|
|
|
|
*
|
|
|
|
* The calling thread must hold the lock. Otherwise behaviour is undefined.
|
|
|
|
*/
|
2011-05-07 13:06:21 +02:00
|
|
|
VLC_API void vlc_rwlock_unlock(vlc_rwlock_t *);
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a thread-specific variable.
|
|
|
|
*
|
|
|
|
* @param key where to store the thread-specific variable handle
|
|
|
|
* @param destr a destruction callback. It is called whenever a thread exits
|
|
|
|
* and the thread-specific variable has a non-NULL value.
|
|
|
|
*
|
|
|
|
* @return 0 on success, a system error code otherwise.
|
|
|
|
* This function can actually fail: on most systems, there is a fixed limit to
|
|
|
|
* the number of thread-specific variables in a given process.
|
|
|
|
*/
|
|
|
|
VLC_API int vlc_threadvar_create(vlc_threadvar_t *key, void (*destr) (void *));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deallocates a thread-specific variable.
|
|
|
|
*/
|
2011-05-07 13:06:21 +02:00
|
|
|
VLC_API void vlc_threadvar_delete(vlc_threadvar_t *);
|
2011-05-22 22:30:32 +02:00
|
|
|
|
2015-07-01 20:35:09 +02:00
|
|
|
/**
|
|
|
|
* Sets a thread-specific variable.
|
|
|
|
|
|
|
|
* \param key thread-local variable key (created with vlc_threadvar_create())
|
|
|
|
* \param value new value for the variable for the calling thread
|
|
|
|
* \return 0 on success, a system error code otherwise.
|
|
|
|
*/
|
|
|
|
VLC_API int vlc_threadvar_set(vlc_threadvar_t key, void *value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the value of a thread-local variable for the calling thread.
|
|
|
|
* This function cannot fail.
|
|
|
|
*
|
|
|
|
* \return the value associated with the given variable for the calling
|
|
|
|
* or NULL if no value was set.
|
|
|
|
*/
|
|
|
|
VLC_API void *vlc_threadvar_get(vlc_threadvar_t);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and starts a new thread.
|
|
|
|
*
|
|
|
|
* The thread must be <i>joined</i> with vlc_join() to reclaim resources
|
|
|
|
* when it is not needed anymore.
|
|
|
|
*
|
|
|
|
* @param th [OUT] pointer to write the handle of the created thread to
|
|
|
|
* (mandatory, must be non-NULL)
|
|
|
|
* @param entry entry point for the thread
|
|
|
|
* @param data data parameter given to the entry point
|
|
|
|
* @param priority thread priority value
|
|
|
|
* @return 0 on success, a standard error code on error.
|
|
|
|
*/
|
|
|
|
VLC_API int vlc_clone(vlc_thread_t *th, void *(*entry)(void *), void *data,
|
|
|
|
int priority) VLC_USED;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks a thread as cancelled.
|
|
|
|
*
|
|
|
|
* Next time the target thread reaches a cancellation point (while not having
|
|
|
|
* disabled cancellation), it will run its cancellation cleanup handler, the
|
|
|
|
* thread variable destructors, and terminate.
|
|
|
|
*
|
|
|
|
* vlc_join() must be used regardless of a thread being cancelled or not, to
|
|
|
|
* avoid leaking resources.
|
|
|
|
*/
|
2011-05-07 13:06:21 +02:00
|
|
|
VLC_API void vlc_cancel(vlc_thread_t);
|
|
|
|
|
2015-07-01 20:35:09 +02:00
|
|
|
/**
|
|
|
|
* Waits for a thread to complete (if needed), then destroys it.
|
|
|
|
*
|
|
|
|
* \note This is a cancellation point. In case of cancellation, the thread is
|
|
|
|
* <b>not</b> joined.
|
|
|
|
|
|
|
|
* \warning A thread cannot join itself (normally VLC will abort if this is
|
|
|
|
* attempted). Also a detached thread <b>cannot</b> be joined.
|
|
|
|
*
|
|
|
|
* @param th thread handle
|
|
|
|
* @param result [OUT] pointer to write the thread return value or NULL
|
|
|
|
*/
|
|
|
|
VLC_API void vlc_join(vlc_thread_t th, void **result);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disables thread cancellation.
|
|
|
|
*
|
|
|
|
* This functions saves the current cancellation state (enabled or disabled),
|
|
|
|
* then disables cancellation for the calling thread. It must be called before
|
|
|
|
* entering a piece of code that is not cancellation-safe, unless it can be
|
|
|
|
* proven that the calling thread will not be cancelled.
|
|
|
|
*
|
|
|
|
* \note This function is not a cancellation point.
|
|
|
|
*
|
|
|
|
* \return Previous cancellation state (opaque value for vlc_restorecancel()).
|
|
|
|
*/
|
|
|
|
VLC_API int vlc_savecancel(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restores the cancellation state.
|
|
|
|
*
|
|
|
|
* This function restores the cancellation state of the calling thread to
|
|
|
|
* a state previously saved by vlc_savecancel().
|
|
|
|
*
|
|
|
|
* \note This function is not a cancellation point.
|
|
|
|
*
|
|
|
|
* \param state previous state as returned by vlc_savecancel().
|
|
|
|
*/
|
|
|
|
VLC_API void vlc_restorecancel(int state);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal handler for thread cancellation.
|
|
|
|
*
|
|
|
|
* Do not call this function directly. Use wrapper macros instead:
|
2015-07-08 20:13:20 +02:00
|
|
|
* vlc_cleanup_push(), vlc_cleanup_pop().
|
2015-07-01 20:35:09 +02:00
|
|
|
*/
|
|
|
|
VLC_API void vlc_control_cancel(int cmd, ...);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Precision monotonic clock.
|
|
|
|
*
|
|
|
|
* In principles, the clock has a precision of 1 MHz. But the actual resolution
|
|
|
|
* may be much lower, especially when it comes to sleeping with mwait() or
|
|
|
|
* msleep(). Most general-purpose operating systems provide a resolution of
|
|
|
|
* only 100 to 1000 Hz.
|
|
|
|
*
|
|
|
|
* \warning The origin date (time value "zero") is not specified. It is
|
|
|
|
* typically the time the kernel started, but this is platform-dependent.
|
|
|
|
* If you need wall clock time, use gettimeofday() instead.
|
|
|
|
*
|
|
|
|
* \return a timestamp in microseconds.
|
|
|
|
*/
|
2011-07-12 17:02:54 +02:00
|
|
|
VLC_API mtime_t mdate(void);
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Waits until a deadline.
|
|
|
|
*
|
|
|
|
* \param deadline timestamp to wait for (\ref mdate())
|
|
|
|
*
|
|
|
|
* \note The deadline may be exceeded due to OS scheduling.
|
|
|
|
*/
|
2011-07-12 17:02:54 +02:00
|
|
|
VLC_API void mwait(mtime_t deadline);
|
2015-07-01 20:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Waits for an interval of time.
|
|
|
|
*
|
|
|
|
* @param delay how long to wait (in microseconds)
|
|
|
|
*/
|
2011-07-12 17:02:54 +02:00
|
|
|
VLC_API void msleep(mtime_t delay);
|
|
|
|
|
|
|
|
#define VLC_HARD_MIN_SLEEP 10000 /* 10 milliseconds = 1 tick at 100Hz */
|
|
|
|
#define VLC_SOFT_MIN_SLEEP 9000000 /* 9 seconds */
|
|
|
|
|
2011-08-17 17:28:25 +02:00
|
|
|
#if VLC_GCC_VERSION(4,3)
|
2011-07-12 17:02:54 +02:00
|
|
|
/* Linux has 100, 250, 300 or 1000Hz
|
|
|
|
*
|
|
|
|
* HZ=100 by default on FreeBSD, but some architectures use a 1000Hz timer
|
|
|
|
*/
|
|
|
|
|
|
|
|
static
|
|
|
|
__attribute__((unused))
|
|
|
|
__attribute__((noinline))
|
|
|
|
__attribute__((error("sorry, cannot sleep for such short a time")))
|
|
|
|
mtime_t impossible_delay( mtime_t delay )
|
|
|
|
{
|
|
|
|
(void) delay;
|
|
|
|
return VLC_HARD_MIN_SLEEP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
__attribute__((unused))
|
|
|
|
__attribute__((noinline))
|
|
|
|
__attribute__((warning("use proper event handling instead of short delay")))
|
|
|
|
mtime_t harmful_delay( mtime_t delay )
|
|
|
|
{
|
|
|
|
return delay;
|
|
|
|
}
|
|
|
|
|
|
|
|
# define check_delay( d ) \
|
|
|
|
((__builtin_constant_p(d < VLC_HARD_MIN_SLEEP) \
|
|
|
|
&& (d < VLC_HARD_MIN_SLEEP)) \
|
|
|
|
? impossible_delay(d) \
|
|
|
|
: ((__builtin_constant_p(d < VLC_SOFT_MIN_SLEEP) \
|
|
|
|
&& (d < VLC_SOFT_MIN_SLEEP)) \
|
|
|
|
? harmful_delay(d) \
|
|
|
|
: d))
|
|
|
|
|
|
|
|
static
|
|
|
|
__attribute__((unused))
|
|
|
|
__attribute__((noinline))
|
|
|
|
__attribute__((error("deadlines can not be constant")))
|
|
|
|
mtime_t impossible_deadline( mtime_t deadline )
|
|
|
|
{
|
|
|
|
return deadline;
|
|
|
|
}
|
|
|
|
|
|
|
|
# define check_deadline( d ) \
|
|
|
|
(__builtin_constant_p(d) ? impossible_deadline(d) : d)
|
|
|
|
#else
|
|
|
|
# define check_delay(d) (d)
|
|
|
|
# define check_deadline(d) (d)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define msleep(d) msleep(check_delay(d))
|
|
|
|
#define mwait(d) mwait(check_deadline(d))
|
|
|
|
|
2015-07-01 20:35:09 +02:00
|
|
|
/**
|
|
|
|
* Initializes an asynchronous timer.
|
|
|
|
*
|
|
|
|
* \param id pointer to timer to be initialized
|
|
|
|
* \param func function that the timer will call
|
|
|
|
* \param data parameter for the timer function
|
|
|
|
* \return 0 on success, a system error code otherwise.
|
|
|
|
*
|
|
|
|
* \warning Asynchronous timers are processed from an unspecified thread.
|
2016-04-02 16:50:31 +02:00
|
|
|
* \note Multiple occurrences of a single interval timer are serialized:
|
2015-07-01 20:35:09 +02:00
|
|
|
* they cannot run concurrently.
|
|
|
|
*/
|
|
|
|
VLC_API int vlc_timer_create(vlc_timer_t *id, void (*func)(void *), void *data)
|
|
|
|
VLC_USED;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys an initialized timer.
|
|
|
|
*
|
|
|
|
* If needed, the timer is first disarmed. Behaviour is undefined if the
|
|
|
|
* specified timer is not initialized.
|
|
|
|
*
|
|
|
|
* \warning This function <b>must</b> be called before the timer data can be
|
|
|
|
* freed and before the timer callback function can be unmapped/unloaded.
|
|
|
|
*
|
|
|
|
* \param timer timer to destroy
|
|
|
|
*/
|
|
|
|
VLC_API void vlc_timer_destroy(vlc_timer_t timer);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Arms or disarms an initialized timer.
|
|
|
|
*
|
|
|
|
* This functions overrides any previous call to itself.
|
|
|
|
*
|
|
|
|
* \note A timer can fire later than requested due to system scheduling
|
|
|
|
* limitations. An interval timer can fail to trigger sometimes, either because
|
|
|
|
* the system is busy or suspended, or because a previous iteration of the
|
|
|
|
* timer is still running. See also vlc_timer_getoverrun().
|
|
|
|
*
|
|
|
|
* \param timer initialized timer
|
|
|
|
* \param absolute the timer value origin is the same as mdate() if true,
|
|
|
|
* the timer value is relative to now if false.
|
|
|
|
* \param value zero to disarm the timer, otherwise the initial time to wait
|
|
|
|
* before firing the timer.
|
|
|
|
* \param interval zero to fire the timer just once, otherwise the timer
|
|
|
|
* repetition interval.
|
|
|
|
*/
|
|
|
|
VLC_API void vlc_timer_schedule(vlc_timer_t timer, bool absolute,
|
|
|
|
mtime_t value, mtime_t interval);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches and resets the overrun counter for a timer.
|
|
|
|
*
|
|
|
|
* This functions returns the number of times that the interval timer should
|
|
|
|
* have fired, but the callback was not invoked due to scheduling problems.
|
|
|
|
* The call resets the counter to zero.
|
|
|
|
*
|
|
|
|
* \param timer initialized timer
|
|
|
|
* \return the timer overrun counter (typically zero)
|
|
|
|
*/
|
2011-05-07 22:02:08 +02:00
|
|
|
VLC_API unsigned vlc_timer_getoverrun(vlc_timer_t) VLC_USED;
|
2009-06-02 19:19:19 +02:00
|
|
|
|
2015-07-01 20:35:09 +02:00
|
|
|
/**
|
|
|
|
* Count CPUs.
|
|
|
|
*
|
|
|
|
* \return number of available (logical) CPUs.
|
|
|
|
*/
|
2011-06-29 20:00:34 +02:00
|
|
|
VLC_API unsigned vlc_GetCPUCount(void);
|
|
|
|
|
2012-10-13 10:55:51 +02:00
|
|
|
#if defined (LIBVLC_USE_PTHREAD_CLEANUP)
|
2008-08-10 20:06:11 +02:00
|
|
|
/**
|
2015-07-01 20:35:09 +02:00
|
|
|
* Registers a thread cancellation handler.
|
|
|
|
*
|
|
|
|
* This pushes a function to run if the thread is cancelled (or otherwise
|
|
|
|
* exits prematurely).
|
|
|
|
*
|
|
|
|
* If multiple procedures are registered,
|
2008-08-10 20:06:11 +02:00
|
|
|
* they are handled in last-in first-out order.
|
|
|
|
*
|
2015-07-01 20:35:09 +02:00
|
|
|
* \note Any call to vlc_cleanup_push() <b>must</b> paired with a call to
|
2015-07-08 20:13:20 +02:00
|
|
|
* vlc_cleanup_pop().
|
2015-07-01 20:35:09 +02:00
|
|
|
* \warning Branching into or out of the block between these two function calls
|
|
|
|
* is not allowed (read: it will likely crash the whole process).
|
|
|
|
*
|
|
|
|
* \param routine procedure to call if the thread ends
|
|
|
|
* \param arg argument for the procedure
|
2008-08-10 20:06:11 +02:00
|
|
|
*/
|
|
|
|
# define vlc_cleanup_push( routine, arg ) pthread_cleanup_push (routine, arg)
|
|
|
|
|
|
|
|
/**
|
2015-07-01 20:35:09 +02:00
|
|
|
* Unregisters the last cancellation handler.
|
|
|
|
*
|
|
|
|
* This pops the cancellation handler that was last pushed with
|
|
|
|
* vlc_cleanup_push() in the calling thread.
|
2008-08-10 20:06:11 +02:00
|
|
|
*/
|
|
|
|
# define vlc_cleanup_pop( ) pthread_cleanup_pop (0)
|
|
|
|
|
|
|
|
#else
|
2012-10-13 10:55:51 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
VLC_CLEANUP_PUSH,
|
|
|
|
VLC_CLEANUP_POP,
|
|
|
|
};
|
2008-08-10 20:06:11 +02:00
|
|
|
typedef struct vlc_cleanup_t vlc_cleanup_t;
|
|
|
|
|
|
|
|
struct vlc_cleanup_t
|
|
|
|
{
|
|
|
|
vlc_cleanup_t *next;
|
|
|
|
void (*proc) (void *);
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This macros opens a code block on purpose. This is needed for multiple
|
2009-07-08 18:56:28 +02:00
|
|
|
* calls within a single function. This also prevent Win32 developers from
|
2008-08-10 20:06:11 +02:00
|
|
|
* writing code that would break on POSIX (POSIX opens a block as well). */
|
|
|
|
# define vlc_cleanup_push( routine, arg ) \
|
|
|
|
do { \
|
|
|
|
vlc_cleanup_t vlc_cleanup_data = { NULL, routine, arg, }; \
|
|
|
|
vlc_control_cancel (VLC_CLEANUP_PUSH, &vlc_cleanup_data)
|
|
|
|
|
|
|
|
# define vlc_cleanup_pop( ) \
|
|
|
|
vlc_control_cancel (VLC_CLEANUP_POP); \
|
|
|
|
} while (0)
|
|
|
|
|
2013-08-18 20:56:49 +02:00
|
|
|
#endif /* !LIBVLC_USE_PTHREAD_CLEANUP */
|
2012-10-13 10:55:51 +02:00
|
|
|
|
2008-08-10 20:43:05 +02:00
|
|
|
static inline void vlc_cleanup_lock (void *lock)
|
|
|
|
{
|
|
|
|
vlc_mutex_unlock ((vlc_mutex_t *)lock);
|
|
|
|
}
|
|
|
|
#define mutex_cleanup_push( lock ) vlc_cleanup_push (vlc_cleanup_lock, lock)
|
|
|
|
|
2008-10-20 21:45:16 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
/**
|
|
|
|
* Helper C++ class to lock a mutex.
|
2015-07-01 20:35:09 +02:00
|
|
|
*
|
2008-10-20 21:45:16 +02:00
|
|
|
* The mutex is locked when the object is created, and unlocked when the object
|
|
|
|
* is destroyed.
|
|
|
|
*/
|
|
|
|
class vlc_mutex_locker
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
vlc_mutex_t *lock;
|
|
|
|
public:
|
|
|
|
vlc_mutex_locker (vlc_mutex_t *m) : lock (m)
|
|
|
|
{
|
|
|
|
vlc_mutex_lock (lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
~vlc_mutex_locker (void)
|
|
|
|
{
|
|
|
|
vlc_mutex_unlock (lock);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2012-10-13 10:55:51 +02:00
|
|
|
enum
|
|
|
|
{
|
2010-06-03 22:25:31 +02:00
|
|
|
VLC_AVCODEC_MUTEX = 0,
|
|
|
|
VLC_GCRYPT_MUTEX,
|
2010-06-03 22:55:27 +02:00
|
|
|
VLC_XLIB_MUTEX,
|
2011-07-21 16:23:07 +02:00
|
|
|
VLC_MOSAIC_MUTEX,
|
2011-07-21 16:31:41 +02:00
|
|
|
VLC_HIGHLIGHT_MUTEX,
|
2010-06-03 22:55:27 +02:00
|
|
|
/* Insert new entry HERE */
|
2010-06-03 22:25:31 +02:00
|
|
|
VLC_MAX_MUTEX
|
|
|
|
};
|
|
|
|
|
2015-07-01 20:35:09 +02:00
|
|
|
/**
|
|
|
|
* Internal handler for global mutexes.
|
|
|
|
*
|
|
|
|
* Do not use this function directly. Use helper macros instead:
|
|
|
|
* vlc_global_lock(), vlc_global_unlock().
|
|
|
|
*/
|
|
|
|
VLC_API void vlc_global_mutex(unsigned, bool);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Acquires a global mutex.
|
|
|
|
*/
|
|
|
|
#define vlc_global_lock( n ) vlc_global_mutex(n, true)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Releases a global mutex.
|
|
|
|
*/
|
|
|
|
#define vlc_global_unlock( n ) vlc_global_mutex(n, false)
|
2010-06-03 22:25:31 +02:00
|
|
|
|
2015-11-09 17:35:14 +01:00
|
|
|
/** @} */
|
|
|
|
|
2008-01-22 17:25:57 +01:00
|
|
|
#endif /* !_VLC_THREADS_H */
|