#pragma once #if defined(_M_X64) || defined(__x86_64__) # define SPRAWL_64_BIT 1 # define SPRAWL_32_BIT 0 #else # define SPRAWL_64_BIT 0 # define SPRAWL_32_BIT 1 #endif #if defined(_MSC_VER) && !defined(__clang__) # define SPRAWL_COMPILER_MSVC 1 # define SPRAWL_COMPILER_CLANG 0 # define SPRAWL_COMPILER_GCC 0 # define SPRAWL_COMPILER_INTEL 0 # define SPRAWL_COMPILER_GNU_COMPAT 0 #elif defined(__INTEL_COMPILER_BUILD_DATE) # define SPRAWL_COMPILER_MSVC 0 # define SPRAWL_COMPILER_CLANG 0 # define SPRAWL_COMPILER_GCC 0 # define SPRAWL_COMPILER_INTEL 1 # define SPRAWL_COMPILER_GNU_COMPAT 1 #elif defined(__clang__) # define SPRAWL_COMPILER_MSVC 0 # define SPRAWL_COMPILER_CLANG 1 # define SPRAWL_COMPILER_GCC 0 # define SPRAWL_COMPILER_INTEL 0 # define SPRAWL_COMPILER_GNU_COMPAT 1 #elif defined(__GNUC__) # define SPRAWL_COMPILER_MSVC 0 # define SPRAWL_COMPILER_CLANG 0 # define SPRAWL_COMPILER_GCC 1 # define SPRAWL_COMPILER_INTEL 0 # define SPRAWL_COMPILER_GNU_COMPAT 1 #endif #if SPRAWL_COMPILER_GNU_COMPAT # define SPRAWL_LIKELY(x) (__builtin_expect(!!(x), 1)) # define SPRAWL_UNLIKELY(x) (__builtin_expect(!!(x), 0)) #else # define SPRAWL_LIKELY(x) (x) # define SPRAWL_UNLIKELY(x) (x) #endif #if SPRAWL_COMPILER_GNU_COMPAT # define SPRAWL_MEMCMP __builtin_memcmp # ifndef SPRAWL_MULTITHREADED # ifdef _REENTRANT # define SPRAWL_MULTITHREADED 1 # else # define SPRAWL_MULTITHREADED 0 # endif # endif # define SPRAWL_FORCEINLINE inline __attribute__((always_inline)) #else # define SPRAWL_MEMCMP memcmp # ifndef SPRAWL_MULTITHREADED # ifdef _MT # define SPRAWL_MULTITHREADED 1 # else # define SPRAWL_MULTITHREADED 0 # endif # endif # define SPRAWL_FORCEINLINE inline __forceinline #endif #define SPRAWL_CONCAT_2(left, right) left ## right #define SPRAWL_CONCAT(left, right) SPRAWL_CONCAT_2(left, right) #if defined(_WIN32) # include <BaseTsd.h> typedef SSIZE_T ssize_t; #endif #if defined(_WIN32) #define SPRAWL_I64FMT "ll" #elif defined(__APPLE__) #define SPRAWL_I64FMT "ll" #else #define SPRAWL_I64FMT "l" #endif //Detecting debug settings works as follows: // 1) If __OPTIMIZE__ is defined, DEBUG is 0 regardless of system // 2) If _DEBUG is defined, DEBUG is 1 regardless of system // 3) If neither of those is defined, DEBUG is 0 for Windows (which makes a define for when something IS debug) // or 1 otherwise (where a define is made when something IS NOT debug) #if defined(__OPTIMIZE__) # define SPRAWL_DEBUG 0 #elif defined(_DEBUG) # define SPRAWL_DEBUG 1 #else # ifdef _WIN32 # define SPRAWL_DEBUG 0 # else # define SPRAWL_DEBUG 1 # endif #endif #if SPRAWL_COMPILER_MSVC # define SPRAWL_CONSTEXPR_INCLASS_INIT(...) # define SPRAWL_CONSTEXPR_OUT_OF_CLASS_INIT(...) = __VA_ARGS__ # define CONSTEXPR_ARRAY const #else # define SPRAWL_CONSTEXPR_INCLASS_INIT(...) = __VA_ARGS__ # define SPRAWL_CONSTEXPR_OUT_OF_CLASS_INIT(...) # define CONSTEXPR_ARRAY constexpr #endif #define SPRAWL_DEFINE_COMPILE_ERROR(type, text) template<bool t_Check> struct type { static_assert(t_Check, text); } #if !defined(SPRAWL_BIG_ENDIAN) || !defined(SPRAWL_LITTLE_ENDIAN) # if (defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)) || \ (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) || \ defined(__ARMEB__) || \ defined(__THUMBEB__) || \ defined(__AARCH64EB__) || \ defined(_MIPSEB) || \ defined(__MIPSEB) || \ defined(__MIPSEB__) || \ (defined(_MSC_VER) && defined(_M_PPC)) # define SPRAWL_BIG_ENDIAN 1 # define SPRAWL_LITTLE_ENDIAN 0 # elif (defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) || \ (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) || \ defined(__ARMEL__) || \ defined(__THUMBEL__) || \ defined(__AARCH64EL__) || \ defined(_MIPSEL) || \ defined(__MIPSEL) || \ defined(__MIPSEL__) || \ (defined(_MSC_VER) && !defined(_M_PPC)) # define SPRAWL_BIG_ENDIAN 0 # define SPRAWL_LITTLE_ENDIAN 1 # else # error "Could not detect endianness - please define both SPRAWL_BIG_ENDIAN and SPRAWL_LITTLE_ENDIAN" # endif #endif #if SPRAWL_BIG_ENDIAN && SPRAWL_LITTLE_ENDIAN # error "SPRAWL_BIG_ENDIAN and SPRAWL_LITTLE_ENDIAN are both true! One must be false!" #elif !SPRAWL_BIG_ENDIAN && !SPRAWL_LITTLE_ENDIAN # error "SPRAWL_BIG_ENDIAN and SPRAWL_LITTLE_ENDIAN are both false! One must be true!" #endif
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 23398 | ququlala | "Forking branch Mainline of shadauxcat-libsprawl to ququlala-libsprawl." | ||
//guest/ShadauxCat/Sprawl/Mainline/common/compat.hpp | |||||
#8 | 19906 | ShadauxCat |
- Added tag, compile time string type - Since tag requires visual studio 2015, removed compatibility code for earlier versions of visual studio - Improved compiler detection - Added endianness detection - Added template if/else helper - Fixed bug with murmur3 64 bit - Added seed argument for murmur3 #review-19907 |
||
#7 | 16768 | ShadauxCat |
Improvements to error handling in builds with exceptions disabled: - In debug builds or with SPRAWL_ERRORSTATE_STRICT enabled, ErrorState will output a message to stderr and terminate if Get() is called when an error flag is set. (In release buils or with SPRAWL_ERRORSTATE_PERMISSIVE defined, Get() will return junk memory in this case.) - In debug builds or with SPRAWL_ERRORSTATE_STRICT enabled, ErrorState will output a message to stderr and terminate if its destructor is called without checking the errorstate if an error is present (equivalent to an exception terminating the application if no catch() block is present for it). - On linux builds and when running "Analyze" through visual studio, a warning will be issued if any function returning ErrorState has its return value ignored. (This only applies to builds with exceptions not enabled; when exceptions are enabled no warning is issued) - Many functions that could return ErrorState were having their return values silently ignored in internal sprawl code so the user would not find out about errors if exceptions are disabled; now anything in sprawl code that calls a function returning ErrorState will either handle the error, or (in most cases) surface it back up to the user. - As a positive side-effect of the warnings for ignoring ErrorState, several constructors that were capable of throwing exceptions are no longer capable of doing so. #review-16769 |
||
#6 | 16179 | ShadauxCat |
- Added SPRAWL_DEBUG macro - Added additional runtime coroutine safety checks against not only wrong type of coroutine, but wrong send/receive type - Added ability to disable these additional runtime checks (and defaulted them to turned off in release builds) as they entail up to three virtual function calls and possibly an exception (when exceptions are enabled) - Added requirement that a coroutine that can yield a value must call a function that returns a value of the same type - this ensures that after the last value from the function has been received, the function doesn't have to be called again (with potentially unpredictable results...) to put it into the "Completed" state. Now the last value must be transmitted with a full return, so the last value and the "Completed" state come around at the same time. (This involves all sorts of ca-razy assumptions and reinterpret_casting... assumptions protected via static_assert) #review-16180 |
||
#5 | 16052 | ShadauxCat |
- Changed default block size for concurrent queue to a more reasonable value - Changed some memory orders to memory_order_seq_cst when they don't actually need to be that to get around a bug in visual studio 2013 - debug builds assert when memory_order_acq_rel is used for a compare_exchange_strong (this is a standard library bug and is fixed in VS2015) - Added Event API - events are an alternative to condition variables that do not require a mutex and are guaranteed not to miss any signals, even if the signal comes while the thread is not listening for it. Unlike condition variables, however, they do not support broadcasting (and in fact, in general, are not safe to use with multiple threads listening for the same event simultaneously - though notifying on the same event is fine) - Rewrote ThreadManager around ConcurrentQueue and Event API so it is now lock-free. Also improved some behaviors of the staged thread manager operation so it now supports tasks that can be run on multiple stages via a bitmask. - Fixed an issue where the Coroutine copy constructor was calling the std::function constructor instead and another where initializing with a stack might try to call the wrong constructor and vice-versa - Fixed Coroutine never calling munmap() on its stack in linux and causing a memory leak - Added default arguments to time functions - Attempted to fix some issues with BinaryTree. Fixed some but not all. It's currently not suitable for use, sadly. - Logging Improvements: - - Added thread ID to logging - - Fixed some issues with category handlers - - Added backtraces - - Added the following additional log macros: - - - LOG_IF - - - LOG_EVERY_N - - - LOG_FIRST_N - - - LOG_IF_EVERY_N - - - LOG_IF_FIRST_N - - - LOG_ASSERT - - Added the ability to set extra info callbacks to get data such as script backtraces - - Removed the thread-related handlers and replaced them with RunHandler_Threaded and RunHandler_ThreadManager, which will enable any passed-in handler to be run in a threaded fashion - Removed StaticPoolAllocator and renamed DynamicPoolAllocator to PoolAllocator; adjusted unit tests accordingly - PoolAllocator now allocates its pool with mmap and VirtualAlloc, rather than with malloc - Fixed a bug with Vector copy assignment operator - Improved performance of StringBuilder considerably for cases where there are no modifier strings - Removed Copy-On-Write behavior of JSONToken as it was broken; copies are now performed with explicit DeepCopy() and ShallowCopy() functions - Fixed some parser bugs with JSONToken - Added iteration to JSONToken to iterate its children - Fixed crash when reading a negative number of bytes from a file - Changed StringBuilder to favor speed instead of memory by default - Added some performance unit tests for JSON token #review-16053 |
||
#4 | 15891 | ShadauxCat |
Concurrent queue implementation, plus updates to makefile in light of recent csbuild changes. #review-15892 |
||
#3 | 14121 | ShadauxCat |
-Fixed msvc compile errors (msvc sucks at decltype, btw...) -Fixed BitVector and BitSet being broken on msvc due to 1L being 32-bit rather than 64-bit -Fixed Deque being broken on 32-bit systems due to an errant int64_t -Changed types of deque indexes from size_t to ssize_t; since they have to be signed for a moment to handle circling the buffer, the sign bit is lost for capacity anyway, and using signed indexes means... -Deque and Vector now support negative indexing a la python list #review-14122 |
||
#2 | 13650 | ShadauxCat |
- Windows implementations of thread and time libraries - Added coroutines - Added some more unit tests, fixed some unit tests in windows environments - Fixed an issue where multi threading was not properly detected on Linux - Fixed the makefiles to build with threading by default on linux - Changed the pool allocator to use thread-local pools instead of locking mutexes - Fixed output of sprawl::string in the StringBuilder library to take length into account - Added string builder options for StringLiteral - Added thread local implementation #review |
||
#1 | 11496 | ShadauxCat | Initial checkin: Current states for csbuild and libSprawl |