Buckets:
| /* | |
| Simple DirectMedia Layer | |
| Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org> | |
| This software is provided 'as-is', without any express or implied | |
| warranty. In no event will the authors be held liable for any damages | |
| arising from the use of this software. | |
| Permission is granted to anyone to use this software for any purpose, | |
| including commercial applications, and to alter it and redistribute it | |
| freely, subject to the following restrictions: | |
| 1. The origin of this software must not be misrepresented; you must not | |
| claim that you wrote the original software. If you use this software | |
| in a product, an acknowledgment in the product documentation would be | |
| appreciated but is not required. | |
| 2. Altered source versions must be plainly marked as such, and must not be | |
| misrepresented as being the original software. | |
| 3. This notice may not be removed or altered from any source distribution. | |
| */ | |
| /** | |
| * \file SDL_atomic.h | |
| * | |
| * Atomic operations. | |
| * | |
| * IMPORTANT: | |
| * If you are not an expert in concurrent lockless programming, you should | |
| * only be using the atomic lock and reference counting functions in this | |
| * file. In all other cases you should be protecting your data structures | |
| * with full mutexes. | |
| * | |
| * The list of "safe" functions to use are: | |
| * SDL_AtomicLock() | |
| * SDL_AtomicUnlock() | |
| * SDL_AtomicIncRef() | |
| * SDL_AtomicDecRef() | |
| * | |
| * Seriously, here be dragons! | |
| * ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| * | |
| * You can find out a little more about lockless programming and the | |
| * subtle issues that can arise here: | |
| * http://msdn.microsoft.com/en-us/library/ee418650%28v=vs.85%29.aspx | |
| * | |
| * There's also lots of good information here: | |
| * http://www.1024cores.net/home/lock-free-algorithms | |
| * | |
| * These operations may or may not actually be implemented using | |
| * processor specific atomic operations. When possible they are | |
| * implemented as true processor specific atomic operations. When that | |
| * is not possible the are implemented using locks that *do* use the | |
| * available atomic operations. | |
| * | |
| * All of the atomic operations that modify memory are full memory barriers. | |
| */ | |
| /* Need to do this here because intrin.h has C++ code in it */ | |
| /* Visual Studio 2005 has a bug where intrin.h conflicts with winnt.h */ | |
| /* Set up for C function definitions, even when using C++ */ | |
| /* *INDENT-OFF* */ | |
| extern "C" { | |
| /* *INDENT-ON* */ | |
| /** | |
| * \name SDL AtomicLock | |
| * | |
| * The atomic locks are efficient spinlocks using CPU instructions, | |
| * but are vulnerable to starvation and can spin forever if a thread | |
| * holding a lock has been terminated. For this reason you should | |
| * minimize the code executed inside an atomic lock and never do | |
| * expensive things like API or system calls while holding them. | |
| * | |
| * The atomic locks are not safe to lock recursively. | |
| * | |
| * Porting Note: | |
| * The spin lock functions and type are required and can not be | |
| * emulated because they are used in the atomic emulation code. | |
| */ | |
| /*@{*/ | |
| typedef int SDL_SpinLock; | |
| /** | |
| * \brief Try to lock a spin lock by setting it to a non-zero value. | |
| * | |
| * \param lock Points to the lock. | |
| * | |
| * \return SDL_TRUE if the lock succeeded, SDL_FALSE if the lock is already held. | |
| */ | |
| extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTryLock(SDL_SpinLock *lock); | |
| /** | |
| * \brief Lock a spin lock by setting it to a non-zero value. | |
| * | |
| * \param lock Points to the lock. | |
| */ | |
| extern DECLSPEC void SDLCALL SDL_AtomicLock(SDL_SpinLock *lock); | |
| /** | |
| * \brief Unlock a spin lock by setting it to 0. Always returns immediately | |
| * | |
| * \param lock Points to the lock. | |
| */ | |
| extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock); | |
| /*@}*//*SDL AtomicLock*/ | |
| /** | |
| * The compiler barrier prevents the compiler from reordering | |
| * reads and writes to globally visible variables across the call. | |
| */ | |
| void _ReadWriteBarrier(void); | |
| /* Platform specific optimized versions of the atomic functions, | |
| * you can disable these by defining SDL_DISABLE_ATOMIC_INLINE | |
| */ | |
| /** | |
| * \brief A type representing an atomic integer value. It is a struct | |
| * so people don't accidentally use numeric operations on it. | |
| */ | |
| typedef struct { int value; } SDL_atomic_t; | |
| /** | |
| * \brief Set an atomic variable to a new value if it is currently an old value. | |
| * | |
| * \return SDL_TRUE if the atomic variable was set, SDL_FALSE otherwise. | |
| * | |
| * \note If you don't know what this function is for, you shouldn't use it! | |
| */ | |
| extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int newval); | |
| /** | |
| * \brief Set an atomic variable to a value. | |
| * | |
| * \return The previous value of the atomic variable. | |
| */ | |
| static __inline__ int SDL_AtomicSet(SDL_atomic_t *a, int v) | |
| { | |
| int value; | |
| do { | |
| value = a->value; | |
| } while (!SDL_AtomicCAS(a, value, v)); | |
| return value; | |
| } | |
| /** | |
| * \brief Get the value of an atomic variable | |
| */ | |
| static __inline__ int SDL_AtomicGet(SDL_atomic_t *a) | |
| { | |
| int value = a->value; | |
| SDL_CompilerBarrier(); | |
| return value; | |
| } | |
| /** | |
| * \brief Add to an atomic variable. | |
| * | |
| * \return The previous value of the atomic variable. | |
| * | |
| * \note This same style can be used for any number operation | |
| */ | |
| static __inline__ int SDL_AtomicAdd(SDL_atomic_t *a, int v) | |
| { | |
| int value; | |
| do { | |
| value = a->value; | |
| } while (!SDL_AtomicCAS(a, value, (value + v))); | |
| return value; | |
| } | |
| /** | |
| * \brief Increment an atomic variable used as a reference count. | |
| */ | |
| /** | |
| * \brief Decrement an atomic variable used as a reference count. | |
| * | |
| * \return SDL_TRUE if the variable reached zero after decrementing, | |
| * SDL_FALSE otherwise | |
| */ | |
| /** | |
| * \brief Set a pointer to a new value if it is currently an old value. | |
| * | |
| * \return SDL_TRUE if the pointer was set, SDL_FALSE otherwise. | |
| * | |
| * \note If you don't know what this function is for, you shouldn't use it! | |
| */ | |
| extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr_(void* *a, void *oldval, void *newval); | |
| /** | |
| * \brief Set a pointer to a value atomically. | |
| * | |
| * \return The previous value of the pointer. | |
| */ | |
| static __inline__ void* SDL_AtomicSetPtr(void* *a, void* v) | |
| { | |
| void* value; | |
| do { | |
| value = *a; | |
| } while (!SDL_AtomicCASPtr(a, value, v)); | |
| return value; | |
| } | |
| /** | |
| * \brief Get the value of a pointer atomically. | |
| */ | |
| static __inline__ void* SDL_AtomicGetPtr(void* *a) | |
| { | |
| void* value = *a; | |
| SDL_CompilerBarrier(); | |
| return value; | |
| } | |
| /* Ends C function definitions when using C++ */ | |
| /* *INDENT-OFF* */ | |
| } | |
| /* *INDENT-ON* */ | |
| /* vi: set ts=4 sw=4 expandtab: */ | |
Xet Storage Details
- Size:
- 9.39 kB
- Xet hash:
- 7d462a780fa159e48eb8be35a69d6afad2b37ae18b43c1ec4355b57f937a79a0
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.