1 // The MIT License (MIT) 2 // 3 // Copyright (c) 2015 Sergey Makeev, Vadim Slyusarev 4 // 5 // Permission is hereby granted, free of charge, to any person obtaining a copy 6 // of this software and associated documentation files (the "Software"), to deal 7 // in the Software without restriction, including without limitation the rights 8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 // copies of the Software, and to permit persons to whom the Software is 10 // furnished to do so, subject to the following conditions: 11 // 12 // The above copyright notice and this permission notice shall be included in 13 // all copies or substantial portions of the Software. 14 // 15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 // THE SOFTWARE. 22 23 #pragma once 24 25 #include <MTTypes.h> 26 #include <MTDebug.h> 27 28 typedef void (*TThreadEntryPoint)(void* userData); 29 30 #define ARRAY_SIZE( arr ) ( sizeof( arr ) / sizeof( (arr)[0] ) ) 31 32 namespace MT 33 { 34 namespace EventReset 35 { 36 enum Type 37 { 38 AUTOMATIC = 0, 39 MANUAL = 1, 40 }; 41 } 42 } 43 44 45 46 #ifdef _WIN32 47 #include <Platform/Windows/MTCommon.h> 48 #else 49 #include <Platform/Posix/MTCommon.h> 50 #endif 51 52 53 namespace MT 54 { 55 56 // 57 // 58 // 59 class ScopedGuard 60 { 61 MT::Mutex & mutex; 62 63 ScopedGuard( const ScopedGuard & ) : mutex(*((MT::Mutex*)nullptr)) {} 64 void operator=( const ScopedGuard &) {} 65 66 public: 67 68 ScopedGuard(MT::Mutex & _mutex) : mutex(_mutex) 69 { 70 mutex.Lock(); 71 } 72 73 ~ScopedGuard() 74 { 75 mutex.Unlock(); 76 } 77 }; 78 79 // 80 // Simple Linear congruential generator 81 // 82 class LcgRandom 83 { 84 uint32 state; 85 86 public: 87 88 LcgRandom() 89 : state(2578432553) 90 { 91 } 92 93 void SetSeed(uint32 seed) 94 { 95 state = seed; 96 } 97 98 uint16 Get() 99 { 100 state = 214013 * state + 2531011; 101 uint16 rnd = (state >> 16); 102 return rnd; 103 } 104 105 106 }; 107 108 } 109 110