Containers (STL-compatible) StateMachines MessageBus and more for Embedded Systems. See www.etlcpp.com
atomic/atomic_windows.h@0:b47c2a7920c2, 2018-03-16 (annotated)
- Committer:
- bobbery
- Date:
- Fri Mar 16 16:34:18 2018 +0000
- Revision:
- 0:b47c2a7920c2
Works after using gcc_generic undef CAPACITY and replacing nullptr by std::nullptr
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bobbery | 0:b47c2a7920c2 | 1 | /****************************************************************************** |
bobbery | 0:b47c2a7920c2 | 2 | The MIT License(MIT) |
bobbery | 0:b47c2a7920c2 | 3 | |
bobbery | 0:b47c2a7920c2 | 4 | Embedded Template Library. |
bobbery | 0:b47c2a7920c2 | 5 | https://github.com/ETLCPP/etl |
bobbery | 0:b47c2a7920c2 | 6 | https://www.etlcpp.com |
bobbery | 0:b47c2a7920c2 | 7 | |
bobbery | 0:b47c2a7920c2 | 8 | Copyright(c) 2017 jwellbelove |
bobbery | 0:b47c2a7920c2 | 9 | |
bobbery | 0:b47c2a7920c2 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy |
bobbery | 0:b47c2a7920c2 | 11 | of this software and associated documentation files(the "Software"), to deal |
bobbery | 0:b47c2a7920c2 | 12 | in the Software without restriction, including without limitation the rights |
bobbery | 0:b47c2a7920c2 | 13 | to use, copy, modify, merge, publish, distribute, sublicense, and / or sell |
bobbery | 0:b47c2a7920c2 | 14 | copies of the Software, and to permit persons to whom the Software is |
bobbery | 0:b47c2a7920c2 | 15 | furnished to do so, subject to the following conditions : |
bobbery | 0:b47c2a7920c2 | 16 | |
bobbery | 0:b47c2a7920c2 | 17 | The above copyright notice and this permission notice shall be included in all |
bobbery | 0:b47c2a7920c2 | 18 | copies or substantial portions of the Software. |
bobbery | 0:b47c2a7920c2 | 19 | |
bobbery | 0:b47c2a7920c2 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
bobbery | 0:b47c2a7920c2 | 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
bobbery | 0:b47c2a7920c2 | 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE |
bobbery | 0:b47c2a7920c2 | 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
bobbery | 0:b47c2a7920c2 | 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
bobbery | 0:b47c2a7920c2 | 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
bobbery | 0:b47c2a7920c2 | 26 | SOFTWARE. |
bobbery | 0:b47c2a7920c2 | 27 | ******************************************************************************/ |
bobbery | 0:b47c2a7920c2 | 28 | |
bobbery | 0:b47c2a7920c2 | 29 | #ifndef __ETL_ATOMIC_WINDOWS__ |
bobbery | 0:b47c2a7920c2 | 30 | #define __ETL_ATOMIC_WINDOWS__ |
bobbery | 0:b47c2a7920c2 | 31 | |
bobbery | 0:b47c2a7920c2 | 32 | #include "../platform.h" |
bobbery | 0:b47c2a7920c2 | 33 | |
bobbery | 0:b47c2a7920c2 | 34 | #include <stdint.h> |
bobbery | 0:b47c2a7920c2 | 35 | #include <Windows.h> |
bobbery | 0:b47c2a7920c2 | 36 | |
bobbery | 0:b47c2a7920c2 | 37 | namespace etl |
bobbery | 0:b47c2a7920c2 | 38 | { |
bobbery | 0:b47c2a7920c2 | 39 | class atomic_uint32_t |
bobbery | 0:b47c2a7920c2 | 40 | { |
bobbery | 0:b47c2a7920c2 | 41 | public: |
bobbery | 0:b47c2a7920c2 | 42 | |
bobbery | 0:b47c2a7920c2 | 43 | atomic_uint32_t() |
bobbery | 0:b47c2a7920c2 | 44 | { |
bobbery | 0:b47c2a7920c2 | 45 | InterlockedExchange(&value, 0); |
bobbery | 0:b47c2a7920c2 | 46 | } |
bobbery | 0:b47c2a7920c2 | 47 | |
bobbery | 0:b47c2a7920c2 | 48 | atomic_uint32_t(uint32_t v) |
bobbery | 0:b47c2a7920c2 | 49 | { |
bobbery | 0:b47c2a7920c2 | 50 | InterlockedExchange(&value, v); |
bobbery | 0:b47c2a7920c2 | 51 | } |
bobbery | 0:b47c2a7920c2 | 52 | |
bobbery | 0:b47c2a7920c2 | 53 | atomic_uint32_t& operator =(uint32_t v) |
bobbery | 0:b47c2a7920c2 | 54 | { |
bobbery | 0:b47c2a7920c2 | 55 | InterlockedExchange(&value, v); |
bobbery | 0:b47c2a7920c2 | 56 | |
bobbery | 0:b47c2a7920c2 | 57 | return *this; |
bobbery | 0:b47c2a7920c2 | 58 | } |
bobbery | 0:b47c2a7920c2 | 59 | |
bobbery | 0:b47c2a7920c2 | 60 | atomic_uint32_t& operator ++() |
bobbery | 0:b47c2a7920c2 | 61 | { |
bobbery | 0:b47c2a7920c2 | 62 | InterlockedIncrement(&value); |
bobbery | 0:b47c2a7920c2 | 63 | |
bobbery | 0:b47c2a7920c2 | 64 | return *this; |
bobbery | 0:b47c2a7920c2 | 65 | } |
bobbery | 0:b47c2a7920c2 | 66 | |
bobbery | 0:b47c2a7920c2 | 67 | volatile atomic_uint32_t& operator ++() volatile |
bobbery | 0:b47c2a7920c2 | 68 | { |
bobbery | 0:b47c2a7920c2 | 69 | InterlockedIncrement(&value); |
bobbery | 0:b47c2a7920c2 | 70 | |
bobbery | 0:b47c2a7920c2 | 71 | return *this; |
bobbery | 0:b47c2a7920c2 | 72 | } |
bobbery | 0:b47c2a7920c2 | 73 | |
bobbery | 0:b47c2a7920c2 | 74 | atomic_uint32_t& operator --() |
bobbery | 0:b47c2a7920c2 | 75 | { |
bobbery | 0:b47c2a7920c2 | 76 | InterlockedDecrement(&value); |
bobbery | 0:b47c2a7920c2 | 77 | |
bobbery | 0:b47c2a7920c2 | 78 | return *this; |
bobbery | 0:b47c2a7920c2 | 79 | } |
bobbery | 0:b47c2a7920c2 | 80 | |
bobbery | 0:b47c2a7920c2 | 81 | volatile atomic_uint32_t& operator --() volatile |
bobbery | 0:b47c2a7920c2 | 82 | { |
bobbery | 0:b47c2a7920c2 | 83 | InterlockedDecrement(&value); |
bobbery | 0:b47c2a7920c2 | 84 | |
bobbery | 0:b47c2a7920c2 | 85 | return *this; |
bobbery | 0:b47c2a7920c2 | 86 | } |
bobbery | 0:b47c2a7920c2 | 87 | |
bobbery | 0:b47c2a7920c2 | 88 | operator uint32_t () const |
bobbery | 0:b47c2a7920c2 | 89 | { |
bobbery | 0:b47c2a7920c2 | 90 | return InterlockedAdd((volatile long*)&value, 0); |
bobbery | 0:b47c2a7920c2 | 91 | } |
bobbery | 0:b47c2a7920c2 | 92 | |
bobbery | 0:b47c2a7920c2 | 93 | operator uint32_t() volatile const |
bobbery | 0:b47c2a7920c2 | 94 | { |
bobbery | 0:b47c2a7920c2 | 95 | return InterlockedAdd((volatile long*)&value, 0); |
bobbery | 0:b47c2a7920c2 | 96 | } |
bobbery | 0:b47c2a7920c2 | 97 | |
bobbery | 0:b47c2a7920c2 | 98 | private: |
bobbery | 0:b47c2a7920c2 | 99 | |
bobbery | 0:b47c2a7920c2 | 100 | uint32_t value; |
bobbery | 0:b47c2a7920c2 | 101 | }; |
bobbery | 0:b47c2a7920c2 | 102 | } |
bobbery | 0:b47c2a7920c2 | 103 | |
bobbery | 0:b47c2a7920c2 | 104 | #endif |
bobbery | 0:b47c2a7920c2 | 105 |