| Previous | 199869 Revisions | Next |
| r40684 Saturday 12th September, 2015 at 08:22:55 UTC by Miodrag Milanović |
|---|
| Added latest BX (nw) |
| [3rdparty/bx/include/bx] | allocator.h |
| [3rdparty/bx/include/compat/freebsd] | signal.h* |
| [3rdparty/bx/include/compat/mingw] | sal.h |
| [3rdparty/bx/include/tinystl] | buffer.h vector.h |
| [3rdparty/bx/scripts] | genie.lua toolchain.lua unittest++.lua |
| [3rdparty/bx/tests] | handle.cpp* misc.cpp* uint32_t.cpp unordered_map_nonpod.cpp vector_complex.cpp vector_header.cpp vector_nocopy.cpp* vector_nodefault.cpp |
| [3rdparty/bx/tools/bin/darwin] | genie |
| [3rdparty/bx/tools/bin/linux] | genie |
| [3rdparty/bx/tools/bin/windows] | genie.exe |
| r249195 | r249196 | |
|---|---|---|
| 58 | 58 | return un.ptr; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | /// Check if pointer is aligned. _align must be power of two. | |
| 62 | inline bool isPtrAligned(const void* _ptr, size_t _align = BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT) | |
| 63 | { | |
| 64 | union { const void* ptr; size_t addr; } un; | |
| 65 | un.ptr = _ptr; | |
| 66 | return 0 == (un.addr & (_align-1) ); | |
| 67 | } | |
| 68 | ||
| 69 | 61 | struct BX_NO_VTABLE AllocatorI |
| 70 | 62 | { |
| 71 | 63 | virtual ~AllocatorI() = 0; |
| r249195 | r249196 | |
|---|---|---|
| 1 | /* | |
| 2 | * Copyright 2010-2015 Branimir Karadzic. All rights reserved. | |
| 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause | |
| 4 | */ | |
| 5 | ||
| 6 | #ifndef BX_BLOCKALLOC_H_HEADER_GUARD | |
| 7 | #define BX_BLOCKALLOC_H_HEADER_GUARD | |
| 8 | ||
| 9 | #include "bx.h" | |
| 10 | ||
| 11 | namespace bx | |
| 12 | { | |
| 13 | class BlockAlloc | |
| 14 | { | |
| 15 | public: | |
| 16 | static const uint16_t invalidIndex = 0xffff; | |
| 17 | static const uint32_t minElementSize = 2; | |
| 18 | ||
| 19 | BlockAlloc() | |
| 20 | : m_data(NULL) | |
| 21 | , m_num(0) | |
| 22 | , m_size(0) | |
| 23 | , m_numFree(0) | |
| 24 | , m_freeIndex(invalidIndex) | |
| 25 | { | |
| 26 | } | |
| 27 | ||
| 28 | BlockAlloc(void* _data, uint16_t _num, uint16_t _size) | |
| 29 | : m_data(_data) | |
| 30 | , m_num(_num) | |
| 31 | , m_size(_size) | |
| 32 | , m_numFree(_num) | |
| 33 | , m_freeIndex(0) | |
| 34 | { | |
| 35 | char* data = (char*)_data; | |
| 36 | uint16_t* index = (uint16_t*)_data; | |
| 37 | for (uint16_t ii = 0; ii < m_num-1; ++ii) | |
| 38 | { | |
| 39 | *index = ii+1; | |
| 40 | data += m_size; | |
| 41 | index = (uint16_t*)data; | |
| 42 | } | |
| 43 | *index = invalidIndex; | |
| 44 | } | |
| 45 | ||
| 46 | ~BlockAlloc() | |
| 47 | { | |
| 48 | } | |
| 49 | ||
| 50 | void* alloc() | |
| 51 | { | |
| 52 | if (invalidIndex == m_freeIndex) | |
| 53 | { | |
| 54 | return NULL; | |
| 55 | } | |
| 56 | ||
| 57 | void* obj = ( (char*)m_data) + m_freeIndex*m_size; | |
| 58 | m_freeIndex = *( (uint16_t*)obj); | |
| 59 | --m_numFree; | |
| 60 | ||
| 61 | return obj; | |
| 62 | } | |
| 63 | ||
| 64 | void free(void* _obj) | |
| 65 | { | |
| 66 | uint16_t index = getIndex(_obj); | |
| 67 | BX_CHECK(index < m_num, "index %d, m_num %d", index, m_num); | |
| 68 | ||
| 69 | *( (uint16_t*)_obj) = m_freeIndex; | |
| 70 | m_freeIndex = index; | |
| 71 | ++m_numFree; | |
| 72 | } | |
| 73 | ||
| 74 | uint16_t getIndex(void* _obj) const | |
| 75 | { | |
| 76 | return (uint16_t)( ( (char*)_obj - (char*)m_data ) / m_size); | |
| 77 | } | |
| 78 | ||
| 79 | uint16_t getNumFree() const | |
| 80 | { | |
| 81 | return m_numFree; | |
| 82 | } | |
| 83 | ||
| 84 | void* getFromIndex(uint16_t _index) | |
| 85 | { | |
| 86 | return (char*)m_data + _index*m_size; | |
| 87 | } | |
| 88 | ||
| 89 | private: | |
| 90 | void* m_data; | |
| 91 | uint16_t m_num; | |
| 92 | uint16_t m_size; | |
| 93 | uint16_t m_numFree; | |
| 94 | uint16_t m_freeIndex; | |
| 95 | }; | |
| 96 | ||
| 97 | } // namespace bx | |
| 98 | ||
| 99 | #endif // BX_BLOCKALLOC_H_HEADER_GUARD |
| r249195 | r249196 | |
|---|---|---|
| 44 | 44 | Ty tmp = _a; _a = _b; _b = tmp; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | /// Check if pointer is aligned. _align must be power of two. | |
| 48 | inline bool isPtrAligned(const void* _ptr, size_t _align) | |
| 49 | { | |
| 50 | union { const void* ptr; size_t addr; } un; | |
| 51 | un.ptr = _ptr; | |
| 52 | return 0 == (un.addr & (_align-1) ); | |
| 53 | } | |
| 54 | ||
| 47 | 55 | } // namespace bx |
| 48 | 56 | |
| 49 | 57 | // Annoying C++0x stuff.. |
| r249195 | r249196 | |
|---|---|---|
| 24 | 24 | # define BX_CONFIG_CRT_FILE_READER_WRITER (0 \ |
| 25 | 25 | || BX_PLATFORM_ANDROID \ |
| 26 | 26 | || BX_PLATFORM_FREEBSD \ |
| 27 | || BX_PLATFORM_EMSCRIPTEN \ | |
| 27 | 28 | || BX_PLATFORM_IOS \ |
| 28 | 29 | || BX_PLATFORM_LINUX \ |
| 29 | 30 | || BX_PLATFORM_OSX \ |
| r249195 | r249196 | |
|---|---|---|
| 31 | 31 | |
| 32 | 32 | inline float fround(float _f) |
| 33 | 33 | { |
| 34 | return flo | |
| 34 | return floorf(_f + 0.5f); | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | inline float fmin(float _a, float _b) |
| r249195 | r249196 | |
| 121 | 121 | return result; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | // References: | |
| 125 | // - Bias And Gain Are Your Friend | |
| 126 | // http://blog.demofox.org/2012/09/24/bias-and-gain-are-your-friend/ | |
| 127 | // - http://demofox.org/biasgain.html | |
| 128 | inline float fbias(float _time, float _bias) | |
| 129 | { | |
| 130 | return _time / ( ( (1.0f/_bias - 2.0f)*(1.0f - _time) ) + 1.0f); | |
| 131 | } | |
| 132 | ||
| 133 | inline float fgain(float _time, float _gain) | |
| 134 | { | |
| 135 | if (_time < 0.5f) | |
| 136 | { | |
| 137 | return fbias(_time * 2.0f, _gain) * 0.5f; | |
| 138 | } | |
| 139 | ||
| 140 | return fbias(_time * 2.0f - 1.0f, 1.0f - _gain) * 0.5f + 0.5f; | |
| 141 | } | |
| 142 | ||
| 124 | 143 | inline void vec3Move(float* __restrict _result, const float* __restrict _a) |
| 125 | 144 | { |
| 126 | 145 | _result[0] = _a[0]; |
| r249195 | r249196 | |
| 833 | 852 | _result[3] = -vec3Dot(normal, _va); |
| 834 | 853 | } |
| 835 | 854 | |
| 855 | inline void calcLinearFit2D(float _result[2], const void* _points, uint32_t _stride, uint32_t _numPoints) | |
| 856 | { | |
| 857 | float sumX = 0.0f; | |
| 858 | float sumY = 0.0f; | |
| 859 | float sumXX = 0.0f; | |
| 860 | float sumXY = 0.0f; | |
| 861 | ||
| 862 | const uint8_t* ptr = (const uint8_t*)_points; | |
| 863 | for (uint32_t ii = 0; ii < _numPoints; ++ii, ptr += _stride) | |
| 864 | { | |
| 865 | const float* point = (const float*)ptr; | |
| 866 | float xx = point[0]; | |
| 867 | float yy = point[1]; | |
| 868 | sumX += xx; | |
| 869 | sumY += yy; | |
| 870 | sumXX += xx*xx; | |
| 871 | sumXY += xx*yy; | |
| 872 | } | |
| 873 | ||
| 874 | // [ sum(x^2) sum(x) ] [ A ] = [ sum(x*y) ] | |
| 875 | // [ sum(x) numPoints ] [ B ] [ sum(y) ] | |
| 876 | ||
| 877 | float det = (sumXX*_numPoints - sumX*sumX); | |
| 878 | float invDet = 1.0f/det; | |
| 879 | ||
| 880 | _result[0] = (-sumX * sumY + _numPoints * sumXY) * invDet; | |
| 881 | _result[1] = (sumXX * sumY - sumX * sumXY) * invDet; | |
| 882 | } | |
| 883 | ||
| 884 | inline void calcLinearFit3D(float _result[3], const void* _points, uint32_t _stride, uint32_t _numPoints) | |
| 885 | { | |
| 886 | float sumX = 0.0f; | |
| 887 | float sumY = 0.0f; | |
| 888 | float sumZ = 0.0f; | |
| 889 | float sumXX = 0.0f; | |
| 890 | float sumXY = 0.0f; | |
| 891 | float sumXZ = 0.0f; | |
| 892 | float sumYY = 0.0f; | |
| 893 | float sumYZ = 0.0f; | |
| 894 | ||
| 895 | const uint8_t* ptr = (const uint8_t*)_points; | |
| 896 | for (uint32_t ii = 0; ii < _numPoints; ++ii, ptr += _stride) | |
| 897 | { | |
| 898 | const float* point = (const float*)ptr; | |
| 899 | float xx = point[0]; | |
| 900 | float yy = point[1]; | |
| 901 | float zz = point[2]; | |
| 902 | ||
| 903 | sumX += xx; | |
| 904 | sumY += yy; | |
| 905 | sumZ += zz; | |
| 906 | sumXX += xx*xx; | |
| 907 | sumXY += xx*yy; | |
| 908 | sumXZ += xx*zz; | |
| 909 | sumYY += yy*yy; | |
| 910 | sumYZ += yy*zz; | |
| 911 | } | |
| 912 | ||
| 913 | // [ sum(x^2) sum(x*y) sum(x) ] [ A ] [ sum(x*z) ] | |
| 914 | // [ sum(x*y) sum(y^2) sum(y) ] [ B ] = [ sum(y*z) ] | |
| 915 | // [ sum(x) sum(y) numPoints ] [ C ] [ sum(z) ] | |
| 916 | ||
| 917 | float mtx[9] = | |
| 918 | { | |
| 919 | sumXX, sumXY, sumX, | |
| 920 | sumXY, sumYY, sumY, | |
| 921 | sumX, sumY, float(_numPoints), | |
| 922 | }; | |
| 923 | float invMtx[9]; | |
| 924 | mtx3Inverse(invMtx, mtx); | |
| 925 | ||
| 926 | _result[0] = invMtx[0]*sumXZ + invMtx[1]*sumYZ + invMtx[2]*sumZ; | |
| 927 | _result[1] = invMtx[3]*sumXZ + invMtx[4]*sumYZ + invMtx[5]*sumZ; | |
| 928 | _result[2] = invMtx[6]*sumXZ + invMtx[7]*sumYZ + invMtx[8]*sumZ; | |
| 929 | } | |
| 930 | ||
| 836 | 931 | inline void rgbToHsv(float _hsv[3], const float _rgb[3]) |
| 837 | 932 | { |
| 838 | 933 | const float rr = _rgb[0]; |
| r249195 | r249196 | |
|---|---|---|
| 11 | 11 | |
| 12 | 12 | namespace bx |
| 13 | 13 | { |
| 14 | template <uint16_t MaxHandlesT> | |
| 15 | class HandleAllocT | |
| 14 | class HandleAlloc | |
| 16 | 15 | { |
| 17 | 16 | public: |
| 18 | static const uint16_t invalid = | |
| 17 | static const uint16_t invalid = UINT16_MAX; | |
| 19 | 18 | |
| 20 | HandleAlloc | |
| 19 | HandleAlloc(uint16_t _maxHandles) | |
| 21 | 20 | : m_numHandles(0) |
| 21 | , m_maxHandles(_maxHandles) | |
| 22 | 22 | { |
| 23 | for (uint16_t ii = 0; ii < MaxHandlesT; ++ii) | |
| 24 | { | |
| 25 | m_handles[ii] = ii; | |
| 26 | } | |
| 23 | reset(); | |
| 27 | 24 | } |
| 28 | 25 | |
| 29 | ~HandleAlloc | |
| 26 | ~HandleAlloc() | |
| 30 | 27 | { |
| 31 | 28 | } |
| 32 | 29 | |
| 33 | 30 | const uint16_t* getHandles() const |
| 34 | 31 | { |
| 35 | return | |
| 32 | return getDensePtr(); | |
| 36 | 33 | } |
| 37 | 34 | |
| 38 | 35 | uint16_t getHandleAt(uint16_t _at) const |
| 39 | 36 | { |
| 40 | return | |
| 37 | return getDensePtr()[_at]; | |
| 41 | 38 | } |
| 42 | 39 | |
| 43 | 40 | uint16_t getNumHandles() const |
| r249195 | r249196 | |
| 47 | 44 | |
| 48 | 45 | uint16_t getMaxHandles() const |
| 49 | 46 | { |
| 50 | return | |
| 47 | return m_maxHandles; | |
| 51 | 48 | } |
| 52 | 49 | |
| 53 | 50 | uint16_t alloc() |
| 54 | 51 | { |
| 55 | if (m_numHandles < | |
| 52 | if (m_numHandles < m_maxHandles) | |
| 56 | 53 | { |
| 57 | 54 | uint16_t index = m_numHandles; |
| 58 | 55 | ++m_numHandles; |
| 59 | 56 | |
| 60 | uint16_t handle = m_handles[index]; | |
| 61 | uint16_t* sparse = &m_handles[MaxHandlesT]; | |
| 57 | uint16_t* dense = getDensePtr(); | |
| 58 | uint16_t handle = dense[index]; | |
| 59 | uint16_t* sparse = getSparsePtr(); | |
| 62 | 60 | sparse[handle] = index; |
| 63 | 61 | return handle; |
| 64 | 62 | } |
| r249195 | r249196 | |
| 66 | 64 | return invalid; |
| 67 | 65 | } |
| 68 | 66 | |
| 69 | bool isValid(uint16_t _handle) | |
| 67 | bool isValid(uint16_t _handle) const | |
| 70 | 68 | { |
| 71 | uint16_t* sparse = &m_handles[MaxHandlesT]; | |
| 72 | uint16_t index = sparse[_handle]; | |
| 69 | uint16_t* dense = getDensePtr(); | |
| 70 | uint16_t* sparse = getSparsePtr(); | |
| 71 | uint16_t index = sparse[_handle]; | |
| 73 | 72 | |
| 74 | 73 | return index < m_numHandles |
| 75 | && | |
| 74 | && dense[index] == _handle | |
| 76 | 75 | ; |
| 77 | 76 | } |
| 78 | 77 | |
| 79 | 78 | void free(uint16_t _handle) |
| 80 | 79 | { |
| 81 | BX_CHECK(0 < m_numHandles, "Freeing invalid handle %d.", _handle); | |
| 82 | uint16_t* sparse = &m_handles[MaxHandlesT]; | |
| 80 | uint16_t* dense = getDensePtr(); | |
| 81 | uint16_t* sparse = getSparsePtr(); | |
| 83 | 82 | uint16_t index = sparse[_handle]; |
| 84 | 83 | --m_numHandles; |
| 85 | uint16_t temp = m_handles[m_numHandles]; | |
| 86 | m_handles[m_numHandles] = _handle; | |
| 84 | uint16_t temp = dense[m_numHandles]; | |
| 85 | dense[m_numHandles] = _handle; | |
| 87 | 86 | sparse[temp] = index; |
| 88 | | |
| 87 | dense[index] = temp; | |
| 89 | 88 | } |
| 90 | 89 | |
| 90 | void reset() | |
| 91 | { | |
| 92 | m_numHandles = 0; | |
| 93 | uint16_t* dense = getDensePtr(); | |
| 94 | for (uint16_t ii = 0, num = m_maxHandles; ii < num; ++ii) | |
| 95 | { | |
| 96 | dense[ii] = ii; | |
| 97 | } | |
| 98 | } | |
| 99 | ||
| 91 | 100 | private: |
| 92 | uint16_t m_handles[MaxHandlesT*2]; | |
| 101 | HandleAlloc(); | |
| 102 | ||
| 103 | uint16_t* getDensePtr() const | |
| 104 | { | |
| 105 | uint8_t* ptr = (uint8_t*)reinterpret_cast<const uint8_t*>(this); | |
| 106 | return (uint16_t*)&ptr[sizeof(HandleAlloc)]; | |
| 107 | } | |
| 108 | ||
| 109 | uint16_t* getSparsePtr() const | |
| 110 | { | |
| 111 | return &getDensePtr()[m_maxHandles]; | |
| 112 | } | |
| 113 | ||
| 93 | 114 | uint16_t m_numHandles; |
| 115 | uint16_t m_maxHandles; | |
| 94 | 116 | }; |
| 95 | 117 | |
| 96 | | |
| 118 | inline HandleAlloc* createHandleAlloc(AllocatorI* _allocator, uint16_t _maxHandles) | |
| 97 | 119 | { |
| 120 | uint8_t* ptr = (uint8_t*)BX_ALLOC(_allocator, sizeof(HandleAlloc) + 2*_maxHandles*sizeof(uint16_t) ); | |
| 121 | return ::new (ptr) HandleAlloc(_maxHandles); | |
| 122 | } | |
| 123 | ||
| 124 | inline void destroyHandleAlloc(AllocatorI* _allocator, HandleAlloc* _handleAlloc) | |
| 125 | { | |
| 126 | _handleAlloc->~HandleAlloc(); | |
| 127 | BX_FREE(_allocator, _handleAlloc); | |
| 128 | } | |
| 129 | ||
| 130 | template <uint16_t MaxHandlesT> | |
| 131 | class HandleAllocT : public HandleAlloc | |
| 132 | { | |
| 98 | 133 | public: |
| 99 | static const uint16_t invalid = 0xffff; | |
| 134 | HandleAllocT() | |
| 135 | : HandleAlloc(MaxHandlesT) | |
| 136 | { | |
| 137 | } | |
| 100 | 138 | |
| 101 | HandleAlloc(uint16_t _maxHandles, void* _handles) | |
| 102 | : m_handles( (uint16_t*)_handles) | |
| 103 | , m_numHandles(0) | |
| 104 | , m_maxHandles(_maxHandles) | |
| 139 | ~HandleAllocT() | |
| 105 | 140 | { |
| 106 | for (uint16_t ii = 0; ii < _maxHandles; ++ii) | |
| 141 | } | |
| 142 | ||
| 143 | private: | |
| 144 | uint16_t m_padding[2*MaxHandlesT]; | |
| 145 | }; | |
| 146 | ||
| 147 | template <uint16_t MaxHandlesT> | |
| 148 | class HandleListT | |
| 149 | { | |
| 150 | public: | |
| 151 | static const uint16_t invalid = UINT16_MAX; | |
| 152 | ||
| 153 | HandleListT() | |
| 154 | : m_front(invalid) | |
| 155 | , m_back(invalid) | |
| 156 | { | |
| 157 | reset(); | |
| 158 | } | |
| 159 | ||
| 160 | void pushBack(uint16_t _handle) | |
| 161 | { | |
| 162 | insertAfter(m_back, _handle); | |
| 163 | } | |
| 164 | ||
| 165 | uint16_t popBack() | |
| 166 | { | |
| 167 | uint16_t last = invalid != m_back | |
| 168 | ? m_back | |
| 169 | : m_front | |
| 170 | ; | |
| 171 | ||
| 172 | if (invalid != last) | |
| 107 | 173 | { |
| 108 | m | |
| 174 | remove(last); | |
| 109 | 175 | } |
| 176 | ||
| 177 | return last; | |
| 110 | 178 | } |
| 111 | 179 | |
| 112 | | |
| 180 | void pushFront(uint16_t _handle) | |
| 113 | 181 | { |
| 182 | insertBefore(m_front, _handle); | |
| 114 | 183 | } |
| 115 | 184 | |
| 185 | uint16_t popFront() | |
| 186 | { | |
| 187 | uint16_t front = m_front; | |
| 188 | ||
| 189 | if (invalid != front) | |
| 190 | { | |
| 191 | remove(front); | |
| 192 | } | |
| 193 | ||
| 194 | return front; | |
| 195 | } | |
| 196 | ||
| 197 | uint16_t getFront() const | |
| 198 | { | |
| 199 | return m_front; | |
| 200 | } | |
| 201 | ||
| 202 | uint16_t getBack() const | |
| 203 | { | |
| 204 | return m_back; | |
| 205 | } | |
| 206 | ||
| 207 | uint16_t getNext(uint16_t _handle) const | |
| 208 | { | |
| 209 | BX_CHECK(isValid(_handle), "Invalid handle %d!", _handle); | |
| 210 | const Link& curr = m_links[_handle]; | |
| 211 | return curr.m_next; | |
| 212 | } | |
| 213 | ||
| 214 | uint16_t getPrev(uint16_t _handle) const | |
| 215 | { | |
| 216 | BX_CHECK(isValid(_handle), "Invalid handle %d!", _handle); | |
| 217 | const Link& curr = m_links[_handle]; | |
| 218 | return curr.m_prev; | |
| 219 | } | |
| 220 | ||
| 221 | void remove(uint16_t _handle) | |
| 222 | { | |
| 223 | BX_CHECK(isValid(_handle), "Invalid handle %d!", _handle); | |
| 224 | Link& curr = m_links[_handle]; | |
| 225 | ||
| 226 | if (invalid != curr.m_prev) | |
| 227 | { | |
| 228 | Link& prev = m_links[curr.m_prev]; | |
| 229 | prev.m_next = curr.m_next; | |
| 230 | } | |
| 231 | else | |
| 232 | { | |
| 233 | m_front = curr.m_next; | |
| 234 | } | |
| 235 | ||
| 236 | if (invalid != curr.m_next) | |
| 237 | { | |
| 238 | Link& next = m_links[curr.m_next]; | |
| 239 | next.m_prev = curr.m_prev; | |
| 240 | } | |
| 241 | else | |
| 242 | { | |
| 243 | m_back = curr.m_prev; | |
| 244 | } | |
| 245 | ||
| 246 | curr.m_prev = invalid; | |
| 247 | curr.m_next = invalid; | |
| 248 | } | |
| 249 | ||
| 250 | void reset() | |
| 251 | { | |
| 252 | memset(m_links, 0xff, sizeof(m_links) ); | |
| 253 | } | |
| 254 | ||
| 255 | private: | |
| 256 | void insertBefore(int16_t _before, uint16_t _handle) | |
| 257 | { | |
| 258 | Link& curr = m_links[_handle]; | |
| 259 | curr.m_next = _before; | |
| 260 | ||
| 261 | if (invalid != _before) | |
| 262 | { | |
| 263 | Link& link = m_links[_before]; | |
| 264 | if (invalid != link.m_prev) | |
| 265 | { | |
| 266 | Link& prev = m_links[link.m_prev]; | |
| 267 | prev.m_next = _handle; | |
| 268 | } | |
| 269 | ||
| 270 | curr.m_prev = link.m_prev; | |
| 271 | link.m_prev = _handle; | |
| 272 | } | |
| 273 | ||
| 274 | updateFrontBack(_handle); | |
| 275 | } | |
| 276 | ||
| 277 | void insertAfter(uint16_t _after, uint16_t _handle) | |
| 278 | { | |
| 279 | Link& curr = m_links[_handle]; | |
| 280 | curr.m_prev = _after; | |
| 281 | ||
| 282 | if (invalid != _after) | |
| 283 | { | |
| 284 | Link& link = m_links[_after]; | |
| 285 | if (invalid != link.m_next) | |
| 286 | { | |
| 287 | Link& next = m_links[link.m_next]; | |
| 288 | next.m_prev = _handle; | |
| 289 | } | |
| 290 | ||
| 291 | curr.m_next = link.m_next; | |
| 292 | link.m_next = _handle; | |
| 293 | } | |
| 294 | ||
| 295 | updateFrontBack(_handle); | |
| 296 | } | |
| 297 | ||
| 298 | bool isValid(uint16_t _handle) const | |
| 299 | { | |
| 300 | return _handle < MaxHandlesT; | |
| 301 | } | |
| 302 | ||
| 303 | void updateFrontBack(uint16_t _handle) | |
| 304 | { | |
| 305 | Link& curr = m_links[_handle]; | |
| 306 | ||
| 307 | if (invalid == curr.m_prev) | |
| 308 | { | |
| 309 | m_front = _handle; | |
| 310 | } | |
| 311 | ||
| 312 | if (invalid == curr.m_next) | |
| 313 | { | |
| 314 | m_back = _handle; | |
| 315 | } | |
| 316 | } | |
| 317 | ||
| 318 | uint16_t m_front; | |
| 319 | uint16_t m_back; | |
| 320 | ||
| 321 | struct Link | |
| 322 | { | |
| 323 | uint16_t m_prev; | |
| 324 | uint16_t m_next; | |
| 325 | }; | |
| 326 | ||
| 327 | Link m_links[MaxHandlesT]; | |
| 328 | }; | |
| 329 | ||
| 330 | template <uint16_t MaxHandlesT> | |
| 331 | class HandleAllocLruT | |
| 332 | { | |
| 333 | public: | |
| 334 | static const uint16_t invalid = UINT16_MAX; | |
| 335 | ||
| 336 | HandleAllocLruT() | |
| 337 | { | |
| 338 | reset(); | |
| 339 | } | |
| 340 | ||
| 341 | ~HandleAllocLruT() | |
| 342 | { | |
| 343 | } | |
| 344 | ||
| 116 | 345 | const uint16_t* getHandles() const |
| 117 | 346 | { |
| 118 | return m_ | |
| 347 | return m_alloc.getHandles(); | |
| 119 | 348 | } |
| 120 | 349 | |
| 121 | 350 | uint16_t getHandleAt(uint16_t _at) const |
| 122 | 351 | { |
| 123 | return m_ | |
| 352 | return m_alloc.getHandleAt(_at); | |
| 124 | 353 | } |
| 125 | 354 | |
| 126 | 355 | uint16_t getNumHandles() const |
| 127 | 356 | { |
| 128 | return m_ | |
| 357 | return m_alloc.getNumHandles(); | |
| 129 | 358 | } |
| 130 | 359 | |
| 131 | 360 | uint16_t getMaxHandles() const |
| 132 | 361 | { |
| 133 | return m_ | |
| 362 | return m_alloc.getMaxHandles(); | |
| 134 | 363 | } |
| 135 | 364 | |
| 136 | 365 | uint16_t alloc() |
| 137 | 366 | { |
| 138 | if (m_numHandles < m_maxHandles) | |
| 367 | uint16_t handle = m_alloc.alloc(); | |
| 368 | if (invalid != handle) | |
| 139 | 369 | { |
| 140 | uint16_t index = m_numHandles; | |
| 141 | ++m_numHandles; | |
| 142 | ||
| 143 | uint16_t handle = m_handles[index]; | |
| 144 | uint16_t* sparse = &m_handles[m_maxHandles]; | |
| 145 | sparse[handle] = index; | |
| 146 | return handle; | |
| 370 | m_list.pushFront(handle); | |
| 147 | 371 | } |
| 372 | return handle; | |
| 373 | } | |
| 148 | 374 | |
| 149 | return invalid; | |
| 375 | bool isValid(uint16_t _handle) const | |
| 376 | { | |
| 377 | return m_alloc.isValid(_handle); | |
| 150 | 378 | } |
| 151 | 379 | |
| 152 | | |
| 380 | void free(uint16_t _handle) | |
| 153 | 381 | { |
| 154 | uint16_t* sparse = &m_handles[m_maxHandles]; | |
| 155 | uint16_t index = sparse[_handle]; | |
| 382 | BX_CHECK(isValid(_handle), "Invalid handle %d!", _handle); | |
| 383 | m_list.remove(_handle); | |
| 384 | m_alloc.free(_handle); | |
| 385 | } | |
| 156 | 386 | |
| 157 | return (index < m_numHandles && m_handles[index] == _handle); | |
| 387 | void touch(uint16_t _handle) | |
| 388 | { | |
| 389 | BX_CHECK(isValid(_handle), "Invalid handle %d!", _handle); | |
| 390 | m_list.remove(_handle); | |
| 391 | m_list.pushFront(_handle); | |
| 158 | 392 | } |
| 159 | 393 | |
| 160 | | |
| 394 | uint16_t getFront() const | |
| 161 | 395 | { |
| 162 | uint16_t* sparse = &m_handles[m_maxHandles]; | |
| 163 | uint16_t index = sparse[_handle]; | |
| 164 | --m_numHandles; | |
| 165 | uint16_t temp = m_handles[m_numHandles]; | |
| 166 | m_handles[m_numHandles] = _handle; | |
| 167 | sparse[temp] = index; | |
| 168 | m_handles[index] = temp; | |
| 396 | return m_list.getFront(); | |
| 169 | 397 | } |
| 170 | 398 | |
| 399 | uint16_t getBack() const | |
| 400 | { | |
| 401 | return m_list.getBack(); | |
| 402 | } | |
| 403 | ||
| 404 | uint16_t getNext(uint16_t _handle) const | |
| 405 | { | |
| 406 | return m_list.getNext(_handle); | |
| 407 | } | |
| 408 | ||
| 409 | uint16_t getPrev(uint16_t _handle) const | |
| 410 | { | |
| 411 | return m_list.getPrev(_handle); | |
| 412 | } | |
| 413 | ||
| 414 | void reset() | |
| 415 | { | |
| 416 | m_list.reset(); | |
| 417 | m_alloc.reset(); | |
| 418 | } | |
| 419 | ||
| 171 | 420 | private: |
| 172 | uint16_t* m_handles; | |
| 173 | uint16_t m_numHandles; | |
| 174 | uint16_t m_maxHandles; | |
| 421 | HandleListT<MaxHandlesT> m_list; | |
| 422 | HandleAllocT<MaxHandlesT> m_alloc; | |
| 175 | 423 | }; |
| 176 | 424 | |
| 177 | inline HandleAlloc* createHandleAlloc(AllocatorI* _allocator, uint16_t _maxHandles) | |
| 178 | { | |
| 179 | uint8_t* ptr = (uint8_t*)BX_ALLOC(_allocator, sizeof(HandleAlloc) + 2*_maxHandles*sizeof(uint16_t) ); | |
| 180 | return ::new (ptr) HandleAlloc(_maxHandles, &ptr[sizeof(HandleAlloc)]); | |
| 181 | } | |
| 182 | ||
| 183 | inline void destroyHandleAlloc(AllocatorI* _allocator, HandleAlloc* _handleAlloc) | |
| 184 | { | |
| 185 | _handleAlloc->~HandleAlloc(); | |
| 186 | BX_FREE(_allocator, _handleAlloc); | |
| 187 | } | |
| 188 | ||
| 189 | 425 | } // namespace bx |
| 190 | 426 | |
| 191 | 427 | #endif // BX_HANDLE_ALLOC_H_HEADER_GUARD |
| r249195 | r249196 | |
|---|---|---|
| 30 | 30 | |
| 31 | 31 | void add(const void* _data, int _len) |
| 32 | 32 | { |
| 33 | const uint8_t* data = (uint8_t*)_data; | |
| 33 | if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) | |
| 34 | && BX_UNLIKELY(!isPtrAligned(_data, 4) ) ) | |
| 35 | { | |
| 36 | addUnaligned(_data, _len); | |
| 37 | return; | |
| 38 | } | |
| 39 | ||
| 40 | addAligned(_data, _len); | |
| 41 | } | |
| 42 | ||
| 43 | void addAligned(const void* _data, int _len) | |
| 44 | { | |
| 45 | const uint8_t* data = (const uint8_t*)_data; | |
| 34 | 46 | m_size += _len; |
| 35 | 47 | |
| 36 | 48 | mixTail(data, _len); |
| r249195 | r249196 | |
| 48 | 60 | mixTail(data, _len); |
| 49 | 61 | } |
| 50 | 62 | |
| 63 | void addUnaligned(const void* _data, int _len) | |
| 64 | { | |
| 65 | const uint8_t* data = (const uint8_t*)_data; | |
| 66 | m_size += _len; | |
| 67 | ||
| 68 | mixTail(data, _len); | |
| 69 | ||
| 70 | while(_len >= 4) | |
| 71 | { | |
| 72 | uint32_t kk; | |
| 73 | readUnaligned(data, kk); | |
| 74 | ||
| 75 | mmix(m_hash, kk); | |
| 76 | ||
| 77 | data += 4; | |
| 78 | _len -= 4; | |
| 79 | } | |
| 80 | ||
| 81 | mixTail(data, _len); | |
| 82 | } | |
| 83 | ||
| 51 | 84 | template<typename Ty> |
| 52 | 85 | void add(Ty _value) |
| 53 | 86 | { |
| r249195 | r249196 | |
| 67 | 100 | } |
| 68 | 101 | |
| 69 | 102 | private: |
| 103 | static void readUnaligned(const void* _data, uint32_t& _out) | |
| 104 | { | |
| 105 | const uint8_t* data = (const uint8_t*)_data; | |
| 106 | if (BX_ENABLED(BX_CPU_ENDIAN_LITTLE) ) | |
| 107 | { | |
| 108 | _out = 0 | |
| 109 | | data[0]<<24 | |
| 110 | | data[1]<<16 | |
| 111 | | data[2]<<8 | |
| 112 | | data[3] | |
| 113 | ; | |
| 114 | } | |
| 115 | else | |
| 116 | { | |
| 117 | _out = 0 | |
| 118 | | data[0] | |
| 119 | | data[1]<<8 | |
| 120 | | data[2]<<16 | |
| 121 | | data[3]<<24 | |
| 122 | ; | |
| 123 | } | |
| 124 | } | |
| 125 | ||
| 70 | 126 | void mixTail(const uint8_t*& _data, int& _len) |
| 71 | 127 | { |
| 72 | 128 | while( _len && ((_len<4) || m_count) ) |
| r249195 | r249196 | |
|---|---|---|
| 53 | 53 | # define BX_ALLOW_UNUSED __attribute__( (unused) ) |
| 54 | 54 | # define BX_FORCE_INLINE __extension__ static __inline __attribute__( (__always_inline__) ) |
| 55 | 55 | # define BX_FUNCTION __PRETTY_FUNCTION__ |
| 56 | # define BX_LIKELY(_x) __builtin_expect(!!(_x), 1) | |
| 57 | # define BX_UNLIKELY(_x) __builtin_expect(!!(_x), 0) | |
| 56 | 58 | # define BX_NO_INLINE __attribute__( (noinline) ) |
| 57 | 59 | # define BX_NO_RETURN __attribute__( (noreturn) ) |
| 58 | 60 | # define BX_NO_VTABLE |
| r249195 | r249196 | |
| 61 | 63 | # if BX_COMPILER_CLANG && (BX_PLATFORM_OSX || BX_PLATFORM_IOS) |
| 62 | 64 | # define BX_THREAD /* not supported right now */ |
| 63 | 65 | # else |
| 64 | # if (__GNUC__ == 4) && (__GNUC_MINOR__ <= 2) | |
| 65 | # define BX_THREAD /* not supported right now */ | |
| 66 | # else | |
| 67 | # define BX_THREAD __thread | |
| 68 | # endif // __GNUC__ <= 4.2 | |
| 66 | # define BX_THREAD __thread | |
| 69 | 67 | # endif // BX_COMPILER_CLANG |
| 70 | 68 | # define BX_ATTRIBUTE(_x) __attribute__( (_x) ) |
| 71 | 69 | # if BX_COMPILER_MSVC_COMPATIBLE |
| r249195 | r249196 | |
| 76 | 74 | # define BX_ALLOW_UNUSED |
| 77 | 75 | # define BX_FORCE_INLINE __forceinline |
| 78 | 76 | # define BX_FUNCTION __FUNCTION__ |
| 77 | # define BX_LIKELY(_x) (_x) | |
| 78 | # define BX_UNLIKELY(_x) (_x) | |
| 79 | 79 | # define BX_NO_INLINE __declspec(noinline) |
| 80 | 80 | # define BX_NO_RETURN |
| 81 | 81 | # define BX_NO_VTABLE __declspec(novtable) |
| r249195 | r249196 | |
|---|---|---|
| 11 | 11 | |
| 12 | 12 | #if BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT |
| 13 | 13 | # include <windows.h> |
| 14 | #elif BX_PLATFORM_ANDROID \ | |
| 14 | # include <psapi.h> | |
| 15 | #elif BX_PLATFORM_ANDROID \ | |
| 15 | 16 | || BX_PLATFORM_EMSCRIPTEN \ |
| 16 | 17 | || BX_PLATFORM_FREEBSD \ |
| 17 | 18 | || BX_PLATFORM_IOS \ |
| 18 | 19 | || BX_PLATFORM_LINUX \ |
| 19 | 20 | || BX_PLATFORM_NACL \ |
| 20 | || BX_PLATFORM_NETBSD \ | |
| 21 | 21 | || BX_PLATFORM_OSX \ |
| 22 | || BX_PLATFORM_PS4 \ | |
| 22 | 23 | || BX_PLATFORM_RPI |
| 23 | 24 | |
| 24 | 25 | # include <sched.h> // sched_yield |
| 25 | # if BX_PLATFORM_FREEBSD || BX_PLATFORM_IOS || BX_PLATFORM_NACL || BX_PLATFORM_NETBSD || BX_PLATFORM_OSX | |
| 26 | # if BX_PLATFORM_FREEBSD \ | |
| 27 | || BX_PLATFORM_IOS \ | |
| 28 | || BX_PLATFORM_NACL \ | |
| 29 | || BX_PLATFORM_OSX \ | |
| 30 | || BX_PLATFORM_PS4 | |
| 26 | 31 | # include <pthread.h> // mach_port_t |
| 27 | 32 | # endif // BX_PLATFORM_IOS || BX_PLATFORM_OSX || BX_PLATFORM_NACL |
| 28 | 33 | |
| r249195 | r249196 | |
| 30 | 35 | # include <sys/nacl_syscalls.h> // nanosleep |
| 31 | 36 | # else |
| 32 | 37 | # include <time.h> // nanosleep |
| 33 | # include <dlfcn.h> // dlopen, dlclose, dlsym | |
| 38 | # if !BX_PLATFORM_PS4 | |
| 39 | # include <dlfcn.h> // dlopen, dlclose, dlsym | |
| 40 | # endif // !BX_PLATFORM_PS4 | |
| 34 | 41 | # endif // BX_PLATFORM_NACL |
| 35 | 42 | |
| 36 | # if BX_PLATFORM_LINUX || BX_PLATFORM_RPI | |
| 43 | # if BX_PLATFORM_ANDROID | |
| 44 | # include <malloc.h> // mallinfo | |
| 45 | # elif BX_PLATFORM_LINUX || BX_PLATFORM_RPI | |
| 37 | 46 | # include <unistd.h> // syscall |
| 38 | 47 | # include <sys/syscall.h> |
| 39 | # endif // BX_PLATFORM_LINUX || BX_PLATFORM_RPI | |
| 40 | ||
| 41 | # if BX_PLATFORM_ANDROID | |
| 48 | # elif BX_PLATFORM_OSX | |
| 49 | # include <mach/mach.h> // mach_task_basic_info | |
| 50 | # elif BX_PLATFORM_ANDROID | |
| 42 | 51 | # include "debug.h" // getTid is not implemented... |
| 43 | 52 | # endif // BX_PLATFORM_ANDROID |
| 44 | 53 | #endif // BX_PLATFORM_ |
| r249195 | r249196 | |
| 94 | 103 | return (pid_t)::syscall(SYS_gettid); |
| 95 | 104 | #elif BX_PLATFORM_IOS || BX_PLATFORM_OSX |
| 96 | 105 | return (mach_port_t)::pthread_mach_thread_np(pthread_self() ); |
| 97 | #elif BX_PLATFORM_FREEBSD || BX_PLATFORM_NACL | |
| 106 | #elif BX_PLATFORM_FREEBSD || BX_PLATFORM_NACL | |
| 98 | 107 | // Casting __nc_basic_thread_data*... need better way to do this. |
| 99 | 108 | return *(uint32_t*)::pthread_self(); |
| 100 | 109 | #else |
| r249195 | r249196 | |
| 104 | 113 | #endif // |
| 105 | 114 | } |
| 106 | 115 | |
| 116 | inline size_t getProcessMemoryUsed() | |
| 117 | { | |
| 118 | #if BX_PLATFORM_ANDROID | |
| 119 | struct mallinfo mi = mallinfo(); | |
| 120 | return mi.uordblks; | |
| 121 | #elif BX_PLATFORM_LINUX | |
| 122 | FILE* file = fopen("/proc/self/statm", "r"); | |
| 123 | if (NULL == file) | |
| 124 | { | |
| 125 | return 0; | |
| 126 | } | |
| 127 | ||
| 128 | long pages = 0; | |
| 129 | int items = fscanf(file, "%*s%ld", &pages); | |
| 130 | fclose(file); | |
| 131 | return 1 == items | |
| 132 | ? pages * sysconf(_SC_PAGESIZE) | |
| 133 | : 0 | |
| 134 | ; | |
| 135 | #elif BX_PLATFORM_OSX | |
| 136 | mach_task_basic_info info; | |
| 137 | mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT; | |
| 138 | ||
| 139 | int result = task_info(mach_task_self() | |
| 140 | , MACH_TASK_BASIC_INFO | |
| 141 | , (task_info_t)&info | |
| 142 | , &infoCount | |
| 143 | ); | |
| 144 | if (KERN_SUCCESS != result) | |
| 145 | { | |
| 146 | return 0; | |
| 147 | } | |
| 148 | ||
| 149 | return info.resident_size; | |
| 150 | #elif BX_PLATFORM_WINDOWS | |
| 151 | PROCESS_MEMORY_COUNTERS pmc; | |
| 152 | GetProcessMemoryInfo(GetCurrentProcess() | |
| 153 | , &pmc | |
| 154 | , sizeof(pmc) | |
| 155 | ); | |
| 156 | return pmc.WorkingSetSize; | |
| 157 | #else | |
| 158 | return 0; | |
| 159 | #endif // BX_PLATFORM_* | |
| 160 | } | |
| 161 | ||
| 107 | 162 | inline void* dlopen(const char* _filePath) |
| 108 | 163 | { |
| 109 | 164 | #if BX_PLATFORM_WINDOWS |
| 110 | 165 | return (void*)::LoadLibraryA(_filePath); |
| 111 | #elif BX_PLATFORM_NACL || BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_WINRT | |
| 166 | #elif BX_PLATFORM_EMSCRIPTEN \ | |
| 167 | || BX_PLATFORM_NACL \ | |
| 168 | || BX_PLATFORM_PS4 \ | |
| 169 | || BX_PLATFORM_WINRT | |
| 112 | 170 | BX_UNUSED(_filePath); |
| 113 | 171 | return NULL; |
| 114 | 172 | #else |
| r249195 | r249196 | |
| 120 | 178 | { |
| 121 | 179 | #if BX_PLATFORM_WINDOWS |
| 122 | 180 | ::FreeLibrary( (HMODULE)_handle); |
| 123 | #elif BX_PLATFORM_NACL || BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_WINRT | |
| 181 | #elif BX_PLATFORM_EMSCRIPTEN \ | |
| 182 | || BX_PLATFORM_NACL \ | |
| 183 | || BX_PLATFORM_PS4 \ | |
| 184 | || BX_PLATFORM_WINRT | |
| 124 | 185 | BX_UNUSED(_handle); |
| 125 | 186 | #else |
| 126 | 187 | ::dlclose(_handle); |
| r249195 | r249196 | |
| 131 | 192 | { |
| 132 | 193 | #if BX_PLATFORM_WINDOWS |
| 133 | 194 | return (void*)::GetProcAddress( (HMODULE)_handle, _symbol); |
| 134 | #elif BX_PLATFORM_NACL || BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_WINRT | |
| 195 | #elif BX_PLATFORM_EMSCRIPTEN \ | |
| 196 | || BX_PLATFORM_NACL \ | |
| 197 | || BX_PLATFORM_PS4 \ | |
| 198 | || BX_PLATFORM_WINRT | |
| 135 | 199 | BX_UNUSED(_handle, _symbol); |
| 136 | 200 | return NULL; |
| 137 | 201 | #else |
| r249195 | r249196 | |
| 143 | 207 | { |
| 144 | 208 | #if BX_PLATFORM_WINDOWS |
| 145 | 209 | ::SetEnvironmentVariableA(_name, _value); |
| 146 | #elif BX_PLATFORM_WINRT | |
| 210 | #elif BX_PLATFORM_PS4 \ | |
| 211 | || BX_PLATFORM_WINRT | |
| 147 | 212 | BX_UNUSED(_name, _value); |
| 148 | 213 | #else |
| 149 | 214 | ::setenv(_name, _value, 1); |
| r249195 | r249196 | |
| 154 | 219 | { |
| 155 | 220 | #if BX_PLATFORM_WINDOWS |
| 156 | 221 | ::SetEnvironmentVariableA(_name, NULL); |
| 157 | #elif BX_PLATFORM_WINRT | |
| 222 | #elif BX_PLATFORM_PS4 \ | |
| 223 | || BX_PLATFORM_WINRT | |
| 158 | 224 | BX_UNUSED(_name); |
| 159 | 225 | #else |
| 160 | 226 | ::unsetenv(_name); |
| r249195 | r249196 | |
| 163 | 229 | |
| 164 | 230 | inline int chdir(const char* _path) |
| 165 | 231 | { |
| 166 | #if BX_PLATFORM_WINRT | |
| 232 | #if BX_PLATFORM_PS4 \ | |
| 233 | || BX_PLATFORM_WINRT | |
| 167 | 234 | BX_UNUSED(_path); |
| 168 | 235 | return -1; |
| 169 | 236 | #elif BX_COMPILER_MSVC_COMPATIBLE |
| r249195 | r249196 | |
| 175 | 242 | |
| 176 | 243 | inline char* pwd(char* _buffer, uint32_t _size) |
| 177 | 244 | { |
| 178 | #if BX_PLATFORM_WINRT | |
| 245 | #if BX_PLATFORM_PS4 \ | |
| 246 | || BX_PLATFORM_WINRT | |
| 179 | 247 | BX_UNUSED(_buffer, _size); |
| 180 | 248 | return NULL; |
| 181 | 249 | #elif BX_COMPILER_MSVC_COMPATIBLE |
| r249195 | r249196 | |
|---|---|---|
| 18 | 18 | #define BX_PLATFORM_IOS 0 |
| 19 | 19 | #define BX_PLATFORM_LINUX 0 |
| 20 | 20 | #define BX_PLATFORM_NACL 0 |
| 21 | #define BX_PLATFORM_NETBSD 0 | |
| 22 | 21 | #define BX_PLATFORM_OSX 0 |
| 23 | 22 | #define BX_PLATFORM_PS4 0 |
| 24 | 23 | #define BX_PLATFORM_QNX 0 |
| r249195 | r249196 | |
| 176 | 175 | #elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) |
| 177 | 176 | # undef BX_PLATFORM_OSX |
| 178 | 177 | # define BX_PLATFORM_OSX 1 |
| 179 | #elif defined(EMSCRIPTEN) | |
| 178 | #elif defined(__EMSCRIPTEN__) | |
| 180 | 179 | # undef BX_PLATFORM_EMSCRIPTEN |
| 181 | 180 | # define BX_PLATFORM_EMSCRIPTEN 1 |
| 182 | 181 | #elif defined(__ORBIS__) |
| r249195 | r249196 | |
| 188 | 187 | #elif defined(__FreeBSD__) |
| 189 | 188 | # undef BX_PLATFORM_FREEBSD |
| 190 | 189 | # define BX_PLATFORM_FREEBSD 1 |
| 191 | #elif defined(__NetBSD__) | |
| 192 | # undef BX_PLATFORM_NETBSD | |
| 193 | # define BX_PLATFORM_NETBSD 1 | |
| 194 | 190 | #else |
| 195 | 191 | # error "BX_PLATFORM_* is not defined!" |
| 196 | 192 | #endif // |
| r249195 | r249196 | |
| 202 | 198 | || BX_PLATFORM_IOS \ |
| 203 | 199 | || BX_PLATFORM_LINUX \ |
| 204 | 200 | || BX_PLATFORM_NACL \ |
| 205 | || BX_PLATFORM_NETBSD \ | |
| 206 | 201 | || BX_PLATFORM_OSX \ |
| 207 | 202 | || BX_PLATFORM_QNX \ |
| 203 | || BX_PLATFORM_PS4 \ | |
| 208 | 204 | || BX_PLATFORM_RPI \ |
| 209 | 205 | ) |
| 210 | 206 | |
| r249195 | r249196 | |
| 255 | 251 | #elif BX_PLATFORM_NACL |
| 256 | 252 | # define BX_PLATFORM_NAME "NaCl " \ |
| 257 | 253 | BX_STRINGIZE(BX_PLATFORM_NACL) |
| 258 | #elif BX_PLATFORM_NETBSD | |
| 259 | # define BX_PLATFORM_NAME "NetBSD" | |
| 260 | 254 | #elif BX_PLATFORM_OSX |
| 261 | 255 | # define BX_PLATFORM_NAME "OSX" |
| 262 | 256 | #elif BX_PLATFORM_PS4 |
| r0 | r249196 | |
|---|---|---|
| 1 | /* | |
| 2 | * Copyright 2010-2015 Branimir Karadzic. All rights reserved. | |
| 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause | |
| 4 | */ | |
| 5 | ||
| 6 | #ifndef BX_PROCESS_H_HEADER_GUARD | |
| 7 | #define BX_PROCESS_H_HEADER_GUARD | |
| 8 | ||
| 9 | #include "string.h" | |
| 10 | #include "uint32_t.h" | |
| 11 | ||
| 12 | #if BX_PLATFORM_LINUX | |
| 13 | # include <unistd.h> | |
| 14 | #endif // BX_PLATFORM_LINUX | |
| 15 | ||
| 16 | namespace bx | |
| 17 | { | |
| 18 | /// | |
| 19 | inline void* exec(const char* const* _argv) | |
| 20 | { | |
| 21 | #if BX_PLATFORM_LINUX | |
| 22 | pid_t pid = fork(); | |
| 23 | ||
| 24 | if (0 == pid) | |
| 25 | { | |
| 26 | int result = execvp(_argv[0], const_cast<char *const*>(&_argv[1]) ); | |
| 27 | BX_UNUSED(result); | |
| 28 | return NULL; | |
| 29 | } | |
| 30 | ||
| 31 | return (void*)uintptr_t(pid); | |
| 32 | #elif BX_PLATFORM_WINDOWS | |
| 33 | STARTUPINFO si; | |
| 34 | memset(&si, 0, sizeof(STARTUPINFO) ); | |
| 35 | si.cb = sizeof(STARTUPINFO); | |
| 36 | ||
| 37 | PROCESS_INFORMATION pi; | |
| 38 | memset(&pi, 0, sizeof(PROCESS_INFORMATION) ); | |
| 39 | ||
| 40 | int32_t total = 0; | |
| 41 | for (uint32_t ii = 0; NULL != _argv[ii]; ++ii) | |
| 42 | { | |
| 43 | total += (int32_t)strlen(_argv[ii]) + 1; | |
| 44 | } | |
| 45 | ||
| 46 | char* temp = (char*)alloca(total); | |
| 47 | int32_t len = 0; | |
| 48 | for(uint32_t ii = 0; NULL != _argv[ii]; ++ii) | |
| 49 | { | |
| 50 | len += snprintf(&temp[len], bx::uint32_imax(0, total-len) | |
| 51 | , "%s " | |
| 52 | , _argv[ii] | |
| 53 | ); | |
| 54 | } | |
| 55 | ||
| 56 | bool ok = CreateProcessA(_argv[0] | |
| 57 | , temp | |
| 58 | , NULL | |
| 59 | , NULL | |
| 60 | , false | |
| 61 | , 0 | |
| 62 | , NULL | |
| 63 | , NULL | |
| 64 | , &si | |
| 65 | , &pi | |
| 66 | ); | |
| 67 | if (ok) | |
| 68 | { | |
| 69 | return pi.hProcess; | |
| 70 | } | |
| 71 | ||
| 72 | return NULL; | |
| 73 | #else | |
| 74 | return NULL; | |
| 75 | #endif // BX_PLATFORM_LINUX | |
| 76 | } | |
| 77 | ||
| 78 | } // namespace bx | |
| 79 | ||
| 80 | #endif // BX_PROCESS_H_HEADER_GUARD |
| r249195 | r249196 | |
|---|---|---|
| 40 | 40 | uint32_t consume(uint32_t _size) // consumer only |
| 41 | 41 | { |
| 42 | 42 | const uint32_t maxSize = distance(m_read, m_current); |
| 43 | const uint32_t sizeNoSign = uint32_and(_size, 0x7 | |
| 43 | const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); | |
| 44 | 44 | const uint32_t test = uint32_sub(sizeNoSign, maxSize); |
| 45 | 45 | const uint32_t size = uint32_sels(test, _size, maxSize); |
| 46 | 46 | const uint32_t advance = uint32_add(m_read, size); |
| r249195 | r249196 | |
| 53 | 53 | { |
| 54 | 54 | const uint32_t dist = distance(m_write, m_read)-1; |
| 55 | 55 | const uint32_t maxSize = uint32_sels(dist, m_size-1, dist); |
| 56 | const uint32_t sizeNoSign = uint32_and(_size, 0x7 | |
| 56 | const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); | |
| 57 | 57 | const uint32_t test = uint32_sub(sizeNoSign, maxSize); |
| 58 | 58 | const uint32_t size = uint32_sels(test, _size, maxSize); |
| 59 | 59 | const uint32_t advance = uint32_add(m_write, size); |
| r249195 | r249196 | |
| 65 | 65 | uint32_t commit(uint32_t _size) // producer only |
| 66 | 66 | { |
| 67 | 67 | const uint32_t maxSize = distance(m_current, m_write); |
| 68 | const uint32_t sizeNoSign = uint32_and(_size, 0x7 | |
| 68 | const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); | |
| 69 | 69 | const uint32_t test = uint32_sub(sizeNoSign, maxSize); |
| 70 | 70 | const uint32_t size = uint32_sels(test, _size, maxSize); |
| 71 | 71 | const uint32_t advance = uint32_add(m_current, size); |
| r249195 | r249196 | |
| 124 | 124 | uint32_t consume(uint32_t _size) // consumer only |
| 125 | 125 | { |
| 126 | 126 | const uint32_t maxSize = distance(m_read, m_current); |
| 127 | const uint32_t sizeNoSign = uint32_and(_size, 0x7 | |
| 127 | const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); | |
| 128 | 128 | const uint32_t test = uint32_sub(sizeNoSign, maxSize); |
| 129 | 129 | const uint32_t size = uint32_sels(test, _size, maxSize); |
| 130 | 130 | const uint32_t advance = uint32_add(m_read, size); |
| r249195 | r249196 | |
| 137 | 137 | { |
| 138 | 138 | const uint32_t dist = distance(m_write, m_read)-1; |
| 139 | 139 | const uint32_t maxSize = uint32_sels(dist, m_size-1, dist); |
| 140 | const uint32_t sizeNoSign = uint32_and(_size, 0x7 | |
| 140 | const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); | |
| 141 | 141 | const uint32_t test = uint32_sub(sizeNoSign, maxSize); |
| 142 | 142 | const uint32_t size = uint32_sels(test, _size, maxSize); |
| 143 | 143 | const uint32_t advance = uint32_add(m_write, size); |
| r249195 | r249196 | |
| 149 | 149 | uint32_t commit(uint32_t _size) // producer only |
| 150 | 150 | { |
| 151 | 151 | const uint32_t maxSize = distance(m_current, m_write); |
| 152 | const uint32_t sizeNoSign = uint32_and(_size, 0x7 | |
| 152 | const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); | |
| 153 | 153 | const uint32_t test = uint32_sub(sizeNoSign, maxSize); |
| 154 | 154 | const uint32_t size = uint32_sels(test, _size, maxSize); |
| 155 | 155 | const uint32_t advance = uint32_add(m_current, size); |
| r249195 | r249196 | |
|---|---|---|
| 113 | 113 | return NULL; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | /// Find substring in string. Case insensitive. Limit search to _ | |
| 116 | /// Find substring in string. Case insensitive. Limit search to _max. | |
| 117 | 117 | inline const char* stristr(const char* _str, const char* _find, size_t _max) |
| 118 | 118 | { |
| 119 | 119 | const char* ptr = _str; |
| 120 | 120 | |
| 121 | const size_t total = strlen(_str); | |
| 122 | size_t len = _max < total ? _max : total; | |
| 121 | size_t stringLen = strnlen(_str, _max); | |
| 122 | const size_t findLen = strlen(_find); | |
| 123 | 123 | |
| 124 | for ( | |
| 124 | for (; stringLen >= findLen; ++ptr, --stringLen) | |
| 125 | 125 | { |
| 126 | 126 | // Find start of the string. |
| 127 | 127 | while (tolower(*ptr) != tolower(*_find) ) |
| 128 | 128 | { |
| 129 | 129 | ++ptr; |
| 130 | -- | |
| 130 | --stringLen; | |
| 131 | 131 | |
| 132 | 132 | // Search pattern lenght can't be longer than the string. |
| 133 | if ( | |
| 133 | if (findLen > stringLen) | |
| 134 | 134 | { |
| 135 | 135 | return NULL; |
| 136 | 136 | } |
| r249195 | r249196 | |
|---|---|---|
| 31 | 31 | |
| 32 | 32 | public: |
| 33 | 33 | Thread() |
| 34 | #if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_WINRT | |
| 34 | #if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT | |
| 35 | 35 | : m_handle(INVALID_HANDLE_VALUE) |
| 36 | , m_threadId(UINT32_MAX) | |
| 36 | 37 | #elif BX_PLATFORM_POSIX |
| 37 | 38 | : m_handle(0) |
| 38 | 39 | #endif // BX_PLATFORM_ |
| r249195 | r249196 | |
| 52 | 53 | } |
| 53 | 54 | } |
| 54 | 55 | |
| 55 | void init(ThreadFn _fn, void* _userData = NULL, uint32_t _stackSize = 0) | |
| 56 | void init(ThreadFn _fn, void* _userData = NULL, uint32_t _stackSize = 0, const char* _name = NULL) | |
| 56 | 57 | { |
| 57 | 58 | BX_CHECK(!m_running, "Already running!"); |
| 58 | 59 | |
| r249195 | r249196 | |
| 61 | 62 | m_stackSize = _stackSize; |
| 62 | 63 | m_running = true; |
| 63 | 64 | |
| 64 | #if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360 | |
| 65 | #if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 | |
| 65 | 66 | m_handle = CreateThread(NULL |
| 66 | 67 | , m_stackSize |
| 67 | 68 | , threadFunc |
| r249195 | r249196 | |
| 102 | 103 | #endif // BX_PLATFORM_ |
| 103 | 104 | |
| 104 | 105 | m_sem.wait(); |
| 106 | ||
| 107 | if (NULL != _name) | |
| 108 | { | |
| 109 | setThreadName(_name); | |
| 110 | } | |
| 105 | 111 | } |
| 106 | 112 | |
| 107 | 113 | void shutdown() |
| 108 | 114 | { |
| 109 | 115 | BX_CHECK(m_running, "Not running!"); |
| 110 | #if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360 | |
| 116 | #if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 | |
| 111 | 117 | WaitForSingleObject(m_handle, INFINITE); |
| 112 | 118 | GetExitCodeThread(m_handle, (DWORD*)&m_exitCode); |
| 113 | 119 | CloseHandle(m_handle); |
| r249195 | r249196 | |
| 139 | 145 | return m_exitCode; |
| 140 | 146 | } |
| 141 | 147 | |
| 148 | void setThreadName(const char* _name) | |
| 149 | { | |
| 150 | #if BX_PLATFORM_OSX || BX_PLATFORM_IOS | |
| 151 | pthread_setname_np(_name); | |
| 152 | #elif BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD | |
| 153 | pthread_setname_np(m_handle, _name); | |
| 154 | #elif BX_PLATFORM_WINDOWS && BX_COMPILER_MSVC | |
| 155 | # pragma pack(push, 8) | |
| 156 | struct ThreadName | |
| 157 | { | |
| 158 | DWORD type; | |
| 159 | LPCSTR name; | |
| 160 | DWORD id; | |
| 161 | DWORD flags; | |
| 162 | }; | |
| 163 | # pragma pack(pop) | |
| 164 | ThreadName tn; | |
| 165 | tn.type = 0x1000; | |
| 166 | tn.name = _name; | |
| 167 | tn.id = m_threadId; | |
| 168 | tn.flags = 0; | |
| 169 | ||
| 170 | __try | |
| 171 | { | |
| 172 | RaiseException(0x406d1388 | |
| 173 | , 0 | |
| 174 | , sizeof(tn)/4 | |
| 175 | , reinterpret_cast<ULONG_PTR*>(&tn) | |
| 176 | ); | |
| 177 | } | |
| 178 | __except(EXCEPTION_EXECUTE_HANDLER) | |
| 179 | { | |
| 180 | } | |
| 181 | #else | |
| 182 | BX_UNUSED(_name); | |
| 183 | #endif // BX_PLATFORM_ | |
| 184 | } | |
| 185 | ||
| 142 | 186 | private: |
| 143 | 187 | int32_t entry() |
| 144 | 188 | { |
| 189 | #if BX_PLATFORM_WINDOWS | |
| 190 | m_threadId = ::GetCurrentThreadId(); | |
| 191 | #endif // BX_PLATFORM_WINDOWS | |
| 192 | ||
| 145 | 193 | m_sem.post(); |
| 146 | 194 | return m_fn(m_userData); |
| 147 | 195 | } |
| 148 | 196 | |
| 149 | #if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_WINRT | |
| 197 | #if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT | |
| 150 | 198 | static DWORD WINAPI threadFunc(LPVOID _arg) |
| 151 | 199 | { |
| 152 | 200 | Thread* thread = (Thread*)_arg; |
| r249195 | r249196 | |
| 167 | 215 | } |
| 168 | 216 | #endif // BX_PLATFORM_ |
| 169 | 217 | |
| 170 | #if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_WINRT | |
| 218 | #if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT | |
| 171 | 219 | HANDLE m_handle; |
| 220 | DWORD m_threadId; | |
| 172 | 221 | #elif BX_PLATFORM_POSIX |
| 173 | 222 | pthread_t m_handle; |
| 174 | 223 | #endif // BX_PLATFORM_ |
| 175 | 224 | |
| 176 | ThreadFn m_fn; | |
| 177 | void* m_userData; | |
| 225 | ThreadFn m_fn; | |
| 226 | void* m_userData; | |
| 178 | 227 | Semaphore m_sem; |
| 179 | uint32_t m_stackSize; | |
| 180 | int32_t m_exitCode; | |
| 181 | bool m_running; | |
| 228 | uint32_t m_stackSize; | |
| 229 | int32_t m_exitCode; | |
| 230 | bool m_running; | |
| 182 | 231 | }; |
| 183 | 232 | |
| 184 | 233 | #if BX_PLATFORM_WINDOWS |
| r249195 | r249196 | |
|---|---|---|
| 652 | 652 | inline uint64_t uint64_cntlz_ref(uint64_t _val) |
| 653 | 653 | { |
| 654 | 654 | return _val & UINT64_C(0xffffffff00000000) |
| 655 | ? uint32_cntlz(uint32_t(_val>>32) ) + 32 | |
| 656 | : uint32_cntlz(uint32_t(_val) ) | |
| 655 | ? uint32_cntlz(uint32_t(_val>>32) ) | |
| 656 | : uint32_cntlz(uint32_t(_val) ) + 32 | |
| 657 | 657 | ; |
| 658 | 658 | } |
| 659 | 659 |
| r0 | r249196 | |
|---|---|---|
| 1 | #include <sys/signal.h> |
| r249195 | r249196 | |
|---|---|---|
| 42 | 42 | |
| 43 | 43 | #define __ecount(size) |
| 44 | 44 | #define __bcount(size) |
| 45 | #define __in | |
| 45 | // #define __in // Conflicts with STL. | |
| 46 | 46 | #define __in_ecount(size) |
| 47 | 47 | #define __in_bcount(size) |
| 48 | 48 | #define __in_z |
| r249195 | r249196 | |
| 52 | 52 | #define __in_ecount_nz(size) |
| 53 | 53 | #define __in_bcount_nz(size) |
| 54 | 54 | #define __in_xcount_opt(size) |
| 55 | #define __out | |
| 55 | // #define __out // Conflicts with STL. | |
| 56 | 56 | #define __out_ecount(size) |
| 57 | 57 | #define __out_bcount(size) |
| 58 | 58 | #define __out_ecount_part(size,length) |
| r249195 | r249196 | |
| 246 | 246 | #define __control_entrypoint(category) |
| 247 | 247 | #define __data_entrypoint(category) |
| 248 | 248 | |
| 249 | #define _Always_(annos) | |
| 250 | #define _Analysis_noreturn_ | |
| 251 | #define _Analysis_assume_(expr) | |
| 252 | #define _At_(target, annos) | |
| 253 | #define _At_buffer_(target, iter, bound, annos) | |
| 254 | #define _COM_Outptr_ | |
| 255 | #define _COM_Outptr_opt_ | |
| 256 | #define _COM_Outptr_opt_result_maybenull_ | |
| 257 | #define _COM_Outptr_result_maybenull_ | |
| 258 | #define _Check_return_ | |
| 259 | #define _Const_ | |
| 260 | #define _Deref2_pre_readonly_ | |
| 261 | #define _Deref_in_bound_ | |
| 262 | #define _Deref_in_range_(lb,ub) | |
| 263 | #define _Deref_inout_bound_ | |
| 264 | #define _Deref_inout_z_ | |
| 265 | #define _Deref_inout_z_bytecap_c_(size) | |
| 266 | #define _Deref_inout_z_cap_c_(size) | |
| 267 | #define _Deref_opt_out_ | |
| 268 | #define _Deref_opt_out_opt_ | |
| 269 | #define _Deref_opt_out_opt_z_ | |
| 270 | #define _Deref_opt_out_z_ | |
| 271 | #define _Deref_out_ | |
| 272 | #define _Deref_out_bound_ | |
| 273 | #define _Deref_out_opt_ | |
| 274 | #define _Deref_out_opt_z_ | |
| 275 | #define _Deref_out_range_(lb,ub) | |
| 276 | #define _Deref_out_z_ | |
| 277 | #define _Deref_out_z_bytecap_c_(size) | |
| 278 | #define _Deref_out_z_cap_c_(size) | |
| 279 | #define _Deref_post_bytecap_(size) | |
| 280 | #define _Deref_post_bytecap_c_(size) | |
| 281 | #define _Deref_post_bytecap_x_(size) | |
| 282 | #define _Deref_post_bytecount_(size) | |
| 283 | #define _Deref_post_bytecount_c_(size) | |
| 284 | #define _Deref_post_bytecount_x_(size) | |
| 285 | #define _Deref_post_cap_(size) | |
| 286 | #define _Deref_post_cap_c_(size) | |
| 287 | #define _Deref_post_cap_x_(size) | |
| 288 | #define _Deref_post_count_(size) | |
| 289 | #define _Deref_post_count_c_(size) | |
| 290 | #define _Deref_post_count_x_(size) | |
| 291 | #define _Deref_post_maybenull_ | |
| 292 | #define _Deref_post_notnull_ | |
| 293 | #define _Deref_post_null_ | |
| 294 | #define _Deref_post_opt_bytecap_(size) | |
| 295 | #define _Deref_post_opt_bytecap_c_(size) | |
| 296 | #define _Deref_post_opt_bytecap_x_(size) | |
| 297 | #define _Deref_post_opt_bytecount_(size) | |
| 298 | #define _Deref_post_opt_bytecount_c_(size) | |
| 299 | #define _Deref_post_opt_bytecount_x_(size) | |
| 300 | #define _Deref_post_opt_cap_(size) | |
| 301 | #define _Deref_post_opt_cap_c_(size) | |
| 302 | #define _Deref_post_opt_cap_x_(size) | |
| 303 | #define _Deref_post_opt_count_(size) | |
| 304 | #define _Deref_post_opt_count_c_(size) | |
| 305 | #define _Deref_post_opt_count_x_(size) | |
| 306 | #define _Deref_post_opt_valid_ | |
| 307 | #define _Deref_post_opt_valid_bytecap_(size) | |
| 308 | #define _Deref_post_opt_valid_bytecap_c_(size) | |
| 309 | #define _Deref_post_opt_valid_bytecap_x_(size) | |
| 310 | #define _Deref_post_opt_valid_cap_(size) | |
| 311 | #define _Deref_post_opt_valid_cap_c_(size) | |
| 312 | #define _Deref_post_opt_valid_cap_x_(size) | |
| 313 | #define _Deref_post_opt_z_ | |
| 314 | #define _Deref_post_opt_z_bytecap_(size) | |
| 315 | #define _Deref_post_opt_z_bytecap_c_(size) | |
| 316 | #define _Deref_post_opt_z_bytecap_x_(size) | |
| 317 | #define _Deref_post_opt_z_cap_(size) | |
| 318 | #define _Deref_post_opt_z_cap_c_(size) | |
| 319 | #define _Deref_post_opt_z_cap_x_(size) | |
| 320 | #define _Deref_post_valid_ | |
| 321 | #define _Deref_post_valid_bytecap_(size) | |
| 322 | #define _Deref_post_valid_bytecap_c_(size) | |
| 323 | #define _Deref_post_valid_bytecap_x_(size) | |
| 324 | #define _Deref_post_valid_cap_(size) | |
| 325 | #define _Deref_post_valid_cap_c_(size) | |
| 326 | #define _Deref_post_valid_cap_x_(size) | |
| 327 | #define _Deref_post_z_ | |
| 328 | #define _Deref_post_z_bytecap_(size) | |
| 329 | #define _Deref_post_z_bytecap_c_(size) | |
| 330 | #define _Deref_post_z_bytecap_x_(size) | |
| 331 | #define _Deref_post_z_cap_(size) | |
| 332 | #define _Deref_post_z_cap_c_(size) | |
| 333 | #define _Deref_post_z_cap_x_(size) | |
| 334 | #define _Deref_pre_bytecap_(size) | |
| 335 | #define _Deref_pre_bytecap_c_(size) | |
| 336 | #define _Deref_pre_bytecap_x_(size) | |
| 337 | #define _Deref_pre_bytecount_(size) | |
| 338 | #define _Deref_pre_bytecount_c_(size) | |
| 339 | #define _Deref_pre_bytecount_x_(size) | |
| 340 | #define _Deref_pre_cap_(size) | |
| 341 | #define _Deref_pre_cap_c_(size) | |
| 342 | #define _Deref_pre_cap_x_(size) | |
| 343 | #define _Deref_pre_count_(size) | |
| 344 | #define _Deref_pre_count_c_(size) | |
| 345 | #define _Deref_pre_count_x_(size) | |
| 346 | #define _Deref_pre_invalid_ | |
| 347 | #define _Deref_pre_maybenull_ | |
| 348 | #define _Deref_pre_notnull_ | |
| 349 | #define _Deref_pre_null_ | |
| 350 | #define _Deref_pre_opt_bytecap_(size) | |
| 351 | #define _Deref_pre_opt_bytecap_c_(size) | |
| 352 | #define _Deref_pre_opt_bytecap_x_(size) | |
| 353 | #define _Deref_pre_opt_bytecount_(size) | |
| 354 | #define _Deref_pre_opt_bytecount_c_(size) | |
| 355 | #define _Deref_pre_opt_bytecount_x_(size) | |
| 356 | #define _Deref_pre_opt_cap_(size) | |
| 357 | #define _Deref_pre_opt_cap_c_(size) | |
| 358 | #define _Deref_pre_opt_cap_x_(size) | |
| 359 | #define _Deref_pre_opt_count_(size) | |
| 360 | #define _Deref_pre_opt_count_c_(size) | |
| 361 | #define _Deref_pre_opt_count_x_(size) | |
| 362 | #define _Deref_pre_opt_valid_ | |
| 363 | #define _Deref_pre_opt_valid_bytecap_(size) | |
| 364 | #define _Deref_pre_opt_valid_bytecap_c_(size) | |
| 365 | #define _Deref_pre_opt_valid_bytecap_x_(size) | |
| 366 | #define _Deref_pre_opt_valid_cap_(size) | |
| 367 | #define _Deref_pre_opt_valid_cap_c_(size) | |
| 368 | #define _Deref_pre_opt_valid_cap_x_(size) | |
| 369 | #define _Deref_pre_opt_z_ | |
| 370 | #define _Deref_pre_opt_z_bytecap_(size) | |
| 371 | #define _Deref_pre_opt_z_bytecap_c_(size) | |
| 372 | #define _Deref_pre_opt_z_bytecap_x_(size) | |
| 373 | #define _Deref_pre_opt_z_cap_(size) | |
| 374 | #define _Deref_pre_opt_z_cap_c_(size) | |
| 375 | #define _Deref_pre_opt_z_cap_x_(size) | |
| 376 | #define _Deref_pre_readonly_ | |
| 377 | #define _Deref_pre_valid_ | |
| 378 | #define _Deref_pre_valid_bytecap_(size) | |
| 379 | #define _Deref_pre_valid_bytecap_c_(size) | |
| 380 | #define _Deref_pre_valid_bytecap_x_(size) | |
| 381 | #define _Deref_pre_valid_cap_(size) | |
| 382 | #define _Deref_pre_valid_cap_c_(size) | |
| 383 | #define _Deref_pre_valid_cap_x_(size) | |
| 384 | #define _Deref_pre_writeonly_ | |
| 385 | #define _Deref_pre_z_ | |
| 386 | #define _Deref_pre_z_bytecap_(size) | |
| 387 | #define _Deref_pre_z_bytecap_c_(size) | |
| 388 | #define _Deref_pre_z_bytecap_x_(size) | |
| 389 | #define _Deref_pre_z_cap_(size) | |
| 390 | #define _Deref_pre_z_cap_c_(size) | |
| 391 | #define _Deref_pre_z_cap_x_(size) | |
| 392 | #define _Deref_prepost_bytecap_(size) | |
| 393 | #define _Deref_prepost_bytecap_x_(size) | |
| 394 | #define _Deref_prepost_bytecount_(size) | |
| 395 | #define _Deref_prepost_bytecount_x_(size) | |
| 396 | #define _Deref_prepost_cap_(size) | |
| 397 | #define _Deref_prepost_cap_x_(size) | |
| 398 | #define _Deref_prepost_count_(size) | |
| 399 | #define _Deref_prepost_count_x_(size) | |
| 400 | #define _Deref_prepost_opt_bytecap_(size) | |
| 401 | #define _Deref_prepost_opt_bytecap_x_(size) | |
| 402 | #define _Deref_prepost_opt_bytecount_(size) | |
| 403 | #define _Deref_prepost_opt_bytecount_x_(size) | |
| 404 | #define _Deref_prepost_opt_cap_(size) | |
| 405 | #define _Deref_prepost_opt_cap_x_(size) | |
| 406 | #define _Deref_prepost_opt_count_(size) | |
| 407 | #define _Deref_prepost_opt_count_x_(size) | |
| 408 | #define _Deref_prepost_opt_valid_ | |
| 409 | #define _Deref_prepost_opt_valid_bytecap_(size) | |
| 410 | #define _Deref_prepost_opt_valid_bytecap_x_(size) | |
| 411 | #define _Deref_prepost_opt_valid_cap_(size) | |
| 412 | #define _Deref_prepost_opt_valid_cap_x_(size) | |
| 413 | #define _Deref_prepost_opt_z_ | |
| 414 | #define _Deref_prepost_opt_z_bytecap_(size) | |
| 415 | #define _Deref_prepost_opt_z_cap_(size) | |
| 416 | #define _Deref_prepost_valid_ | |
| 417 | #define _Deref_prepost_valid_bytecap_(size) | |
| 418 | #define _Deref_prepost_valid_bytecap_x_(size) | |
| 419 | #define _Deref_prepost_valid_cap_(size) | |
| 420 | #define _Deref_prepost_valid_cap_x_(size) | |
| 421 | #define _Deref_prepost_z_ | |
| 422 | #define _Deref_prepost_z_bytecap_(size) | |
| 423 | #define _Deref_prepost_z_cap_(size) | |
| 424 | #define _Deref_ret_bound_ | |
| 425 | #define _Deref_ret_opt_z_ | |
| 426 | #define _Deref_ret_range_(lb,ub) | |
| 427 | #define _Deref_ret_z_ | |
| 428 | #define _Field_range_(min,max) | |
| 429 | #define _Field_size_(size) | |
| 430 | #define _Field_size_bytes_(size) | |
| 431 | #define _Field_size_bytes_full_(size) | |
| 432 | #define _Field_size_bytes_full_opt_(size) | |
| 433 | #define _Field_size_bytes_opt_(size) | |
| 434 | #define _Field_size_bytes_part_(size, count) | |
| 435 | #define _Field_size_bytes_part_opt_(size, count) | |
| 436 | #define _Field_size_full_(size) | |
| 437 | #define _Field_size_full_opt_(size) | |
| 438 | #define _Field_size_opt_(size) | |
| 439 | #define _Field_size_part_(size, count) | |
| 440 | #define _Field_size_part_opt_(size, count) | |
| 441 | #define _Field_z_ | |
| 442 | #define _Function_class_(x) | |
| 443 | #define _Group_(annos) | |
| 444 | #define _In_ | |
| 445 | #define _In_bound_ | |
| 446 | #define _In_bytecount_(size) | |
| 447 | #define _In_bytecount_c_(size) | |
| 448 | #define _In_bytecount_x_(size) | |
| 449 | #define _In_count_(size) | |
| 450 | #define _In_count_c_(size) | |
| 451 | #define _In_count_x_(size) | |
| 452 | #define _In_defensive_(annotes) | |
| 453 | #define _In_opt_ | |
| 454 | #define _In_opt_bytecount_(size) | |
| 455 | #define _In_opt_bytecount_c_(size) | |
| 456 | #define _In_opt_bytecount_x_(size) | |
| 457 | #define _In_opt_count_(size) | |
| 458 | #define _In_opt_count_c_(size) | |
| 459 | #define _In_opt_count_x_(size) | |
| 460 | #define _In_opt_ptrdiff_count_(size) | |
| 461 | #define _In_opt_z_ | |
| 462 | #define _In_opt_z_bytecount_(size) | |
| 463 | #define _In_opt_z_bytecount_c_(size) | |
| 464 | #define _In_opt_z_count_(size) | |
| 465 | #define _In_opt_z_count_c_(size) | |
| 466 | #define _In_ptrdiff_count_(size) | |
| 467 | #define _In_range_(lb,ub) | |
| 468 | #define _In_reads_(size) | |
| 469 | #define _In_reads_bytes_(size) | |
| 470 | #define _In_reads_bytes_opt_(size) | |
| 471 | #define _In_reads_opt_(size) | |
| 472 | #define _In_reads_opt_z_(size) | |
| 473 | #define _In_reads_or_z_(size) | |
| 474 | #define _In_reads_to_ptr_(ptr) | |
| 475 | #define _In_reads_to_ptr_opt_(ptr) | |
| 476 | #define _In_reads_to_ptr_opt_z_(ptr) | |
| 477 | #define _In_reads_to_ptr_z_(ptr) | |
| 478 | #define _In_reads_z_(size) | |
| 479 | #define _In_z_ | |
| 480 | #define _In_z_bytecount_(size) | |
| 481 | #define _In_z_bytecount_c_(size) | |
| 482 | #define _In_z_count_(size) | |
| 483 | #define _In_z_count_c_(size) | |
| 484 | #define _Inout_ | |
| 485 | #define _Inout_bytecap_(size) | |
| 486 | #define _Inout_bytecap_c_(size) | |
| 487 | #define _Inout_bytecap_x_(size) | |
| 488 | #define _Inout_bytecount_(size) | |
| 489 | #define _Inout_bytecount_c_(size) | |
| 490 | #define _Inout_bytecount_x_(size) | |
| 491 | #define _Inout_cap_(size) | |
| 492 | #define _Inout_cap_c_(size) | |
| 493 | #define _Inout_cap_x_(size) | |
| 494 | #define _Inout_count_(size) | |
| 495 | #define _Inout_count_c_(size) | |
| 496 | #define _Inout_count_x_(size) | |
| 497 | #define _Inout_defensive_(annotes) | |
| 498 | #define _Inout_opt_ | |
| 499 | #define _Inout_opt_bytecap_(size) | |
| 500 | #define _Inout_opt_bytecap_c_(size) | |
| 501 | #define _Inout_opt_bytecap_x_(size) | |
| 502 | #define _Inout_opt_bytecount_(size) | |
| 503 | #define _Inout_opt_bytecount_c_(size) | |
| 504 | #define _Inout_opt_bytecount_x_(size) | |
| 505 | #define _Inout_opt_cap_(size) | |
| 506 | #define _Inout_opt_cap_c_(size) | |
| 507 | #define _Inout_opt_cap_x_(size) | |
| 508 | #define _Inout_opt_count_(size) | |
| 509 | #define _Inout_opt_count_c_(size) | |
| 510 | #define _Inout_opt_count_x_(size) | |
| 511 | #define _Inout_opt_ptrdiff_count_(size) | |
| 512 | #define _Inout_opt_z_ | |
| 513 | #define _Inout_opt_z_bytecap_(size) | |
| 514 | #define _Inout_opt_z_bytecap_c_(size) | |
| 515 | #define _Inout_opt_z_bytecap_x_(size) | |
| 516 | #define _Inout_opt_z_bytecount_(size) | |
| 517 | #define _Inout_opt_z_bytecount_c_(size) | |
| 518 | #define _Inout_opt_z_cap_(size) | |
| 519 | #define _Inout_opt_z_cap_c_(size) | |
| 520 | #define _Inout_opt_z_cap_x_(size) | |
| 521 | #define _Inout_opt_z_count_(size) | |
| 522 | #define _Inout_opt_z_count_c_(size) | |
| 523 | #define _Inout_ptrdiff_count_(size) | |
| 524 | #define _Inout_updates_(size) | |
| 525 | #define _Inout_updates_all_(size) | |
| 526 | #define _Inout_updates_all_opt_(size) | |
| 527 | #define _Inout_updates_bytes_(size) | |
| 528 | #define _Inout_updates_bytes_all_(size) | |
| 529 | #define _Inout_updates_bytes_all_opt_(size) | |
| 530 | #define _Inout_updates_bytes_opt_(size) | |
| 531 | #define _Inout_updates_bytes_to_(size,count) | |
| 532 | #define _Inout_updates_bytes_to_opt_(size,count) | |
| 533 | #define _Inout_updates_opt_(size) | |
| 534 | #define _Inout_updates_opt_z_(size) | |
| 535 | #define _Inout_updates_to_(size,count) | |
| 536 | #define _Inout_updates_to_opt_(size,count) | |
| 537 | #define _Inout_updates_z_(size) | |
| 538 | #define _Inout_z_ | |
| 539 | #define _Inout_z_bytecap_(size) | |
| 540 | #define _Inout_z_bytecap_c_(size) | |
| 541 | #define _Inout_z_bytecap_x_(size) | |
| 542 | #define _Inout_z_bytecount_(size) | |
| 543 | #define _Inout_z_bytecount_c_(size) | |
| 544 | #define _Inout_z_cap_(size) | |
| 545 | #define _Inout_z_cap_c_(size) | |
| 546 | #define _Inout_z_cap_x_(size) | |
| 547 | #define _Inout_z_count_(size) | |
| 548 | #define _Inout_z_count_c_(size) | |
| 549 | #define _Interlocked_operand_ | |
| 550 | #define _Literal_ | |
| 551 | #define _Maybe_raises_SEH_exception | |
| 552 | #define _Maybe_raises_SEH_exception_ | |
| 553 | #define _Maybenull_ | |
| 554 | #define _Maybevalid_ | |
| 555 | #define _Must_inspect_result_ | |
| 556 | #define _Notliteral_ | |
| 557 | #define _Notnull_ | |
| 558 | #define _Notref_ | |
| 559 | #define _Notvalid_ | |
| 560 | #define _NullNull_terminated_ | |
| 561 | #define _Null_ | |
| 562 | #define _Null_terminated_ | |
| 563 | #define _On_failure_(annos) | |
| 564 | #define _Out_ | |
| 565 | #define _Out_bound_ | |
| 566 | #define _Out_bytecap_(size) | |
| 567 | #define _Out_bytecap_c_(size) | |
| 568 | #define _Out_bytecap_post_bytecount_(cap,count) | |
| 569 | #define _Out_bytecap_x_(size) | |
| 570 | #define _Out_bytecapcount_(capcount) | |
| 571 | #define _Out_bytecapcount_x_(capcount) | |
| 572 | #define _Out_cap_(size) | |
| 573 | #define _Out_cap_c_(size) | |
| 574 | #define _Out_cap_m_(mult,size) | |
| 575 | #define _Out_cap_post_count_(cap,count) | |
| 576 | #define _Out_cap_x_(size) | |
| 577 | #define _Out_capcount_(capcount) | |
| 578 | #define _Out_capcount_x_(capcount) | |
| 579 | #define _Out_defensive_(annotes) | |
| 580 | #define _Out_opt_ | |
| 581 | #define _Out_opt_bytecap_(size) | |
| 582 | #define _Out_opt_bytecap_c_(size) | |
| 583 | #define _Out_opt_bytecap_post_bytecount_(cap,count) | |
| 584 | #define _Out_opt_bytecap_x_(size) | |
| 585 | #define _Out_opt_bytecapcount_(capcount) | |
| 586 | #define _Out_opt_bytecapcount_x_(capcount) | |
| 587 | #define _Out_opt_cap_(size) | |
| 588 | #define _Out_opt_cap_c_(size) | |
| 589 | #define _Out_opt_cap_m_(mult,size) | |
| 590 | #define _Out_opt_cap_post_count_(cap,count) | |
| 591 | #define _Out_opt_cap_x_(size) | |
| 592 | #define _Out_opt_capcount_(capcount) | |
| 593 | #define _Out_opt_capcount_x_(capcount) | |
| 594 | #define _Out_opt_ptrdiff_cap_(size) | |
| 595 | #define _Out_opt_z_bytecap_(size) | |
| 596 | #define _Out_opt_z_bytecap_c_(size) | |
| 597 | #define _Out_opt_z_bytecap_post_bytecount_(cap,count) | |
| 598 | #define _Out_opt_z_bytecap_x_(size) | |
| 599 | #define _Out_opt_z_bytecapcount_(capcount) | |
| 600 | #define _Out_opt_z_cap_(size) | |
| 601 | #define _Out_opt_z_cap_c_(size) | |
| 602 | #define _Out_opt_z_cap_m_(mult,size) | |
| 603 | #define _Out_opt_z_cap_post_count_(cap,count) | |
| 604 | #define _Out_opt_z_cap_x_(size) | |
| 605 | #define _Out_opt_z_capcount_(capcount) | |
| 606 | #define _Out_ptrdiff_cap_(size) | |
| 607 | #define _Out_range_(lb,ub) | |
| 608 | #define _Out_writes_(size) | |
| 609 | #define _Out_writes_all_(size) | |
| 610 | #define _Out_writes_all_opt_(size) | |
| 611 | #define _Out_writes_bytes_(size) | |
| 612 | #define _Out_writes_bytes_all_(size) | |
| 613 | #define _Out_writes_bytes_all_opt_(size) | |
| 614 | #define _Out_writes_bytes_opt_(size) | |
| 615 | #define _Out_writes_bytes_to_(size,count) | |
| 616 | #define _Out_writes_bytes_to_opt_(size,count) | |
| 617 | #define _Out_writes_opt_(size) | |
| 618 | #define _Out_writes_opt_z_(size) | |
| 619 | #define _Out_writes_to_(size,count) | |
| 620 | #define _Out_writes_to_opt_(size,count) | |
| 621 | #define _Out_writes_to_ptr_(ptr) | |
| 622 | #define _Out_writes_to_ptr_opt_(ptr) | |
| 623 | #define _Out_writes_to_ptr_opt_z_(ptr) | |
| 624 | #define _Out_writes_to_ptr_z_(ptr) | |
| 625 | #define _Out_writes_z_(size) | |
| 626 | #define _Out_z_bytecap_(size) | |
| 627 | #define _Out_z_bytecap_c_(size) | |
| 628 | #define _Out_z_bytecap_post_bytecount_(cap,count) | |
| 629 | #define _Out_z_bytecap_x_(size) | |
| 630 | #define _Out_z_bytecapcount_(capcount) | |
| 631 | #define _Out_z_cap_(size) | |
| 632 | #define _Out_z_cap_c_(size) | |
| 633 | #define _Out_z_cap_m_(mult,size) | |
| 634 | #define _Out_z_cap_post_count_(cap,count) | |
| 635 | #define _Out_z_cap_x_(size) | |
| 636 | #define _Out_z_capcount_(capcount) | |
| 637 | #define _Outptr_ | |
| 638 | #define _Outptr_opt_ | |
| 639 | #define _Outptr_opt_result_buffer_(size) | |
| 640 | #define _Outptr_opt_result_buffer_all_(size) | |
| 641 | #define _Outptr_opt_result_buffer_all_maybenull_(size) | |
| 642 | #define _Outptr_opt_result_buffer_maybenull_(size) | |
| 643 | #define _Outptr_opt_result_buffer_to_(size, count) | |
| 644 | #define _Outptr_opt_result_buffer_to_maybenull_(size, count) | |
| 645 | #define _Outptr_opt_result_bytebuffer_(size) | |
| 646 | #define _Outptr_opt_result_bytebuffer_all_(size) | |
| 647 | #define _Outptr_opt_result_bytebuffer_all_maybenull_(size) | |
| 648 | #define _Outptr_opt_result_bytebuffer_maybenull_(size) | |
| 649 | #define _Outptr_opt_result_bytebuffer_to_(size, count) | |
| 650 | #define _Outptr_opt_result_bytebuffer_to_maybenull_(size, count) | |
| 651 | #define _Outptr_opt_result_maybenull_ | |
| 652 | #define _Outptr_opt_result_maybenull_z_ | |
| 653 | #define _Outptr_opt_result_nullonfailure_ | |
| 654 | #define _Outptr_opt_result_z_ | |
| 655 | #define _Outptr_result_buffer_(size) | |
| 656 | #define _Outptr_result_buffer_all_(size) | |
| 657 | #define _Outptr_result_buffer_all_maybenull_(size) | |
| 658 | #define _Outptr_result_buffer_maybenull_(size) | |
| 659 | #define _Outptr_result_buffer_to_(size, count) | |
| 660 | #define _Outptr_result_buffer_to_maybenull_(size, count) | |
| 661 | #define _Outptr_result_bytebuffer_(size) | |
| 662 | #define _Outptr_result_bytebuffer_all_(size) | |
| 663 | #define _Outptr_result_bytebuffer_all_maybenull_(size) | |
| 664 | #define _Outptr_result_bytebuffer_maybenull_(size) | |
| 665 | #define _Outptr_result_bytebuffer_to_(size, count) | |
| 666 | #define _Outptr_result_bytebuffer_to_maybenull_(size, count) | |
| 667 | #define _Outptr_result_maybenull_ | |
| 668 | #define _Outptr_result_maybenull_z_ | |
| 669 | #define _Outptr_result_nullonfailure_ | |
| 670 | #define _Outptr_result_z_ | |
| 671 | #define _Outref_ | |
| 672 | #define _Outref_result_buffer_(size) | |
| 673 | #define _Outref_result_buffer_all_(size) | |
| 674 | #define _Outref_result_buffer_all_maybenull_(size) | |
| 675 | #define _Outref_result_buffer_maybenull_(size) | |
| 676 | #define _Outref_result_buffer_to_(size, count) | |
| 677 | #define _Outref_result_buffer_to_maybenull_(size, count) | |
| 678 | #define _Outref_result_bytebuffer_(size) | |
| 679 | #define _Outref_result_bytebuffer_all_(size) | |
| 680 | #define _Outref_result_bytebuffer_all_maybenull_(size) | |
| 681 | #define _Outref_result_bytebuffer_maybenull_(size) | |
| 682 | #define _Outref_result_bytebuffer_to_(size, count) | |
| 683 | #define _Outref_result_bytebuffer_to_maybenull_(size, count) | |
| 684 | #define _Outref_result_maybenull_ | |
| 685 | #define _Outref_result_nullonfailure_ | |
| 686 | #define _Points_to_data_ | |
| 687 | #define _Post_ | |
| 688 | #define _Post_bytecap_(size) | |
| 689 | #define _Post_bytecount_(size) | |
| 690 | #define _Post_bytecount_c_(size) | |
| 691 | #define _Post_bytecount_x_(size) | |
| 692 | #define _Post_cap_(size) | |
| 693 | #define _Post_count_(size) | |
| 694 | #define _Post_count_c_(size) | |
| 695 | #define _Post_count_x_(size) | |
| 696 | #define _Post_defensive_ | |
| 697 | #define _Post_equal_to_(expr) | |
| 698 | #define _Post_invalid_ | |
| 699 | #define _Post_maybenull_ | |
| 700 | #define _Post_maybez_ | |
| 701 | #define _Post_notnull_ | |
| 702 | #define _Post_null_ | |
| 703 | #define _Post_ptr_invalid_ | |
| 704 | #define _Post_readable_byte_size_(size) | |
| 705 | #define _Post_readable_size_(size) | |
| 706 | #define _Post_satisfies_(cond) | |
| 707 | #define _Post_valid_ | |
| 708 | #define _Post_writable_byte_size_(size) | |
| 709 | #define _Post_writable_size_(size) | |
| 710 | #define _Post_z_ | |
| 711 | #define _Post_z_bytecount_(size) | |
| 712 | #define _Post_z_bytecount_c_(size) | |
| 713 | #define _Post_z_bytecount_x_(size) | |
| 714 | #define _Post_z_count_(size) | |
| 715 | #define _Post_z_count_c_(size) | |
| 716 | #define _Post_z_count_x_(size) | |
| 717 | #define _Pre_ | |
| 718 | #define _Pre_bytecap_(size) | |
| 719 | #define _Pre_bytecap_c_(size) | |
| 720 | #define _Pre_bytecap_x_(size) | |
| 721 | #define _Pre_bytecount_(size) | |
| 722 | #define _Pre_bytecount_c_(size) | |
| 723 | #define _Pre_bytecount_x_(size) | |
| 724 | #define _Pre_cap_(size) | |
| 725 | #define _Pre_cap_c_(size) | |
| 726 | #define _Pre_cap_c_one_ | |
| 727 | #define _Pre_cap_for_(param) | |
| 728 | #define _Pre_cap_m_(mult,size) | |
| 729 | #define _Pre_cap_x_(size) | |
| 730 | #define _Pre_count_(size) | |
| 731 | #define _Pre_count_c_(size) | |
| 732 | #define _Pre_count_x_(size) | |
| 733 | #define _Pre_defensive_ | |
| 734 | #define _Pre_equal_to_(expr) | |
| 735 | #define _Pre_invalid_ | |
| 736 | #define _Pre_maybenull_ | |
| 737 | #define _Pre_notnull_ | |
| 738 | #define _Pre_null_ | |
| 739 | #define _Pre_opt_bytecap_(size) | |
| 740 | #define _Pre_opt_bytecap_c_(size) | |
| 741 | #define _Pre_opt_bytecap_x_(size) | |
| 742 | #define _Pre_opt_bytecount_(size) | |
| 743 | #define _Pre_opt_bytecount_c_(size) | |
| 744 | #define _Pre_opt_bytecount_x_(size) | |
| 745 | #define _Pre_opt_cap_(size) | |
| 746 | #define _Pre_opt_cap_c_(size) | |
| 747 | #define _Pre_opt_cap_c_one_ | |
| 748 | #define _Pre_opt_cap_for_(param) | |
| 749 | #define _Pre_opt_cap_m_(mult,size) | |
| 750 | #define _Pre_opt_cap_x_(size) | |
| 751 | #define _Pre_opt_count_(size) | |
| 752 | #define _Pre_opt_count_c_(size) | |
| 753 | #define _Pre_opt_count_x_(size) | |
| 754 | #define _Pre_opt_ptrdiff_cap_(ptr) | |
| 755 | #define _Pre_opt_ptrdiff_count_(ptr) | |
| 756 | #define _Pre_opt_valid_ | |
| 757 | #define _Pre_opt_valid_bytecap_(size) | |
| 758 | #define _Pre_opt_valid_bytecap_c_(size) | |
| 759 | #define _Pre_opt_valid_bytecap_x_(size) | |
| 760 | #define _Pre_opt_valid_cap_(size) | |
| 761 | #define _Pre_opt_valid_cap_c_(size) | |
| 762 | #define _Pre_opt_valid_cap_x_(size) | |
| 763 | #define _Pre_opt_z_ | |
| 764 | #define _Pre_opt_z_bytecap_(size) | |
| 765 | #define _Pre_opt_z_bytecap_c_(size) | |
| 766 | #define _Pre_opt_z_bytecap_x_(size) | |
| 767 | #define _Pre_opt_z_cap_(size) | |
| 768 | #define _Pre_opt_z_cap_c_(size) | |
| 769 | #define _Pre_opt_z_cap_x_(size) | |
| 770 | #define _Pre_ptrdiff_cap_(ptr) | |
| 771 | #define _Pre_ptrdiff_count_(ptr) | |
| 772 | #define _Pre_readable_byte_size_(size) | |
| 773 | #define _Pre_readable_size_(size) | |
| 774 | #define _Pre_readonly_ | |
| 775 | #define _Pre_satisfies_(cond) | |
| 776 | #define _Pre_valid_ | |
| 777 | #define _Pre_valid_bytecap_(size) | |
| 778 | #define _Pre_valid_bytecap_c_(size) | |
| 779 | #define _Pre_valid_bytecap_x_(size) | |
| 780 | #define _Pre_valid_cap_(size) | |
| 781 | #define _Pre_valid_cap_c_(size) | |
| 782 | #define _Pre_valid_cap_x_(size) | |
| 783 | #define _Pre_writable_byte_size_(size) | |
| 784 | #define _Pre_writable_size_(size) | |
| 785 | #define _Pre_writeonly_ | |
| 786 | #define _Pre_z_ | |
| 787 | #define _Pre_z_bytecap_(size) | |
| 788 | #define _Pre_z_bytecap_c_(size) | |
| 789 | #define _Pre_z_bytecap_x_(size) | |
| 790 | #define _Pre_z_cap_(size) | |
| 791 | #define _Pre_z_cap_c_(size) | |
| 792 | #define _Pre_z_cap_x_(size) | |
| 793 | #define _Prepost_bytecount_(size) | |
| 794 | #define _Prepost_bytecount_c_(size) | |
| 795 | #define _Prepost_bytecount_x_(size) | |
| 796 | #define _Prepost_count_(size) | |
| 797 | #define _Prepost_count_c_(size) | |
| 798 | #define _Prepost_count_x_(size) | |
| 799 | #define _Prepost_opt_bytecount_(size) | |
| 800 | #define _Prepost_opt_bytecount_c_(size) | |
| 801 | #define _Prepost_opt_bytecount_x_(size) | |
| 802 | #define _Prepost_opt_count_(size) | |
| 803 | #define _Prepost_opt_count_c_(size) | |
| 804 | #define _Prepost_opt_count_x_(size) | |
| 805 | #define _Prepost_opt_valid_ | |
| 806 | #define _Prepost_opt_z_ | |
| 807 | #define _Prepost_valid_ | |
| 808 | #define _Prepost_z_ | |
| 809 | #define _Printf_format_string_ | |
| 810 | #define _Raises_SEH_exception_ | |
| 811 | #define _Readable_bytes_(size) | |
| 812 | #define _Readable_elements_(size) | |
| 813 | #define _Reserved_ | |
| 814 | #define _Result_nullonfailure_ | |
| 815 | #define _Result_zeroonfailure_ | |
| 816 | #define _Ret_ | |
| 817 | #define _Ret_bound_ | |
| 818 | #define _Ret_bytecap_(size) | |
| 819 | #define _Ret_bytecap_c_(size) | |
| 820 | #define _Ret_bytecap_x_(size) | |
| 821 | #define _Ret_bytecount_(size) | |
| 822 | #define _Ret_bytecount_c_(size) | |
| 823 | #define _Ret_bytecount_x_(size) | |
| 824 | #define _Ret_cap_(size) | |
| 825 | #define _Ret_cap_c_(size) | |
| 826 | #define _Ret_cap_x_(size) | |
| 827 | #define _Ret_count_(size) | |
| 828 | #define _Ret_count_c_(size) | |
| 829 | #define _Ret_count_x_(size) | |
| 830 | #define _Ret_maybenull_ | |
| 831 | #define _Ret_maybenull_z_ | |
| 832 | #define _Ret_notnull_ | |
| 833 | #define _Ret_null_ | |
| 834 | #define _Ret_opt_ | |
| 835 | #define _Ret_opt_bytecap_(size) | |
| 836 | #define _Ret_opt_bytecap_c_(size) | |
| 837 | #define _Ret_opt_bytecap_x_(size) | |
| 838 | #define _Ret_opt_bytecount_(size) | |
| 839 | #define _Ret_opt_bytecount_c_(size) | |
| 840 | #define _Ret_opt_bytecount_x_(size) | |
| 841 | #define _Ret_opt_cap_(size) | |
| 842 | #define _Ret_opt_cap_c_(size) | |
| 843 | #define _Ret_opt_cap_x_(size) | |
| 844 | #define _Ret_opt_count_(size) | |
| 845 | #define _Ret_opt_count_c_(size) | |
| 846 | #define _Ret_opt_count_x_(size) | |
| 847 | #define _Ret_opt_valid_ | |
| 848 | #define _Ret_opt_z_ | |
| 849 | #define _Ret_opt_z_bytecap_(size) | |
| 850 | #define _Ret_opt_z_bytecount_(size) | |
| 851 | #define _Ret_opt_z_cap_(size) | |
| 852 | #define _Ret_opt_z_count_(size) | |
| 853 | #define _Ret_range_(lb,ub) | |
| 854 | #define _Ret_valid_ | |
| 855 | #define _Ret_writes_(size) | |
| 856 | #define _Ret_writes_bytes_(size) | |
| 857 | #define _Ret_writes_bytes_maybenull_(size) | |
| 858 | #define _Ret_writes_bytes_to_(size,count) | |
| 859 | #define _Ret_writes_bytes_to_maybenull_(size,count) | |
| 860 | #define _Ret_writes_maybenull_(size) | |
| 861 | #define _Ret_writes_maybenull_z_(size) | |
| 862 | #define _Ret_writes_to_(size,count) | |
| 863 | #define _Ret_writes_to_maybenull_(size,count) | |
| 864 | #define _Ret_writes_z_(size) | |
| 865 | #define _Ret_z_ | |
| 866 | #define _Ret_z_bytecap_(size) | |
| 867 | #define _Ret_z_bytecount_(size) | |
| 868 | #define _Ret_z_cap_(size) | |
| 869 | #define _Ret_z_count_(size) | |
| 870 | #define _Return_type_success_(expr) | |
| 871 | #define _Scanf_format_string_ | |
| 872 | #define _Scanf_s_format_string_ | |
| 873 | #define _Struct_size_bytes_(size) | |
| 874 | #define _Success_(expr) | |
| 875 | #define _Unchanged_(e) | |
| 876 | #define _Use_decl_annotations_ | |
| 877 | #define _Valid_ | |
| 878 | #define _When_(expr, annos) | |
| 879 | #define _Writable_bytes_(size) | |
| 880 | #define _Writable_elements_(size) | |
| 881 | #define __inner_callback | |
| 882 | #define __inner_exceptthat | |
| 883 | #define __inner_typefix(ctype) | |
| 884 | ||
| 249 | 885 | #ifndef __fallthrough |
| 250 | 886 | # define __fallthrough __inner_fallthrough |
| 251 | 887 | #endif |
| r249195 | r249196 | |
|---|---|---|
| 1 | 1 | /*- |
| 2 | * Copyright 2012 Matthew Endsley | |
| 2 | * Copyright 2012-1015 Matthew Endsley | |
| 3 | 3 | * All rights reserved |
| 4 | 4 | * |
| 5 | 5 | * Redistribution and use in source and binary forms, with or without |
| r249195 | r249196 | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | template<typename T> |
| 58 | static inline void buffer_fill_urange_traits(T* first, T* last, pod_traits<T, false>) { | |
| 59 | for (; first < last; ++first) | |
| 60 | new(placeholder(), first) T(); | |
| 61 | } | |
| 62 | ||
| 63 | template<typename T> | |
| 64 | static inline void buffer_fill_urange_traits(T* first, T* last, pod_traits<T, true>) { | |
| 65 | for (; first < last; ++first) | |
| 66 | *first = T(); | |
| 67 | } | |
| 68 | ||
| 69 | template<typename T> | |
| 58 | 70 | static inline void buffer_fill_urange_traits(T* first, T* last, const T& value, pod_traits<T, false>) { |
| 59 | 71 | for (; first < last; ++first) |
| 60 | 72 | new(placeholder(), first) T(value); |
| r249195 | r249196 | |
| 106 | 118 | } |
| 107 | 119 | |
| 108 | 120 | template<typename T> |
| 121 | static inline void buffer_fill_urange(T* first, T* last) { | |
| 122 | buffer_fill_urange_traits(first, last, pod_traits<T>()); | |
| 123 | } | |
| 124 | ||
| 125 | template<typename T> | |
| 109 | 126 | static inline void buffer_fill_urange(T* first, T* last, const T& value) { |
| 110 | 127 | buffer_fill_urange_traits(first, last, value, pod_traits<T>()); |
| 111 | 128 | } |
| r249195 | r249196 | |
| 138 | 155 | } |
| 139 | 156 | |
| 140 | 157 | template<typename T, typename Alloc> |
| 158 | static inline void buffer_resize(buffer<T, Alloc>* b, size_t size) { | |
| 159 | buffer_reserve(b, size); | |
| 160 | ||
| 161 | buffer_fill_urange(b->last, b->first + size); | |
| 162 | buffer_destroy_range(b->first + size, b->last); | |
| 163 | b->last = b->first + size; | |
| 164 | } | |
| 165 | ||
| 166 | template<typename T, typename Alloc> | |
| 141 | 167 | static inline void buffer_resize(buffer<T, Alloc>* b, size_t size, const T& value) { |
| 142 | 168 | buffer_reserve(b, size); |
| 143 | 169 | |
| r249195 | r249196 | |
| 169 | 195 | } |
| 170 | 196 | |
| 171 | 197 | template<typename T, typename Alloc> |
| 172 | static inline | |
| 198 | static inline T* buffer_insert_common(buffer<T, Alloc>* b, T* where, size_t count) { | |
| 173 | 199 | const size_t offset = (size_t)(where - b->first); |
| 174 | const size_t newsize = (size_t)((b->last - b->first) + | |
| 200 | const size_t newsize = (size_t)((b->last - b->first) + count); | |
| 175 | 201 | if (b->first + newsize > b->capacity) |
| 176 | 202 | buffer_reserve(b, (newsize * 3) / 2); |
| 177 | 203 | |
| 178 | 204 | where = b->first + offset; |
| 179 | const size_t count = (size_t)(last - first); | |
| 180 | 205 | |
| 181 | 206 | if (where != b->last) |
| 182 | 207 | buffer_bmove_urange(where + count, where, b->last); |
| 183 | 208 | |
| 209 | b->last = b->first + newsize; | |
| 210 | ||
| 211 | return where; | |
| 212 | } | |
| 213 | ||
| 214 | template<typename T, typename Alloc, typename Param> | |
| 215 | static inline void buffer_insert(buffer<T, Alloc>* b, T* where, const Param* first, const Param* last) { | |
| 216 | where = buffer_insert_common(b, where, last - first); | |
| 184 | 217 | for (; first != last; ++first, ++where) |
| 185 | 218 | new(placeholder(), where) T(*first); |
| 219 | } | |
| 186 | 220 | |
| 187 | b->last = b->first + newsize; | |
| 221 | template<typename T, typename Alloc> | |
| 222 | static inline void buffer_insert(buffer<T, Alloc>* b, T* where, size_t count) { | |
| 223 | where = buffer_insert_common(b, where, count); | |
| 224 | for (size_t i = 0; i < count; ++i) | |
| 225 | new(placeholder(), where) T(); | |
| 188 | 226 | } |
| 189 | 227 | |
| 190 | 228 | template<typename T, typename Alloc> |
| r249195 | r249196 | |
|---|---|---|
| 1 | 1 | /*- |
| 2 | * Copyright 2012 Matthew Endsley | |
| 2 | * Copyright 2012-1015 Matthew Endsley | |
| 3 | 3 | * All rights reserved |
| 4 | 4 | * |
| 5 | 5 | * Redistribution and use in source and binary forms, with or without |
| r249195 | r249196 | |
| 56 | 56 | T& operator[](size_t idx); |
| 57 | 57 | const T& operator[](size_t idx) const; |
| 58 | 58 | |
| 59 | const T& front() const; | |
| 60 | T& front(); | |
| 59 | 61 | const T& back() const; |
| 60 | 62 | T& back(); |
| 61 | 63 | |
| r249195 | r249196 | |
| 67 | 69 | void push_back(const T& t); |
| 68 | 70 | void pop_back(); |
| 69 | 71 | |
| 72 | void emplace_back(); | |
| 73 | template<typename Param> | |
| 74 | void emplace_back(const Param& param); | |
| 75 | ||
| 70 | 76 | void shrink_to_fit(); |
| 71 | 77 | |
| 72 | 78 | void swap(vector& other); |
| r249195 | r249196 | |
| 81 | 87 | const_iterator begin() const; |
| 82 | 88 | const_iterator end() const; |
| 83 | 89 | |
| 90 | void insert(iterator where); | |
| 84 | 91 | void insert(iterator where, const T& value); |
| 85 | 92 | void insert(iterator where, const T* first, const T* last); |
| 86 | 93 | |
| 94 | template<typename Param> | |
| 95 | void emplace(iterator where, const Param& param); | |
| 96 | ||
| 87 | 97 | iterator erase(iterator where); |
| 88 | 98 | iterator erase(iterator first, iterator last); |
| 89 | 99 | |
| r249195 | r249196 | |
| 109 | 119 | template<typename T, typename Alloc> |
| 110 | 120 | inline vector<T, Alloc>::vector(size_t _size) { |
| 111 | 121 | buffer_init(&m_buffer); |
| 112 | buffer_resize(&m_buffer, _size | |
| 122 | buffer_resize(&m_buffer, _size); | |
| 113 | 123 | } |
| 114 | 124 | |
| 115 | 125 | template<typename T, typename Alloc> |
| r249195 | r249196 | |
| 177 | 187 | } |
| 178 | 188 | |
| 179 | 189 | template<typename T, typename Alloc> |
| 190 | inline const T& vector<T, Alloc>::front() const { | |
| 191 | return m_buffer.first[0]; | |
| 192 | } | |
| 193 | ||
| 194 | template<typename T, typename Alloc> | |
| 195 | inline T& vector<T, Alloc>::front() { | |
| 196 | return m_buffer.first[0]; | |
| 197 | } | |
| 198 | ||
| 199 | template<typename T, typename Alloc> | |
| 180 | 200 | inline const T& vector<T, Alloc>::back() const { |
| 181 | 201 | return m_buffer.last[-1]; |
| 182 | 202 | } |
| r249195 | r249196 | |
| 188 | 208 | |
| 189 | 209 | template<typename T, typename Alloc> |
| 190 | 210 | inline void vector<T, Alloc>::resize(size_t _size) { |
| 191 | buffer_resize(&m_buffer, _size | |
| 211 | buffer_resize(&m_buffer, _size); | |
| 192 | 212 | } |
| 193 | 213 | |
| 194 | 214 | template<typename T, typename Alloc> |
| r249195 | r249196 | |
| 212 | 232 | } |
| 213 | 233 | |
| 214 | 234 | template<typename T, typename Alloc> |
| 235 | inline void vector<T, Alloc>::emplace_back() | |
| 236 | { | |
| 237 | buffer_insert(&m_buffer, m_buffer.last, 1); | |
| 238 | } | |
| 239 | ||
| 240 | template<typename T, typename Alloc> | |
| 241 | template<typename Param> | |
| 242 | inline void vector<T, Alloc>::emplace_back(const Param& param) | |
| 243 | { | |
| 244 | buffer_insert(&m_buffer, m_buffer.last, ¶m, ¶m + 1); | |
| 245 | } | |
| 246 | ||
| 247 | template<typename T, typename Alloc> | |
| 215 | 248 | inline void vector<T, Alloc>::pop_back() { |
| 216 | 249 | buffer_erase(&m_buffer, m_buffer.last - 1, m_buffer.last); |
| 217 | 250 | } |
| r249195 | r249196 | |
| 247 | 280 | } |
| 248 | 281 | |
| 249 | 282 | template<typename T, typename Alloc> |
| 283 | inline void vector<T, Alloc>::insert(iterator where) { | |
| 284 | buffer_insert(&m_buffer, where, 1); | |
| 285 | } | |
| 286 | ||
| 287 | template<typename T, typename Alloc> | |
| 250 | 288 | inline void vector<T, Alloc>::insert(iterator where, const T& value) { |
| 251 | 289 | buffer_insert(&m_buffer, where, &value, &value + 1); |
| 252 | 290 | } |
| r249195 | r249196 | |
| 275 | 313 | inline typename vector<T, Alloc>::iterator vector<T, Alloc>::erase_unordered(iterator first, iterator last) { |
| 276 | 314 | return buffer_erase_unordered(&m_buffer, first, last); |
| 277 | 315 | } |
| 316 | ||
| 317 | template<typename T, typename Alloc> | |
| 318 | template<typename Param> | |
| 319 | void vector<T, Alloc>::emplace(iterator where, const Param& param) { | |
| 320 | buffer_insert(&m_buffer, where, ¶m, ¶m + 1); | |
| 321 | } | |
| 278 | 322 | } |
| 279 | 323 | |
| 280 | 324 | #endif |
| r249195 | r249196 | |
|---|---|---|
| 36 | 36 | dofile "bin2c.lua" |
| 37 | 37 | |
| 38 | 38 | project "bx.test" |
| 39 | uuid "8a653da8-23d6-11e3-acb4-887628d43830" | |
| 40 | 39 | kind "ConsoleApp" |
| 41 | 40 | |
| 42 | 41 | debugdir (path.join(BX_DIR, "tests")) |
| r249195 | r249196 | |
|---|---|---|
| 29 | 29 | { "nacl-arm", "Native Client - ARM" }, |
| 30 | 30 | { "osx", "OSX" }, |
| 31 | 31 | { "pnacl", "Native Client - PNaCl" }, |
| 32 | { "ps4", "PS4" }, | |
| 32 | 33 | { "qnx-arm", "QNX/Blackberry - ARM" }, |
| 33 | 34 | { "rpi", "RaspberryPi" }, |
| 34 | 35 | }, |
| r249195 | r249196 | |
| 39 | 40 | value = "toolset", |
| 40 | 41 | description = "Choose VS toolset", |
| 41 | 42 | allowed = { |
| 42 | { "vs2012-clang", "Clang 3.6" }, | |
| 43 | { "vs2013-clang", "Clang 3.6" }, | |
| 43 | { "vs2012-clang", "Clang 3.6" }, | |
| 44 | { "vs2013-clang", "Clang 3.6" }, | |
| 44 | 45 | { "vs2012-xp", "Visual Studio 2012 targeting XP" }, |
| 45 | 46 | { "vs2013-xp", "Visual Studio 2013 targeting XP" }, |
| 46 | 47 | { "vs2015-xp", "Visual Studio 2015 targeting XP" }, |
| 47 | { "winphone8", "Windows Phone 8.0" }, | |
| 48 | { "winphone81", "Windows Phone 8.1" }, | |
| 49 | { "winstore81", "Windows Store 8.1" }, | |
| 50 | { "winstore82", "Universal Windows App" } | |
| 48 | { "winphone8", "Windows Phone 8.0" }, | |
| 49 | { "winphone81", "Windows Phone 8.1" }, | |
| 50 | { "winstore81", "Windows Store 8.1" }, | |
| 51 | { "winstore82", "Universal Windows App" }, | |
| 51 | 52 | }, |
| 52 | 53 | } |
| 53 | 54 | |
| r249195 | r249196 | |
| 257 | 258 | premake.gcc.ar = naclToolchain .. "ar" |
| 258 | 259 | location (path.join(_buildDir, "projects", _ACTION .. "-pnacl")) |
| 259 | 260 | |
| 261 | elseif "ps4" == _OPTIONS["gcc"] then | |
| 262 | ||
| 263 | if not os.getenv("PS4_SDK_ROOT") then | |
| 264 | print("Set PS4_SDK_ROOT enviroment variables.") | |
| 265 | end | |
| 266 | ||
| 267 | ps4Toolchain = "$(PS4_SDK_ROOT)/host_tools/bin/orbis-" | |
| 268 | ||
| 269 | premake.gcc.cc = ps4Toolchain .. "clang" | |
| 270 | premake.gcc.cxx = ps4Toolchain .. "clang++" | |
| 271 | premake.gcc.ar = ps4Toolchain .. "ar" | |
| 272 | location (path.join(_buildDir, "projects", _ACTION .. "-ps4")) | |
| 273 | ||
| 260 | 274 | elseif "qnx-arm" == _OPTIONS["gcc"] then |
| 261 | 275 | |
| 262 | 276 | if not os.getenv("QNX_HOST") then |
| r249195 | r249196 | |
| 799 | 813 | "-m64", |
| 800 | 814 | } |
| 801 | 815 | |
| 816 | configuration { "osx", "Universal" } | |
| 817 | targetdir (path.join(_buildDir, "osx_universal/bin")) | |
| 818 | objdir (path.join(_buildDir, "osx_universal/bin")) | |
| 819 | ||
| 802 | 820 | configuration { "osx" } |
| 803 | 821 | buildoptions { |
| 804 | 822 | "-Wfatal-errors", |
| r249195 | r249196 | |
| 855 | 873 | "--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator" ..iosPlatform .. ".sdk", |
| 856 | 874 | } |
| 857 | 875 | |
| 876 | configuration { "ps4" } | |
| 877 | targetdir (path.join(_buildDir, "ps4/bin")) | |
| 878 | objdir (path.join(_buildDir, "ps4/obj")) | |
| 879 | libdirs { path.join(_libDir, "lib/ps4") } | |
| 880 | includedirs { | |
| 881 | path.join(bxDir, "include/compat/freebsd"), | |
| 882 | "$(PS4_SDK_ROOT)/target/include", | |
| 883 | "$(PS4_SDK_ROOT)/target/include_common", | |
| 884 | } | |
| 885 | buildoptions { | |
| 886 | } | |
| 887 | buildoptions_cpp { | |
| 888 | "-std=c++0x", | |
| 889 | } | |
| 890 | linkoptions { | |
| 891 | } | |
| 892 | ||
| 858 | 893 | configuration { "qnx-arm" } |
| 859 | 894 | targetdir (path.join(_buildDir, "qnx-arm/bin")) |
| 860 | 895 | objdir (path.join(_buildDir, "qnx-arm/obj")) |
| r249195 | r249196 | |
| 951 | 986 | configuration { "asmjs" } |
| 952 | 987 | postbuildcommands { |
| 953 | 988 | "$(SILENT) echo Running asmjs finalize.", |
| 954 | "$(SILENT) $(EMSCRIPTEN)/emcc -O2 -s TOTAL_MEMORY=268435456 \"$(TARGET)\" -o \"$(TARGET)\".html" | |
| 955 | -- ALLOW_MEMORY_GROWTH | |
| 989 | "$(SILENT) $(EMSCRIPTEN)/emcc -O2 " | |
| 990 | -- .. "-s EMTERPRETIFY=1 " | |
| 991 | -- .. "-s EMTERPRETIFY_ASYNC=1 " | |
| 992 | .. "-s TOTAL_MEMORY=268435456 " | |
| 993 | -- .. "-s ALLOW_MEMORY_GROWTH=1 " | |
| 994 | .. "--memory-init-file 1 " | |
| 995 | .. "\"$(TARGET)\" -o \"$(TARGET)\".html " | |
| 996 | -- .. "--preload-file ../../../examples/runtime@/" | |
| 956 | 997 | } |
| 957 | 998 | |
| 958 | 999 | configuration {} -- reset configuration |
| r249195 | r249196 | |
|---|---|---|
| 4 | 4 | -- |
| 5 | 5 | |
| 6 | 6 | project "UnitTest++" |
| 7 | uuid "ab932f5c-2409-11e3-b000-887628d43830" | |
| 8 | 7 | kind "StaticLib" |
| 9 | 8 | |
| 10 | 9 | removeflags { |
| r249195 | r249196 | |
| 16 | 15 | "../3rdparty/UnitTest++/src/*.h", |
| 17 | 16 | } |
| 18 | 17 | |
| 19 | configuration { "linux or osx or android-* or *nacl*" } | |
| 18 | configuration { "linux or osx or android-* or *nacl* or ps4" } | |
| 20 | 19 | files { |
| 21 | 20 | "../3rdparty/UnitTest++/src/Posix/**.cpp", |
| 22 | 21 | "../3rdparty/UnitTest++/src/Posix/**.h", |
| r0 | r249196 | |
|---|---|---|
| 1 | /* | |
| 2 | * Copyright 2010-2015 Branimir Karadzic. All rights reserved. | |
| 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause | |
| 4 | */ | |
| 5 | ||
| 6 | #include "test.h" | |
| 7 | #include <bx/handlealloc.h> | |
| 8 | ||
| 9 | TEST(HandleListT) | |
| 10 | { | |
| 11 | bx::HandleListT<32> list; | |
| 12 | ||
| 13 | list.pushBack(16); | |
| 14 | CHECK(list.getFront() == 16); | |
| 15 | CHECK(list.getBack() == 16); | |
| 16 | ||
| 17 | list.pushFront(7); | |
| 18 | CHECK(list.getFront() == 7); | |
| 19 | CHECK(list.getBack() == 16); | |
| 20 | ||
| 21 | uint16_t expected0[] = { 15, 31, 7, 16, 17, 11, 13 }; | |
| 22 | list.pushBack(17); | |
| 23 | list.pushBack(11); | |
| 24 | list.pushBack(13); | |
| 25 | list.pushFront(31); | |
| 26 | list.pushFront(15); | |
| 27 | uint16_t count = 0; | |
| 28 | for (uint16_t it = list.getFront(); it != UINT16_MAX; it = list.getNext(it), ++count) | |
| 29 | { | |
| 30 | CHECK(it == expected0[count]); | |
| 31 | } | |
| 32 | CHECK(count == BX_COUNTOF(expected0) ); | |
| 33 | ||
| 34 | list.remove(17); | |
| 35 | list.remove(31); | |
| 36 | list.remove(16); | |
| 37 | list.pushBack(16); | |
| 38 | uint16_t expected1[] = { 15, 7, 11, 13, 16 }; | |
| 39 | count = 0; | |
| 40 | for (uint16_t it = list.getFront(); it != UINT16_MAX; it = list.getNext(it), ++count) | |
| 41 | { | |
| 42 | CHECK(it == expected1[count]); | |
| 43 | } | |
| 44 | CHECK(count == BX_COUNTOF(expected1) ); | |
| 45 | ||
| 46 | list.popBack(); | |
| 47 | list.popFront(); | |
| 48 | list.popBack(); | |
| 49 | list.popBack(); | |
| 50 | ||
| 51 | CHECK(list.getFront() == 7); | |
| 52 | CHECK(list.getBack() == 7); | |
| 53 | ||
| 54 | list.popBack(); | |
| 55 | CHECK(list.getFront() == UINT16_MAX); | |
| 56 | CHECK(list.getBack() == UINT16_MAX); | |
| 57 | } | |
| 58 | ||
| 59 | TEST(HandleAllocLruT) | |
| 60 | { | |
| 61 | bx::HandleAllocLruT<16> lru; | |
| 62 | ||
| 63 | uint16_t handle[4] = | |
| 64 | { | |
| 65 | lru.alloc(), | |
| 66 | lru.alloc(), | |
| 67 | lru.alloc(), | |
| 68 | lru.alloc(), | |
| 69 | }; | |
| 70 | ||
| 71 | lru.touch(handle[1]); | |
| 72 | ||
| 73 | uint16_t expected0[] = { handle[1], handle[3], handle[2], handle[0] }; | |
| 74 | uint16_t count = 0; | |
| 75 | for (uint16_t it = lru.getFront(); it != UINT16_MAX; it = lru.getNext(it), ++count) | |
| 76 | { | |
| 77 | CHECK(it == expected0[count]); | |
| 78 | } | |
| 79 | } |
| r0 | r249196 | |
|---|---|---|
| 1 | #include "test.h" | |
| 2 | #include <bx/os.h> | |
| 3 | ||
| 4 | TEST(getProcessMemoryUsed) | |
| 5 | { | |
| 6 | CHECK(0 != bx::getProcessMemoryUsed() ); | |
| 7 | // DBG("bx::getProcessMemoryUsed %d", bx::getProcessMemoryUsed() ); | |
| 8 | } |
| r249195 | r249196 | |
|---|---|---|
| 20 | 20 | CHECK(48 == bx::strideAlign16(ii+1, 12) ); |
| 21 | 21 | } |
| 22 | 22 | } |
| 23 | ||
| 24 | TEST(uint32_cnt) | |
| 25 | { | |
| 26 | CHECK( 0 == bx::uint32_cnttz(UINT32_C(1) ) ); | |
| 27 | CHECK( 0 == bx::uint32_cnttz_ref(UINT32_C(1) ) ); | |
| 28 | ||
| 29 | CHECK(31 == bx::uint32_cntlz(UINT32_C(1) ) ); | |
| 30 | CHECK(31 == bx::uint32_cntlz_ref(UINT32_C(1) ) ); | |
| 31 | ||
| 32 | CHECK( 0 == bx::uint64_cnttz(UINT64_C(1) ) ); | |
| 33 | CHECK( 0 == bx::uint64_cnttz_ref(UINT64_C(1) ) ); | |
| 34 | ||
| 35 | CHECK(63 == bx::uint64_cntlz(UINT64_C(1) ) ); | |
| 36 | CHECK(63 == bx::uint64_cntlz_ref(UINT64_C(1) ) ); | |
| 37 | ||
| 38 | CHECK( 1 == bx::uint32_cntbits(1) ); | |
| 39 | CHECK( 1 == bx::uint32_cntbits_ref(1) ); | |
| 40 | ||
| 41 | CHECK(16 == bx::uint32_cntbits(UINT16_MAX) ); | |
| 42 | CHECK(16 == bx::uint32_cntbits_ref(UINT16_MAX) ); | |
| 43 | ||
| 44 | CHECK(32 == bx::uint32_cntbits(UINT32_MAX) ); | |
| 45 | CHECK(32 == bx::uint32_cntbits_ref(UINT32_MAX) ); | |
| 46 | } | |
| 47 | ||
| 48 | TEST(uint32_part) | |
| 49 | { | |
| 50 | CHECK(UINT32_C(0x55555555) == bx::uint32_part1by1(UINT16_MAX) ); | |
| 51 | CHECK(UINT32_C(0x09249249) == bx::uint32_part1by2(0x3ff) ); | |
| 52 | } |
| r249195 | r249196 | |
|---|---|---|
| 1 | 1 | /*- |
| 2 | * Copyright 2012-201 | |
| 2 | * Copyright 2012-2015 Matthew Endsley | |
| 3 | 3 | * All rights reserved |
| 4 | 4 | * |
| 5 | 5 | * Redistribution and use in source and binary forms, with or without |
| r249195 | r249196 | |
| 29 | 29 | #include <tinystl/allocator.h> |
| 30 | 30 | #include <tinystl/unordered_map.h> |
| 31 | 31 | |
| 32 | struct Foo { int bar; }; | |
| 32 | namespace { | |
| 33 | struct Foo { int bar; }; | |
| 34 | } | |
| 33 | 35 | |
| 34 | 36 | TEST(uomap_nonpod_compiles) { |
| 35 | 37 |
| r249195 | r249196 | |
|---|---|---|
| 1 | 1 | /*- |
| 2 | * Copyright 2012 Matthew Endsley | |
| 2 | * Copyright 2012-1015 Matthew Endsley | |
| 3 | 3 | * All rights reserved |
| 4 | 4 | * |
| 5 | 5 | * Redistribution and use in source and binary forms, with or without |
| r249195 | r249196 | |
| 35 | 35 | |
| 36 | 36 | struct complex { |
| 37 | 37 | complex() {data = 0;} |
| 38 | complex(const char* s) { data = | |
| 38 | complex(const char* s) { data = strdup(s); } | |
| 39 | 39 | ~complex() { free(data); } |
| 40 | complex(const complex& other) { data = 0; if (other.data) data = | |
| 40 | complex(const complex& other) { data = 0; if (other.data) data = strdup(other.data); } | |
| 41 | 41 | complex& operator=(const complex& other) { complex(other).swap(*this); return *this; } |
| 42 | 42 | void swap(complex& other) { std::swap(data, other.data); } |
| 43 | 43 |
| r249195 | r249196 | |
|---|---|---|
| 1 | 1 | /*- |
| 2 | * Copyright 2012 Matthew Endsley | |
| 2 | * Copyright 2012-1015 Matthew Endsley | |
| 3 | 3 | * All rights reserved |
| 4 | 4 | * |
| 5 | 5 | * Redistribution and use in source and binary forms, with or without |
| r0 | r249196 | |
|---|---|---|
| 1 | /*- | |
| 2 | * Copyright 2012-1015 Matthew Endsley | |
| 3 | * All rights reserved | |
| 4 | * | |
| 5 | * Redistribution and use in source and binary forms, with or without | |
| 6 | * modification, are permitted providing that the following conditions | |
| 7 | * are met: | |
| 8 | * 1. Redistributions of source code must retain the above copyright | |
| 9 | * notice, this list of conditions and the following disclaimer. | |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 11 | * notice, this list of conditions and the following disclaimer in the | |
| 12 | * documentation and/or other materials provided with the distribution. | |
| 13 | * | |
| 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
| 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | |
| 18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
| 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
| 22 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
| 23 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 24 | * POSSIBILITY OF SUCH DAMAGE. | |
| 25 | */ | |
| 26 | ||
| 27 | #include "test.h" | |
| 28 | ||
| 29 | #include <tinystl/allocator.h> | |
| 30 | #include <tinystl/vector.h> | |
| 31 | ||
| 32 | #include <algorithm> | |
| 33 | #include <string.h> | |
| 34 | #include <stdlib.h> | |
| 35 | ||
| 36 | struct nocopy { | |
| 37 | nocopy() { data = 0; } | |
| 38 | explicit nocopy(const char* s) { data = s; } | |
| 39 | ~nocopy() { } | |
| 40 | void swap(nocopy& other) { std::swap(data, other.data); } | |
| 41 | void reset(const char* s) { data = s; } | |
| 42 | const char* release() { const char* ret = data; data = 0; return ret; } | |
| 43 | ||
| 44 | const char* data; | |
| 45 | ||
| 46 | private: | |
| 47 | nocopy(const nocopy& other); | |
| 48 | nocopy& operator=(const nocopy& other); | |
| 49 | }; | |
| 50 | ||
| 51 | static inline bool operator==(const nocopy& lhs, const char* rhs) { | |
| 52 | if (lhs.data == 0 && rhs == 0) | |
| 53 | return true; | |
| 54 | if (lhs.data != 0 && rhs != 0) | |
| 55 | return 0 == strcmp(lhs.data, rhs); | |
| 56 | return false; | |
| 57 | } | |
| 58 | ||
| 59 | static inline bool operator==(const nocopy& lhs, const nocopy& rhs) { | |
| 60 | if (lhs.data == 0 && rhs.data == 0) | |
| 61 | return true; | |
| 62 | if (lhs.data != 0 && rhs.data != 0) | |
| 63 | return 0 == strcmp(lhs.data, rhs.data); | |
| 64 | return false; | |
| 65 | } | |
| 66 | ||
| 67 | TEST(vector_nocopy_constructor) { | |
| 68 | typedef tinystl::vector<nocopy> vector; | |
| 69 | ||
| 70 | { | |
| 71 | vector v; | |
| 72 | CHECK( v.empty() ); | |
| 73 | CHECK( v.size() == 0 ); | |
| 74 | } | |
| 75 | { | |
| 76 | vector v(10); | |
| 77 | CHECK( v.size() == 10 ); | |
| 78 | for (tinystl::vector<nocopy>::iterator it = v.begin(); it != v.end(); ++it) { | |
| 79 | CHECK( it->data == 0 ); | |
| 80 | } | |
| 81 | } | |
| 82 | } | |
| 83 | ||
| 84 | TEST(vector_nocopy_pushback) { | |
| 85 | tinystl::vector<nocopy> v; | |
| 86 | v.emplace_back("42"); | |
| 87 | v.emplace_back(); | |
| 88 | v.back().reset("24"); | |
| 89 | ||
| 90 | CHECK( v.size() == 2 ); | |
| 91 | CHECK( v[0] == "42" ); | |
| 92 | CHECK( v[1] == "24" ); | |
| 93 | } | |
| 94 | ||
| 95 | TEST(vector_nocopy_vector) { | |
| 96 | tinystl::vector< tinystl::vector<nocopy> > v(10); | |
| 97 | ||
| 98 | tinystl::vector< tinystl::vector<nocopy> >::iterator it = v.begin(), end = v.end(); | |
| 99 | for (; it != end; ++it) { | |
| 100 | CHECK( (*it).empty() ); | |
| 101 | CHECK( (*it).size() == 0 ); | |
| 102 | CHECK( (*it).begin() == (*it).end() ); | |
| 103 | } | |
| 104 | } | |
| 105 | ||
| 106 | TEST(vector_nocopy_swap) { | |
| 107 | tinystl::vector<nocopy> v1; | |
| 108 | v1.emplace_back("12"); | |
| 109 | v1.emplace_back("20"); | |
| 110 | ||
| 111 | tinystl::vector<nocopy> v2; | |
| 112 | v2.emplace_back("54"); | |
| 113 | ||
| 114 | v1.swap(v2); | |
| 115 | ||
| 116 | CHECK(v1.size() == 1); | |
| 117 | CHECK(v2.size() == 2); | |
| 118 | CHECK(v1[0] == "54"); | |
| 119 | CHECK(v2[0] == "12"); | |
| 120 | CHECK(v2[1] == "20"); | |
| 121 | } | |
| 122 | ||
| 123 | TEST(vector_nocopy_popback) { | |
| 124 | tinystl::vector<nocopy> v; | |
| 125 | v.emplace_back("12"); | |
| 126 | v.emplace_back("24"); | |
| 127 | ||
| 128 | CHECK(v.back() == "24"); | |
| 129 | ||
| 130 | v.pop_back(); | |
| 131 | ||
| 132 | CHECK(v.back() == "12"); | |
| 133 | CHECK(v.size() == 1); | |
| 134 | } | |
| 135 | ||
| 136 | TEST(vector_nocopy_erase) { | |
| 137 | tinystl::vector<nocopy> v; | |
| 138 | v.emplace_back("1"); | |
| 139 | v.emplace_back("2"); | |
| 140 | v.emplace_back("3"); | |
| 141 | v.emplace_back("4"); | |
| 142 | v.emplace_back("5"); | |
| 143 | ||
| 144 | tinystl::vector<nocopy>::iterator it = v.erase(v.begin()); | |
| 145 | CHECK(*it == "2"); | |
| 146 | CHECK(v.size() == 4); | |
| 147 | ||
| 148 | it = v.erase(v.end() - 1); | |
| 149 | CHECK(it == v.end()); | |
| 150 | CHECK(v.size() == 3); | |
| 151 | ||
| 152 | v.erase(v.begin() + 1, v.end() - 1); | |
| 153 | CHECK(v.size() == 2); | |
| 154 | CHECK(v[0] == "2"); | |
| 155 | CHECK(v[1] == "4"); | |
| 156 | } | |
| 157 | ||
| 158 | TEST(vector_nocopy_erase_unordered) { | |
| 159 | typedef tinystl::vector<nocopy> vector; | |
| 160 | vector v; | |
| 161 | v.emplace_back("1"); | |
| 162 | v.emplace_back("2"); | |
| 163 | v.emplace_back("3"); | |
| 164 | v.emplace_back("4"); | |
| 165 | v.emplace_back("5"); | |
| 166 | ||
| 167 | const char* first = v.front().release(); | |
| 168 | vector::iterator it = v.erase_unordered(v.begin()); | |
| 169 | CHECK( it == v.begin() ); | |
| 170 | CHECK( v.size() == 4 ); | |
| 171 | CHECK( std::count(v.begin(), v.end(), first) == 0 ); | |
| 172 | for (it = v.begin(); it != v.end(); ++it) { | |
| 173 | CHECK( std::count(v.begin(), v.end(), *it) == 1 ); | |
| 174 | } | |
| 175 | ||
| 176 | const char* last = v.back().release(); | |
| 177 | it = v.erase_unordered(v.end() - 1); | |
| 178 | CHECK( it == v.end() ); | |
| 179 | CHECK( v.size() == 3 ); | |
| 180 | CHECK( std::count(v.begin(), v.end(), last) == 0 ); | |
| 181 | for (it = v.begin(); it != v.end(); ++it) { | |
| 182 | CHECK( std::count(v.begin(), v.end(), *it) == 1 ); | |
| 183 | } | |
| 184 | ||
| 185 | first = v.begin()->data; | |
| 186 | last = (v.end() - 1)->data; | |
| 187 | v.erase_unordered(v.begin() + 1, v.end() - 1); | |
| 188 | CHECK( v.size() == 2 ); | |
| 189 | CHECK( std::count(v.begin(), v.end(), first) == 1 ); | |
| 190 | CHECK( std::count(v.begin(), v.end(), last) == 1 ); | |
| 191 | } | |
| 192 | ||
| 193 | TEST(vector_nocopy_insert) { | |
| 194 | tinystl::vector<nocopy> v; | |
| 195 | v.emplace_back("1"); | |
| 196 | v.emplace_back("2"); | |
| 197 | v.emplace_back("3"); | |
| 198 | v.emplace_back("4"); | |
| 199 | v.emplace_back("5"); | |
| 200 | ||
| 201 | v.emplace(v.begin(), "0"); | |
| 202 | CHECK( v.size() == 6 ); | |
| 203 | CHECK( v[0] == "0" ); | |
| 204 | CHECK( v[1] == "1" ); | |
| 205 | CHECK( v[5] == "5" ); | |
| 206 | ||
| 207 | v.emplace(v.end(), "6"); | |
| 208 | CHECK( v.size() == 7 ); | |
| 209 | CHECK( v.front() == "0" ); | |
| 210 | CHECK( v.back() == "6" ); | |
| 211 | } | |
| 212 | ||
| 213 | TEST(vector_nocopy_iterator) { | |
| 214 | tinystl::vector<nocopy> v(5); | |
| 215 | v[0].reset("1"); | |
| 216 | v[1].reset("2"); | |
| 217 | v[2].reset("3"); | |
| 218 | v[3].reset("4"); | |
| 219 | v[4].reset("5"); | |
| 220 | ||
| 221 | const tinystl::vector<nocopy>& cv = v; | |
| 222 | ||
| 223 | //CHECK(v.data() == &*v.begin()); | |
| 224 | //CHECK(v.data() == &v[0]); | |
| 225 | //CHECK(v.data() + v.size() == &*v.end()); | |
| 226 | CHECK(v.begin() == cv.begin()); | |
| 227 | CHECK(v.end() == cv.end()); | |
| 228 | //CHECK(v.data() == cv.data()); | |
| 229 | } |
| r249195 | r249196 | |
|---|---|---|
| 1 | 1 | /*- |
| 2 | * Copyright 2012 Matthew Endsley | |
| 2 | * Copyright 2012-1015 Matthew Endsley | |
| 3 | 3 | * All rights reserved |
| 4 | 4 | * |
| 5 | 5 | * Redistribution and use in source and binary forms, with or without |
| r249195 | r249196 | |
| 33 | 33 | #include <string.h> |
| 34 | 34 | #include <stdlib.h> |
| 35 | 35 | |
| 36 | #if !BX_COMPILER_MSVC | |
| 37 | # define _strdup strdup | |
| 38 | #endif // !BX_COMPILER_MSVC | |
| 39 | ||
| 40 | 36 | struct nodefault { |
| 41 | nodefault(const char* s) { data = | |
| 37 | nodefault(const char* s) { data = strdup(s); } | |
| 42 | 38 | ~nodefault() { free(data); } |
| 43 | nodefault(const nodefault& other) { data = 0; if (other.data) data = | |
| 39 | nodefault(const nodefault& other) { data = 0; if (other.data) data = strdup(other.data); } | |
| 44 | 40 | nodefault& operator=(const nodefault& other) { nodefault(other).swap(*this); return *this; } |
| 45 | 41 | void swap(nodefault& other) { std::swap(data, other.data); } |
| 46 | 42 |
| r249195 | r249196 |
|---|
| Previous | 199869 Revisions | Next |