Spinning Topp Logo BlackTopp Studios
inc
atomicoperations.h
Go to the documentation of this file.
1 // The DAGFrameScheduler is a Multi-Threaded lock free and wait free scheduling library.
2 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
3 /* This file is part of The DAGFrameScheduler.
4 
5  The DAGFrameScheduler is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  The DAGFrameScheduler is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with The DAGFrameScheduler. If not, see <http://www.gnu.org/licenses/>.
17 */
18 /* The original authors have included a copy of the license specified above in the
19  'doc' folder. See 'gpl.txt'
20 */
21 /* We welcome the use of the DAGFrameScheduler to anyone, including companies who wish to
22  Build professional software and charge for their product.
23 
24  However there are some practical restrictions, so if your project involves
25  any of the following you should contact us and we will try to work something
26  out:
27  - DRM or Copy Protection of any kind(except Copyrights)
28  - Software Patents You Do Not Wish to Freely License
29  - Any Kind of Linking to Non-GPL licensed Works
30  - Are Currently In Violation of Another Copyright Holder's GPL License
31  - If You want to change our code and not add a few hundred MB of stuff to
32  your distribution
33 
34  These and other limitations could cause serious legal problems if you ignore
35  them, so it is best to simply contact us or the Free Software Foundation, if
36  you have any questions.
37 
38  Joseph Toppi - toppij@gmail.com
39  John Blackwood - makoenergy02@gmail.com
40 */
41 #ifndef _atomic_black_ops_would_be_an_awesome_name_for_a_cheezy_game_h
42 #define _atomic_black_ops_would_be_an_awesome_name_for_a_cheezy_game_h
43 
44 #include "datatypes.h"
45 
46 /// @file
47 /// @brief Simple thread safe ways to check and change a specified variable atomically.
48 
49 namespace Mezzanine
50 {
51  namespace Threading
52  {
53 #if !(defined(SWIG) && defined(MEZZLUA51)) // Stop Swig from making lua bindings but allow other languages
54  /// @brief Atomically Compares And Swaps a 32 bit value.
55  /// @details In such a way that this cannot be interupted by another thread this performs a number of steps.
56  /// First, it compares the dereferenced value VariableToChange to OldValue. Then if they match it writes NewValue
57  /// to the memory location VariableToChange points to. If they did not match, no work is performed except the dereferencing.
58  /// In either case since VariableToChange has been derefenced the value stored before any exchange that might have
59  /// occured is returned.
60  /// @param VariableToChange A pointer to the value to compare and if it matches OldValue Atomically change.
61  /// @param OldValue what is expected to be at the other end of VariableToChange.
62  /// @param NewValue The value to be written to VariableToChange if at the time the actual CPU instruction is executed OldValue Matches *VariableToChange.
63  /// @note This very specific semantics of this function are useless in most scripting so it is not included in Lua and other scripting languages.
64  /// @return This always returns the value that was pointed to by VariableToChange immediately before this call.
65  Int32 MEZZ_LIB AtomicCompareAndSwap32(Int32* VariableToChange, const Int32& OldValue, const Int32& NewValue);
66 /*
67  // @brief Atomically Compares And Swaps a 64 bit value.
68  // @details In such a way that this cannot be interupted by another thread this performs a number of steps.
69  // First, it compares the dereferenced value VariableToChange to OldValue. Then if they match it writes NewValue
70  // to the memory location VariableToChange points to. If they did not match, no work is performed except the dereferencing.
71  // In either case since VariableToChange has been derefenced the value stored before any exchange that might have
72  // occured is returned.
73  // @param VariableToChange A pointer to the value to compare and if it matches OldValue Atomically change.
74  // @param OldValue what is expected to be at the other end of VariableToChange.
75  // @param NewValue The value to be written to VariableToChange if at the time the actual CPU instruction is executed OldValue Matches *VariableToChange.
76  // @return This always returns the value that was pointed to by VariableToChange immediately before this call.
77  Int64 MEZZ_LIB AtomicCompareAndSwap64(Int64* VariableToChange, const Int64& OldValue, const Int64& NewValue);
78 */
79  /// @brief Increments a value in a way guaranteed to not lose any atomic increments.
80  /// @param VariableToChange A pointer to the 32 bit integer to increment by the amount specified.
81  /// @param Value The amount to increment the VariableToChange by.
82  /// @note This very specific semantics of this function are useless in most scripting so it is not included in Lua and other scripting languages.
83  /// @return The value just before being incremented. This is not always *VariableToChange. If another thread attempted an atomic operation on this at the same time the result could be an unexpected value.
84  Int32 MEZZ_LIB AtomicAdd(Int32* VariableToChange, Int32 Value);
85 #endif
86  }//Threading
87 }//Mezzanine
88 
89 #endif
int32_t Int32
An 32-bit integer.
Definition: datatypes.h:124
All the definitions for datatypes as well as some basic conversion functions are defined here...
Int32 AtomicAdd(Int32 *VariableToChange, Int32 Value)
Increments a value in a way guaranteed to not lose any atomic increments.
Int32 AtomicCompareAndSwap32(Int32 *VariableToChange, const Int32 &OldValue, const Int32 &NewValue)
Atomically Compares And Swaps a 32 bit value.
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56