2010-06-28 07:13:33 +08:00
|
|
|
/*****************************************************************************
|
|
|
|
* vlc_atomic.h:
|
|
|
|
*****************************************************************************
|
|
|
|
* Copyright (C) 2010 Rémi Denis-Courmont
|
|
|
|
*
|
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-28 04:44:15 +08: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
|
2010-06-28 07:13:33 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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-28 04:44:15 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
2010-06-28 07:13:33 +08: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-28 04:44:15 +08: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.
|
2010-06-28 07:13:33 +08:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef VLC_ATOMIC_H
|
|
|
|
# define VLC_ATOMIC_H
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Atomic operations do not require locking, but they are not very powerful.
|
|
|
|
*/
|
|
|
|
|
2018-07-05 16:30:48 +08:00
|
|
|
# include <assert.h>
|
2020-11-26 19:25:54 +08:00
|
|
|
#ifndef __cplusplus
|
2017-12-20 01:32:52 +08:00
|
|
|
# include <stdatomic.h>
|
2020-11-26 19:25:54 +08:00
|
|
|
#else
|
|
|
|
# include <atomic>
|
|
|
|
using std::atomic_uintptr_t;
|
|
|
|
using std::memory_order_relaxed;
|
|
|
|
using std::memory_order_acq_rel;
|
|
|
|
#endif
|
2018-07-05 16:30:48 +08:00
|
|
|
# include <vlc_common.h>
|
2023-04-19 18:10:43 +08:00
|
|
|
# include <vlc_tick.h>
|
2012-05-12 01:24:04 +08:00
|
|
|
|
2023-09-01 17:39:39 +08:00
|
|
|
#include <time.h> /* vlc_atomic_timedwait_daytime */
|
|
|
|
|
2022-03-03 02:46:33 +08:00
|
|
|
#define VLC_STATIC_RC { \
|
2024-04-24 20:10:54 +08:00
|
|
|
.refs = (uintptr_t) 1 \
|
2022-03-03 02:46:33 +08:00
|
|
|
}
|
|
|
|
|
2018-07-05 16:30:48 +08:00
|
|
|
typedef struct vlc_atomic_rc_t {
|
2020-02-24 16:33:35 +08:00
|
|
|
atomic_uintptr_t refs;
|
2018-07-05 16:30:48 +08:00
|
|
|
} vlc_atomic_rc_t;
|
|
|
|
|
|
|
|
/** Init the RC to 1 */
|
|
|
|
static inline void vlc_atomic_rc_init(vlc_atomic_rc_t *rc)
|
|
|
|
{
|
2020-11-26 19:25:54 +08:00
|
|
|
atomic_init(&rc->refs, (uintptr_t)1);
|
2018-07-05 16:30:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Increment the RC */
|
|
|
|
static inline void vlc_atomic_rc_inc(vlc_atomic_rc_t *rc)
|
|
|
|
{
|
2020-11-26 19:25:54 +08:00
|
|
|
uintptr_t prev = atomic_fetch_add_explicit(&rc->refs, (uintptr_t)1,
|
|
|
|
memory_order_relaxed);
|
2018-07-05 16:30:48 +08:00
|
|
|
vlc_assert(prev);
|
|
|
|
VLC_UNUSED(prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Decrement the RC and return true if it reaches 0 */
|
|
|
|
static inline bool vlc_atomic_rc_dec(vlc_atomic_rc_t *rc)
|
|
|
|
{
|
2020-11-26 19:25:54 +08:00
|
|
|
uintptr_t prev = atomic_fetch_sub_explicit(&rc->refs, (uintptr_t)1,
|
|
|
|
memory_order_acq_rel);
|
2018-07-05 16:30:48 +08:00
|
|
|
vlc_assert(prev);
|
|
|
|
return prev == 1;
|
|
|
|
}
|
|
|
|
|
2020-12-16 21:29:06 +08:00
|
|
|
/** Returns the current reference count.
|
|
|
|
* This is not safe to use for logic and must only be used for debugging or
|
|
|
|
* assertion purposes */
|
|
|
|
static inline uintptr_t vlc_atomic_rc_get(const vlc_atomic_rc_t* rc)
|
|
|
|
{
|
|
|
|
return atomic_load_explicit(&rc->refs, memory_order_relaxed);
|
|
|
|
}
|
|
|
|
|
2021-10-05 23:54:31 +08:00
|
|
|
/**
|
|
|
|
* Waits on an address.
|
|
|
|
*
|
|
|
|
* Puts the calling thread to sleep if a specific unsigned 32-bits value is
|
|
|
|
* stored at a specified address. The thread will sleep until it is woken up by
|
|
|
|
* a call to vlc_atomic_notify_one() or vlc_atomic_notify_all() in another
|
|
|
|
* thread, or spuriously.
|
|
|
|
*
|
|
|
|
* If the value does not match, do nothing and return immediately.
|
|
|
|
*
|
|
|
|
* \param addr address to check for
|
|
|
|
* \param val value to match at the address
|
|
|
|
*/
|
2021-10-06 00:03:09 +08:00
|
|
|
VLC_API void vlc_atomic_wait(void *addr, unsigned val);
|
2021-10-05 23:54:31 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Waits on an address with a time-out.
|
|
|
|
*
|
|
|
|
* This function operates as vlc_atomic_wait() but provides an additional
|
|
|
|
* time-out. If the deadline is reached, the thread resumes and the function
|
|
|
|
* returns.
|
|
|
|
*
|
|
|
|
* \param addr address to check for
|
|
|
|
* \param val value to match at the address
|
|
|
|
* \param deadline deadline to wait until
|
|
|
|
*
|
|
|
|
* \retval 0 the function was woken up before the time-out
|
|
|
|
* \retval ETIMEDOUT the deadline was reached
|
|
|
|
*/
|
2021-10-06 00:03:09 +08:00
|
|
|
VLC_API
|
2021-10-05 23:54:31 +08:00
|
|
|
int vlc_atomic_timedwait(void *addr, unsigned val, vlc_tick_t deadline);
|
|
|
|
|
|
|
|
int vlc_atomic_timedwait_daytime(void *addr, unsigned val, time_t deadline);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wakes up one thread on an address.
|
|
|
|
*
|
|
|
|
* Wakes up (at least) one of the thread sleeping on the specified address.
|
|
|
|
* The address must be equal to the first parameter given by at least one
|
|
|
|
* thread sleeping within the vlc_atomic_wait() or vlc_atomic_timedwait()
|
|
|
|
* functions. If no threads are found, this function does nothing.
|
|
|
|
*
|
|
|
|
* \param addr address identifying which threads may be woken up
|
|
|
|
*/
|
2021-10-06 00:03:09 +08:00
|
|
|
VLC_API void vlc_atomic_notify_one(void *addr);
|
2021-10-05 23:54:31 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wakes up all thread on an address.
|
|
|
|
*
|
|
|
|
* Wakes up all threads sleeping on the specified address (if any).
|
|
|
|
* Any thread sleeping within a call to vlc_atomic_wait() or
|
|
|
|
* vlc_atomic_timedwait() with the specified address as first call parameter
|
|
|
|
* will be woken up.
|
|
|
|
*
|
|
|
|
* \param addr address identifying which threads to wake up
|
|
|
|
*/
|
2021-10-06 00:03:09 +08:00
|
|
|
VLC_API void vlc_atomic_notify_all(void *addr);
|
2021-10-05 23:54:31 +08:00
|
|
|
|
2010-06-28 07:13:33 +08:00
|
|
|
#endif
|