├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── Makefile ├── README.md ├── RingQueue.cbp ├── RingQueue_Linux.cbp ├── RingQueue_vc2008.sln ├── RingQueue_vc2010.sln ├── RingQueue_vc2013.sln ├── RingQueue_vc2015.sln ├── _mktime32.txt ├── build └── ReadMe.txt ├── cmake ├── ReadMe.txt └── modules │ ├── DisplayComplierEnv.cmake │ └── GetCompilerToolset.cmake ├── disruptor ├── csharp │ ├── Program.cs │ ├── Version.cs │ └── nPnCRingQueueTest.cs └── java │ ├── RingBufferPerfTest.bat │ ├── RingBufferPerfTest.java │ └── RingBufferPerfTest2.java ├── douban ├── SpinWait.cs ├── a.c ├── a2.c ├── a3.c ├── mq.c ├── q.h ├── q3.h ├── q3_new.h └── qlock.h ├── include └── RingQueue │ ├── Attributes.h │ ├── DisruptorRingQueue.h │ ├── DisruptorRingQueueEx.h │ ├── DisruptorRingQueueOld.h │ ├── MessageEvent.h │ ├── RingQueue.h │ ├── Sequence.h │ ├── SerialRingQueue.h │ ├── SingleRingQueue.h │ ├── SpinMutex.h │ ├── console.h │ ├── dump_mem.h │ ├── get_char.h │ ├── mq.h │ ├── msvc │ ├── inttypes.h │ ├── pthread.h │ ├── sched.h │ ├── stdbool.h │ ├── stdint.h │ └── targetver.h │ ├── port.h │ ├── q.h │ ├── q3.h │ ├── sleep.h │ ├── sys_timer.h │ ├── test.h │ ├── vs_inttypes.h │ ├── vs_stdbool.h │ └── vs_stdint.h ├── projects └── RingQueue │ ├── vc2008 │ ├── ReadMe.txt │ └── RingQueue.vcproj │ ├── vc2010 │ ├── ReadMe.txt │ ├── RingQueue.vcxproj │ └── RingQueue.vcxproj.filters │ ├── vc2013 │ ├── ReadMe.txt │ ├── RingQueue.vcxproj │ └── RingQueue.vcxproj.filters │ └── vc2015 │ ├── ReadMe.txt │ ├── RingQueue.vcxproj │ └── RingQueue.vcxproj.filters └── src └── RingQueue ├── CMakeLists.txt ├── console.c ├── dump_mem.c ├── get_char.c ├── main.cpp ├── mq.c ├── msvc ├── pthread.c └── sched.c ├── sleep.c └── sys_timer.c /.gitignore: -------------------------------------------------------------------------------- 1 | ### These files should get ignored no matter where they appear. 2 | 3 | /*.gcov.* 4 | 5 | /autom4te.cache/ 6 | 7 | /config.stamp 8 | /config.log 9 | /config.status 10 | # /configure 11 | 12 | # /Makefile 13 | 14 | /CMakeFiles 15 | *CMakeCache.txt 16 | 17 | /src/*.[od] 18 | /src/*.gcda 19 | /src/*.gcno 20 | 21 | # /test/test.sh 22 | 23 | /test/src/*.[od] 24 | /test/src/*.gcda 25 | /test/src/*.gcno 26 | 27 | # /VERSION 28 | 29 | # Ignore Compiled Object files 30 | *.slo 31 | *.lo 32 | *.o 33 | *.obj 34 | 35 | # Ignore Precompiled Headers 36 | *.gch 37 | *.pch 38 | 39 | # Ignore Compiled Dynamic libraries 40 | *.so 41 | *.dylib 42 | *.dll 43 | 44 | # Ignore Fortran module files 45 | *.mod 46 | 47 | # Ignore Compiled Static libraries 48 | # *.lai 49 | # *.la 50 | # *.a 51 | # *.lib 52 | 53 | # Ignore project build libraries 54 | /lib/ 55 | 56 | # Ignore Executables 57 | *.exe 58 | *.out 59 | *.app 60 | 61 | # Editors leave these lying around 62 | \#*\# 63 | .#* 64 | *~ 65 | *.swp 66 | 67 | # Ignore thumbnails and icon cache files created by Windows 68 | Thumbs.db 69 | ehthumbs.db 70 | 71 | # Ignore some files on Windows 72 | .DS_Store* 73 | Icon? 74 | 75 | # Ignore files build by Visual Studio 76 | *.obj 77 | *.pdb 78 | *.dep 79 | *.user 80 | *.ncb 81 | *.aps 82 | *.pch 83 | *.vspscc 84 | *.idb 85 | *.ilk 86 | *.tlb 87 | *.tlh 88 | *.tli 89 | *.tmp 90 | *.sbr 91 | *.rsp 92 | *.pgc 93 | *.pgd 94 | *.suo 95 | *.sdf 96 | *.opensdf 97 | *.sln.old 98 | *.sln_old 99 | *.meta 100 | *.manifest 101 | *.intermediate.manifest 102 | *.bak 103 | 104 | # *.vcxproj.user 105 | # *_i.c 106 | # *_p.c 107 | 108 | # Ignore AStyle backup files 109 | *.orig 110 | 111 | # Ignore Code::Blocks backup files 112 | *.sav 113 | 114 | # Ignore Sublime Text 2 dump files 115 | *.dump 116 | 117 | # Ignore Eclipse or VSCode settings files 118 | .settings 119 | 120 | # Ignore stackdump files on Linux 121 | *.stackdump 122 | 123 | # Ignore Intel C++ Compiler Log Files & Project Files 124 | IcUpdateLog.htm 125 | *.icproj 126 | 127 | # Ignore CodeBlocks project layout/depend files 128 | *.layout 129 | *.depend 130 | 131 | # Ignore obj files in GCC 132 | *.pic.d 133 | *.jet.d 134 | 135 | # Ignore log files 136 | *.log 137 | 138 | # Ignore Visual Studio 2013 temp files 139 | *.tlog 140 | 141 | # Ignore Visual Studio C# files 142 | *.cache 143 | 144 | # Ignore Visual Studio Update Files 145 | UpgradeLog.XML 146 | UpgradeLog.htm 147 | /[Bb]ackup/ 148 | 149 | # Ignore Zip or Rar files 150 | *.zip 151 | *.rar 152 | 153 | # Ignore CMake cache or temp files(folders) 154 | /CMakeFiles 155 | *CMakeCache.txt 156 | 157 | # Ignore tmp and obj folders 158 | [Bb]in 159 | [Oo]bj/ 160 | /[Oo]bj/ 161 | /[Gg]en/ 162 | /tmp/ 163 | /temp/ 164 | !/[Bb]uild/ReadMe.txt 165 | /[Bb]uild/*/ 166 | 167 | # Ignore bin and build folders 168 | /[Bb]in/ 169 | /[Dd]ebug/ 170 | /[Rr]elease/ 171 | /x86-[Dd]ebug/ 172 | /x86-[Rr]elease/ 173 | /x64-[Dd]ebug/ 174 | /x64-[Rr]elease/ 175 | !/deps/ 176 | 177 | [Bb]in 178 | [Dd]ebug*/ 179 | [Rr]elease*/ 180 | _ReSharper*/ 181 | [Tt]est[Rr]esult* 182 | 183 | # Other files or folders 184 | /.metadata 185 | /169.254.0.1 186 | /ipch/ 187 | # /cmake/ 188 | /Simulator/ 189 | /Simulator-Coverage/ 190 | /Simulator-Profile/ 191 | /Device-Debug/ 192 | /Device-Coverage/ 193 | /Device-Profile/ 194 | /Device-Release/ 195 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.8) 2 | 3 | set(JLANG_CMAKE_SHOW_DETAIL 0) 4 | set(JLANG_CMAKE_SHOW_MSVC_DETAIL 0) 5 | set(JLANG_CMAKE_SHOW_DEBUG 1) 6 | set(JLANG_CMAKE_SHOW_INFO 1) 7 | 8 | # Add path for custom modules 9 | set(CMAKE_MODULE_PATH 10 | ${CMAKE_MODULE_PATH} 11 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" 12 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" 13 | ) 14 | 15 | message(STATUS "CMAKE_SOURCE_DIR = " ${CMAKE_SOURCE_DIR}) 16 | message(STATUS "CMAKE_BINARY_DIR = " ${CMAKE_BINARY_DIR}) 17 | if (JLANG_CMAKE_SHOW_DETAIL) 18 | message(STATUS "CMAKE_CURRENT_SOURCE_DIR = " ${CMAKE_CURRENT_SOURCE_DIR}) 19 | message(STATUS "CMAKE_CURRENT_BINARY_DIR = " ${CMAKE_CURRENT_BINARY_DIR}) 20 | endif() 21 | message(STATUS "") 22 | 23 | if (JLANG_CMAKE_SHOW_DETAIL) 24 | message(STATUS "Now create a empty project.") 25 | message(STATUS "") 26 | endif() 27 | 28 | # Create a empty project to get the project's variants value 29 | project("") 30 | message(STATUS "") 31 | 32 | if (JLANG_CMAKE_SHOW_DETAIL) 33 | message(STATUS "Create the empty project done.") 34 | message(STATUS "") 35 | endif() 36 | 37 | # If we are not building as a part of JLVM, build JLang as an 38 | # standalone project, using JLVM as an external library: 39 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) 40 | # set(CMAKE_C_COMPILER g++) 41 | 42 | if (JLANG_CMAKE_SHOW_DETAIL) 43 | message(STATUS "Start to detect the compiler environment ...") 44 | message(STATUS "") 45 | endif() 46 | 47 | include(GetCompilerToolset) 48 | 49 | # Get the Compiler Toolset 50 | set(COMPILER_TOOLSET) 51 | GetCompilerToolset(COMPILER_TOOLSET "cxx") 52 | message(STATUS "COMPILER_TOOLSET = ${COMPILER_TOOLSET}") 53 | message(STATUS "") 54 | 55 | include(DisplayComplierEnv) 56 | 57 | # Check Compiler Environment Values 58 | DisplayCompilerEnvironment() 59 | 60 | if (JLANG_CMAKE_SHOW_DETAIL) 61 | message(STATUS "Create the real project files.") 62 | endif() 63 | if ((NOT MSVC) OR (COMPILER_TOOLSET STREQUAL "")) 64 | # message(STATUS "The real project filename is \"RingQueue\".") 65 | project("RingQueue") 66 | else() 67 | # message(STATUS "The real project filename is \"RingQueue_${COMPILER_TOOLSET}\".") 68 | project("RingQueue_${COMPILER_TOOLSET}") 69 | endif() 70 | if (JLANG_CMAKE_SHOW_DETAIL) 71 | message(STATUS "Create the real project files done.") 72 | endif() 73 | message(STATUS "") 74 | 75 | # include_directories(${PROJECT_SOURCE_DIR}/include) 76 | # add_library(util STATIC ${SRC_LIST}) 77 | # add_library(libhello SHARED ${LIB_SRC}) 78 | # link_directories(${PROJECT_SOURCE_DIR}/lib) 79 | 80 | message(STATUS "PROJECT_SOURCE_DIR = " ${PROJECT_SOURCE_DIR}) 81 | message(STATUS "PROJECT_BINARY_DIR = " ${PROJECT_BINARY_DIR}) 82 | message(STATUS "") 83 | 84 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) 85 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 86 | 87 | message(STATUS "EXECUTABLE_OUTPUT_PATH = " ${EXECUTABLE_OUTPUT_PATH}) 88 | message(STATUS "LIBRARY_OUTPUT_PATH = " ${LIBRARY_OUTPUT_PATH}) 89 | message(STATUS "") 90 | 91 | set(TOOLS_BINARY_DIR ${PROJECT_BINARY_DIR}/bin) 92 | set(LIBRARY_DIR ${PROJECT_BINARY_DIR}/lib) 93 | set(INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src) 94 | set(JLVM_OBJ_ROOT ${PROJECT_BINARY_DIR}) 95 | set(MAIN_SRC_DIR ${PROJECT_BINARY_DIR}/src) 96 | 97 | set(JLVM_INCLUDE_DIR ${JLVM_BINARY_DIR}/src) 98 | 99 | set(JLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to jlvm/bin") 100 | set(JLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to jlvm/lib") 101 | set(JLVM_MAIN_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Path to jlvm/include") 102 | set(JLVM_BINARY_DIR ${JLVM_OBJ_ROOT} CACHE PATH "Path to JLVM build tree") 103 | set(JLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to JLVM source tree") 104 | 105 | if (EXISTS ${JLVM_INCLUDE_DIR}) 106 | include_directories("${JLVM_INCLUDE_DIR}" "${JLVM_BINARY_DIR}/include" "${JLVM_MAIN_INCLUDE_DIR}") 107 | else() 108 | include_directories("${JLVM_BINARY_DIR}/include" "${JLVM_MAIN_INCLUDE_DIR}") 109 | endif() 110 | link_directories("${JLVM_LIBRARY_DIR}") 111 | 112 | # 113 | # In CMake, how do I work around the Debug and Release directories Visual Studio 2010 tries to add? 114 | # 115 | # See: http://stackoverflow.com/questions/7747857/in-cmake-how-do-i-work-around-the-debug-and-release-directories-visual-studio-2 116 | # 117 | 118 | # First for the generic no-config case (e.g. with mingw) 119 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 120 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 121 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 122 | 123 | # Second, for multi-config builds (e.g. msvc) 124 | foreach (OUTPUT_CONFIG ${CMAKE_CONFIGURATION_TYPES}) 125 | #string(TOUPPER ${OUTPUT_CONFIG} OUTPUT_CONFIG) 126 | string(TOLOWER ${OUTPUT_CONFIG} OUTPUT_CONFIG) 127 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUT_CONFIG} ${CMAKE_BINARY_DIR}/bin/${OUTPUT_CONFIG}) 128 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUT_CONFIG} ${CMAKE_BINARY_DIR}/lib/${OUTPUT_CONFIG}) 129 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUT_CONFIG} ${CMAKE_BINARY_DIR}/lib/${OUTPUT_CONFIG}) 130 | endforeach(OUTPUT_CONFIG CMAKE_CONFIGURATION_TYPES) 131 | endif() 132 | 133 | set(JLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 134 | set(JLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) 135 | 136 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE) 137 | message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite " 138 | "the makefiles distributed with JLVM. Please create a directory and run cmake " 139 | "from there, passing the path to this source directory as the last argument. " 140 | "This process created the file `CMakeCache.txt' and the directory " 141 | "`CMakeFiles'. Please delete them.") 142 | endif() 143 | 144 | # Add appropriate flags for GCC 145 | if (JLVM_COMPILER_IS_GCC_COMPATIBLE) 146 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing") 147 | 148 | # Enable -pedantic for Clang even if it's not enabled for JLVM. 149 | if (NOT JLVM_ENABLE_PEDANTIC) 150 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-long-long") 151 | endif () 152 | 153 | check_cxx_compiler_flag("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG) 154 | if (CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG) 155 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" ) 156 | endif() 157 | endif () 158 | 159 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 160 | 161 | include_directories(BEFORE 162 | ${CMAKE_CURRENT_BINARY_DIR}/include 163 | ${CMAKE_CURRENT_SOURCE_DIR}/include 164 | ) 165 | 166 | add_subdirectory(src/RingQueue) 167 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 XiongHui Guo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | # Clear the default suffixes, so that built-in rules are not used. 3 | .SUFFIXES : 4 | 5 | SHELL := /bin/sh 6 | 7 | CC := gcc 8 | CXX := g++ 9 | 10 | # Configuration parameters. 11 | DESTDIR = 12 | BINDIR := $(DESTDIR)/usr/local/bin 13 | INCLUDEDIR := $(DESTDIR)/usr/local/include 14 | LIBDIR := $(DESTDIR)/usr/local/lib 15 | DATADIR := $(DESTDIR)/usr/local/share 16 | MANDIR := $(DESTDIR)/usr/local/share/man 17 | srcroot := 18 | objroot := obj/gcc/linux/ 19 | binroot := bin/gcc/linux/ 20 | 21 | LDFLAGS := 22 | EXTRA_LDFLAGS := 23 | LIBS := -lpthread 24 | RPATH_EXTRA := 25 | SO := so 26 | IMPORTLIB := so 27 | O := o 28 | A := a 29 | EXE := 30 | LIBPREFIX := lib 31 | REV := 1 32 | install_suffix := 33 | ABI := elf 34 | XSLTPROC := /usr/bin/xsltproc 35 | AUTOCONF := false 36 | _RPATH = -Wl,-rpath,$(1) 37 | RPATH = $(if $(1),$(call _RPATH,$(1))) 38 | 39 | ########################################################################## 40 | # See: http://stackoverflow.com/questions/714100/os-detecting-makefile # 41 | ########################################################################## 42 | 43 | ifeq ($(OS), Windows_NT) 44 | LIBS += -lwinmm 45 | objroot := obj/gcc/mingw/ 46 | binroot := bin/gcc/mingw/ 47 | else 48 | UNAME_S := $(shell uname -s) 49 | 50 | ifeq ($(UNAME_S), Linux) 51 | LIBS += -lrt 52 | CCFLAGS += -D LINUX 53 | CXXFLAGS += -D LINUX 54 | objroot := obj/gcc/linux/ 55 | binroot := bin/gcc/linux/ 56 | endif 57 | ifeq ($(UNAME_S), Darwin) 58 | CCFLAGS += -D OSX 59 | CXXFLAGS += -D OSX 60 | objroot := obj/gcc/darwin/ 61 | binroot := bin/gcc/darwin/ 62 | endif 63 | 64 | UNAME_P := $(shell uname -p) 65 | 66 | # x86_64|amd64|AMD64) 67 | ifeq ($(UNAME_P), x86_64) 68 | CCFLAGS += -m64 -D AMD64 69 | CXXFLAGS += -m64 -D AMD64 70 | endif 71 | # i[3456789]86|x86|i86pc) 72 | ifneq ($(filter %86, $(UNAME_P)),) 73 | CCFLAGS += -m32 -D IA32 74 | CXXFLAGS += -m32 -D IA32 75 | endif 76 | # arm*) 77 | ifneq ($(filter arm%, $(UNAME_P)),) 78 | CCFLAGS += -D ARM 79 | CXXFLAGS += -D ARM 80 | objroot := obj/gcc/arm/ 81 | binroot := bin/gcc/arm/ 82 | endif 83 | endif 84 | 85 | # Build parameters. -m32 for x86 (32 bit), -m64 for x64 (64 bit) 86 | CCFLAGS := -Wall -w -pipe -g3 -fpermissive -fvisibility=hidden -O3 -funroll-loops -msse -msse2 -msse3 -DNDEBUG -D_GNU_SOURC -D__MMX__ -D__SSE__ -D__SSE2__ -D__SSE3__ -I$(srcroot)include -I$(objroot)include -I$(srcroot)include/RingQueue -I$(objroot)include/RingQueue 87 | CXXFLAGS := -std=c++0x -Wall -w -pipe -g3 -fpermissive -fvisibility=hidden -O3 -funroll-loops -msse -msse2 -msse3 -DNDEBUG -D_REENTRANT -D_GNU_SOURC -D__MMX__ -D__SSE__ -D__SSE2__ -D__SSE3__ -I$(srcroot)include -I$(objroot)include -I$(srcroot)include/RingQueue -I$(objroot)include/RingQueue 88 | 89 | header_files := include/RingQueue/console.h include/RingQueue/dump_mem.h include/RingQueue/get_char.h \ 90 | include/RingQueue/mq.h include/RingQueue/port.h include/RingQueue/q3.h \ 91 | include/RingQueue/RingQueue.h include/RingQueue/sleep.h include/RingQueue/sys_timer.h \ 92 | include/RingQueue/test.h include/RingQueue/vs_inttypes.h include/RingQueue/vs_stdbool.h \ 93 | include/RingQueue/vs_stdint.h include/RingQueue/msvc/inttypes.h include/RingQueue/msvc/stdbool.h \ 94 | include/RingQueue/msvc/stdint.h include/RingQueue/msvc/targetver.h \ 95 | include/RingQueue/msvc/pthread.h include/RingQueue/msvc/sched.h \ 96 | include/RingQueue/SpinMutex.h include/RingQueue/MessageEvent.h \ 97 | include/RingQueue/Sequence.h include/RingQueue/DisruptorRingQueue.h \ 98 | include/RingQueue/DisruptorRingQueueOld.h include/RingQueue/SerialRingQueue.h \ 99 | include/RingQueue/SingleRingQueue.h 100 | 101 | enable_autogen := 0 102 | enable_code_coverage := 0 103 | enable_experimental := 1 104 | enable_zone_allocator := 105 | DSO_LDFLAGS = -shared -Wl,-soname,$(@F) 106 | SOREV = so.1 107 | PIC_CCFLAGS = -fPIC -DPIC 108 | PIC_CXXFLAGS = -fPIC -DPIC 109 | CTARGET = -o $@ 110 | LDTARGET = -o $@ 111 | MKLIB = 112 | AR = ar 113 | ARFLAGS = crus 114 | CC_MM = 1 115 | 116 | RINGQUEUE := RingQueue 117 | LIBRINGQUEUE := $(LIBPREFIX)RingQueue$(install_suffix) 118 | 119 | # Lists of files. 120 | BINS := $(srcroot)bin/pprof $(binroot)RingQueue.sh 121 | 122 | C_HDRS := $(srcroot)include/RingQueue/console.h $(srcroot)include/RingQueue/dump_mem.h \ 123 | $(srcroot)include/RingQueue/get_char.h $(srcroot)include/RingQueue/mq.h \ 124 | $(srcroot)include/RingQueue/port.h \ 125 | $(srcroot)include/RingQueue/q3.h $(srcroot)include/RingQueue/RingQueue.h \ 126 | $(srcroot)include/RingQueue/sleep.h $(srcroot)include/RingQueue/sys_timer.h \ 127 | $(srcroot)include/RingQueue/test.h $(srcroot)include/RingQueue/vs_inttypes.h \ 128 | $(srcroot)include/RingQueue/vs_stdbool.h $(srcroot)include/RingQueue/vs_stdint.h \ 129 | $(srcroot)include/RingQueue/msvc/inttypes.h $(srcroot)include/RingQueue/msvc/stdbool.h \ 130 | $(srcroot)include/RingQueue/msvc/stdint.h $(srcroot)include/RingQueue/msvc/targetver.h \ 131 | $(srcroot)include/RingQueue/msvc/pthread.h $(srcroot)include/RingQueue/msvc/sched.h \ 132 | $(srcroot)include/RingQueue/SpinMutex.h $(srcroot)include/RingQueue/MessageEvent.h \ 133 | $(srcroot)include/RingQueue/Sequence.h $(srcroot)include/RingQueue/DisruptorRingQueue.h \ 134 | $(srcroot)include/RingQueue/DisruptorRingQueueOld.h $(srcroot)include/RingQueue/SerialRingQueue.h \ 135 | $(srcroot)include/RingQueue/SingleRingQueue.h 136 | 137 | C_SRCS := $(srcroot)src/RingQueue/console.c \ 138 | $(srcroot)src/RingQueue/dump_mem.c $(srcroot)src/RingQueue/get_char.c $(srcroot)src/RingQueue/mq.c \ 139 | $(srcroot)src/RingQueue/sleep.c $(srcroot)src/RingQueue/sys_timer.c \ 140 | $(srcroot)src/RingQueue/msvc/pthread.c $(srcroot)src/RingQueue/msvc/sched.c 141 | # $(srcroot)src/RingQueue/main.c 142 | 143 | CXX_SRCS := $(srcroot)src/RingQueue/main.cpp 144 | 145 | ifeq ($(IMPORTLIB),$(SO)) 146 | STATIC_LIBS := $(objroot)lib/$(LIBRINGQUEUE).$(A) 147 | endif 148 | ifdef PIC_CCFLAGS 149 | STATIC_LIBS += $(objroot)lib/$(LIBRINGQUEUE)_pic.$(A) 150 | else 151 | ifdef PIC_CXXFLAGS 152 | STATIC_LIBS += $(objroot)lib/$(LIBRINGQUEUE)_pic.$(A) 153 | else 154 | STATIC_LIBS += $(objroot)lib/$(LIBRINGQUEUE)_s.$(A) 155 | endif 156 | endif 157 | DSOS := $(objroot)lib/$(LIBRINGQUEUE).$(SOREV) 158 | ifneq ($(SOREV),$(SO)) 159 | DSOS += $(objroot)lib/$(LIBRINGQUEUE).$(SO) 160 | endif 161 | 162 | C_OBJS := $(C_SRCS:$(srcroot)%.c=$(objroot)%.$(O)) 163 | C_PIC_OBJS := $(C_SRCS:$(srcroot)%.c=$(objroot)%.pic.$(O)) 164 | C_JET_OBJS := $(C_SRCS:$(srcroot)%.c=$(objroot)%.jet.$(O)) 165 | 166 | CXX_OBJS := $(CXX_SRCS:$(srcroot)%.cpp=$(objroot)%.$(O)) 167 | CXX_PIC_OBJS := $(CXX_SRCS:$(srcroot)%.cpp=$(objroot)%.pic.$(O)) 168 | CXX_JET_OBJS := $(CXX_SRCS:$(srcroot)%.cpp=$(objroot)%.jet.$(O)) 169 | 170 | .PHONY: all 171 | .PHONY: clean 172 | .PHONY: help 173 | 174 | # Default target. 175 | all: build_exe 176 | 177 | # 178 | # Include generated dependency files. 179 | # 180 | ifdef CC_MM 181 | -include $(C_OBJS:%.$(O)=%.d) 182 | -include $(C_PIC_OBJS:%.$(O)=%.d) 183 | -include $(C_JET_OBJS:%.$(O)=%.d) 184 | -include $(CXX_OBJS:%.$(O)=%.d) 185 | -include $(CXX_PIC_OBJS:%.$(O)=%.d) 186 | -include $(CXX_JET_OBJS:%.$(O)=%.d) 187 | endif 188 | 189 | $(C_OBJS): $(objroot)src/RingQueue/%.$(O): $(srcroot)src/RingQueue/%.c 190 | $(C_OBJS): CCFLAGS += -I$(srcroot)include -I$(objroot)include/RingQueue 191 | $(C_PIC_OBJS): $(objroot)src/RingQueue/%.pic.$(O): $(srcroot)src/RingQueue/%.c 192 | $(C_PIC_OBJS): CCFLAGS += $(PIC_CCFLAGS) 193 | $(C_JET_OBJS): $(objroot)src/RingQueue/%.jet.$(O): $(srcroot)src/RingQueue/%.c 194 | $(C_JET_OBJS): CCFLAGS += -DRINGQUEUE_JET 195 | 196 | $(CXX_OBJS): $(objroot)src/RingQueue/%.$(O): $(srcroot)src/RingQueue/%.cpp 197 | $(CXX_OBJS): CXXFLAGS += -I$(srcroot)include -I$(objroot)include/RingQueue 198 | $(CXX_PIC_OBJS): $(objroot)src/RingQueue/%.pic.$(O): $(srcroot)src/RingQueue/%.cpp 199 | $(CXX_PIC_OBJS): CXXFLAGS += $(PIC_CXXFLAGS) 200 | $(CXX_JET_OBJS): $(objroot)src/RingQueue/%.jet.$(O): $(srcroot)src/RingQueue/%.cpp 201 | $(CXX_JET_OBJS): CCFLAGS += -DRINGQUEUE_JET 202 | 203 | ifneq ($(IMPORTLIB),$(SO)) 204 | $(C_OBJS): CCFLAGS += -DDLLEXPORT 205 | $(CXX_OBJS): CXXFLAGS += -DDLLEXPORT 206 | endif 207 | 208 | ifndef CC_MM 209 | # Dependencies. 210 | HEADER_DIRS = $(srcroot)src/RingQueue \ 211 | $(srcroot)include/RingQueue $(srcroot)include/RingQueue/msvc 212 | HEADERS = $(wildcard $(foreach dir,$(HEADER_DIRS),$(dir)/*.h)) 213 | $(C_OBJS) $(C_PIC_OBJS) $(C_JET_OBJS) $(CXX_OBJS) $(CXX_PIC_OBJS) $(CXX_JET_OBJS) : $(HEADERS) 214 | endif 215 | 216 | $(C_OBJS) $(C_PIC_OBJS) $(C_JET_OBJS) : %.$(O): 217 | @mkdir -p $(@D) 218 | $(CC) $(CCFLAGS) -c $(CTARGET) $< 219 | 220 | $(CXX_OBJS) $(CXX_PIC_OBJS) $(CXX_JET_OBJS) : %.$(O): 221 | @mkdir -p $(@D) 222 | $(CXX) $(CXXFLAGS) -c $(CTARGET) $< 223 | 224 | ifdef CC_MM 225 | @$(CXX) -MM $(CXXFLAGS) -MT $@ -o $(@:%.$(O)=%.d) $< 226 | endif 227 | 228 | ifneq ($(SOREV),$(SO)) 229 | %.$(SO) : %.$(SOREV) 230 | @mkdir -p $(@D) 231 | ln -sf $( 2 | 3 | 4 | 5 | 116 | 117 | -------------------------------------------------------------------------------- /RingQueue_Linux.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 114 | 115 | -------------------------------------------------------------------------------- /RingQueue_vc2008.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RingQueue", "projects\RingQueue\vc2008\RingQueue.vcproj", "{BB407950-C4DD-446C-A3FD-E2985DD83FD2}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Debug|Win32.Build.0 = Debug|Win32 14 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Release|Win32.ActiveCfg = Release|Win32 15 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /RingQueue_vc2010.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RingQueue", "projects\RingQueue\vc2010\RingQueue.vcxproj", "{BB407950-C4DD-446C-A3FD-E2985DD83FD2}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Debug|Win32.Build.0 = Debug|Win32 16 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Debug|x64.ActiveCfg = Debug|x64 17 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Debug|x64.Build.0 = Debug|x64 18 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Release|Win32.ActiveCfg = Release|Win32 19 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Release|Win32.Build.0 = Release|Win32 20 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Release|x64.ActiveCfg = Release|x64 21 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /RingQueue_vc2013.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30501.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RingQueue", "projects\RingQueue\vc2013\RingQueue.vcxproj", "{BB407950-C4DD-446C-A3FD-E2985DD83FD2}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release|Win32 = Release|Win32 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Debug|Win32.Build.0 = Debug|Win32 18 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Debug|x64.ActiveCfg = Debug|x64 19 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Debug|x64.Build.0 = Debug|x64 20 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Release|Win32.ActiveCfg = Release|Win32 21 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Release|Win32.Build.0 = Release|Win32 22 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Release|x64.ActiveCfg = Release|x64 23 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /RingQueue_vc2015.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30501.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RingQueue", "projects\RingQueue\vc2015\RingQueue.vcxproj", "{BB407950-C4DD-446C-A3FD-E2985DD83FD2}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release|Win32 = Release|Win32 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Debug|Win32.Build.0 = Debug|Win32 18 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Debug|x64.ActiveCfg = Debug|x64 19 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Debug|x64.Build.0 = Debug|x64 20 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Release|Win32.ActiveCfg = Release|Win32 21 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Release|Win32.Build.0 = Release|Win32 22 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Release|x64.ActiveCfg = Release|x64 23 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /_mktime32.txt: -------------------------------------------------------------------------------- 1 | _mktime32(tm) vs fast_mktime_v3(tm): 2 | 3 | [3665] -- year: 1970, month: 1, day: 1, hour: 5, minute: 18, second: 8 4 | [3665] -- timestamp1: 28799, timestamp2: 19088, diff: 9711 5 | 6 | [9066] -- year: 1970, month: 1, day: 1, hour: 3, minute: 9, second: 18 7 | [9066] -- timestamp1: 28799, timestamp2: 11358, diff: 17441 8 | -------------------------------------------------------------------------------- /build/ReadMe.txt: -------------------------------------------------------------------------------- 1 | This folder is the CMake build directory. 2 | -------------------------------------------------------------------------------- /cmake/ReadMe.txt: -------------------------------------------------------------------------------- 1 | This folder is the CMake modules directory. 2 | -------------------------------------------------------------------------------- /cmake/modules/DisplayComplierEnv.cmake: -------------------------------------------------------------------------------- 1 | function(DisplayCompilerEnvironment) 2 | if (JLANG_CMAKE_SHOW_DETAIL) 3 | message(STATUS "CMAKE_C_COMPILER_ID = ${CMAKE_C_COMPILER_ID}") 4 | message(STATUS "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}") 5 | message(STATUS "CMAKE_C_COMPILER_VERSION = ${CMAKE_C_COMPILER_VERSION}") 6 | message(STATUS "CMAKE_CXX_COMPILER_VERSION = ${CMAKE_CXX_COMPILER_VERSION}") 7 | message(STATUS "CMAKE_COMPILER_IS_GNUCC = ${CMAKE_COMPILER_IS_GNUCC}") 8 | message(STATUS "CMAKE_COMPILER_IS_GNUCXX = ${CMAKE_COMPILER_IS_GNUCXX}") 9 | message(STATUS "") 10 | 11 | message(STATUS "WIN32 = ${WIN32}") 12 | message(STATUS "MINGW = ${MINGW}") 13 | message(STATUS "CYGWIN = ${CYGWIN}") 14 | if (NOT JLANG_CMAKE_SHOW_MSVC_DETAIL) 15 | message(STATUS "MSVC = ${MSVC}") 16 | message(STATUS "MSVC_IDE = ${MSVC_IDE}") 17 | endif() 18 | message(STATUS "") 19 | endif() 20 | 21 | if (JLANG_CMAKE_SHOW_MSVC_DETAIL) 22 | if (MSVC_IDE) 23 | message(STATUS "MSVC = ${MSVC}") 24 | message(STATUS "MSVC_IDE = ${MSVC_IDE}") 25 | message(STATUS "MSVC60 = ${MSVC60}") 26 | message(STATUS "MSVC70 = ${MSVC70}") 27 | message(STATUS "MSVC71 = ${MSVC71}") 28 | message(STATUS "MSVC80 = ${MSVC80}") 29 | message(STATUS "MSVC90 = ${MSVC90}") 30 | message(STATUS "MSVC10 = ${MSVC10}") 31 | message(STATUS "MSVC11 = ${MSVC11}") 32 | message(STATUS "MSVC12 = ${MSVC12}") 33 | message(STATUS "MSVC13 = ${MSVC13}") 34 | message(STATUS "CMAKE_COMPILER_2005 = ${CMAKE_COMPILER_2005}") 35 | message(STATUS "MSVC_VERSION = ${MSVC_VERSION}") 36 | message(STATUS "") 37 | endif() 38 | endif() 39 | endfunction(DisplayCompilerEnvironment) 40 | -------------------------------------------------------------------------------- /cmake/modules/GetCompilerToolset.cmake: -------------------------------------------------------------------------------- 1 | 2 | function(get_c_compiler_id COMPILER_ID) 3 | if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") 4 | set(${COMPILER_ID} "gcc" PARENT_SCOPE) 5 | elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "clang") 6 | set(${COMPILER_ID} "clang" PARENT_SCOPE) 7 | elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel") 8 | set(${COMPILER_ID} "intel" PARENT_SCOPE) 9 | elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") 10 | set(${COMPILER_ID} "msvc" PARENT_SCOPE) 11 | # message(STATUS "get_c_compiler_id() msvc: COMPILER_ID = ${COMPILER_ID}") 12 | else() 13 | set(${COMPILER_ID} "" PARENT_SCOPE) 14 | # message(STATUS "get_c_compiler_id() unknown: COMPILER_ID = ${COMPILER_ID}") 15 | endif() 16 | endfunction(get_c_compiler_id) 17 | 18 | function(get_cxx_compiler_id COMPILER_ID) 19 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") 20 | set(${COMPILER_ID} "gcc" PARENT_SCOPE) 21 | elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "clang") 22 | set(${COMPILER_ID} "clang" PARENT_SCOPE) 23 | elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") 24 | set(${COMPILER_ID} "intel" PARENT_SCOPE) 25 | elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 26 | set(${COMPILER_ID} "msvc" PARENT_SCOPE) 27 | # message(STATUS "get_cxx_compiler_id() msvc: COMPILER_ID = ${COMPILER_ID}") 28 | else() 29 | set(${COMPILER_ID} "" PARENT_SCOPE) 30 | # message(STATUS "get_cxx_compiler_id() unknown: COMPILER_ID = ${COMPILER_ID}") 31 | endif() 32 | endfunction(get_cxx_compiler_id) 33 | 34 | function(get_compiler_id COMPILER_ID IS_C_OR_CXX) 35 | set(LOCAL_COMPILER_ID) 36 | if ((IS_C_OR_CXX STREQUAL "cxx") OR (IS_C_OR_CXX STREQUAL "cpp") OR (IS_C_OR_CXX STREQUAL "cc")) 37 | get_cxx_compiler_id(LOCAL_COMPILER_ID) 38 | else() 39 | get_c_compiler_id(LOCAL_COMPILER_ID) 40 | endif() 41 | # message(STATUS "get_compiler_id(): LOCAL_COMPILER_ID = ${LOCAL_COMPILER_ID}") 42 | set(${COMPILER_ID} "${LOCAL_COMPILER_ID}" PARENT_SCOPE) 43 | endfunction(get_compiler_id) 44 | 45 | function(GetCompilerToolset TOOLSET IS_C_OR_CXX) 46 | # message(STATUS "IS_C_OR_CXX = ${IS_C_OR_CXX}") 47 | set(LOCAL_COMPILER_ID) 48 | get_compiler_id(LOCAL_COMPILER_ID ${IS_C_OR_CXX}) 49 | if (JLANG_CMAKE_SHOW_DETAIL) 50 | message(STATUS "LOCAL_COMPILER_ID = ${LOCAL_COMPILER_ID}") 51 | endif() 52 | if (MSVC_IDE) 53 | if (MSVC60) 54 | set(${TOOLSET} "vc60" PARENT_SCOPE) 55 | elseif (MSVC70) 56 | set(${TOOLSET} "vc2003" PARENT_SCOPE) 57 | elseif (MSVC71) 58 | set(${TOOLSET} "vc2003" PARENT_SCOPE) 59 | elseif (MSVC80) 60 | set(${TOOLSET} "vc2005" PARENT_SCOPE) 61 | elseif (CMAKE_COMPILER_2005) 62 | set(${TOOLSET} "vc2005" PARENT_SCOPE) 63 | elseif (MSVC90) 64 | set(${TOOLSET} "vc2008" PARENT_SCOPE) 65 | elseif (MSVC10) 66 | set(${TOOLSET} "vc2010" PARENT_SCOPE) 67 | elseif (MSVC11) 68 | set(${TOOLSET} "vc2012" PARENT_SCOPE) 69 | elseif (MSVC12) 70 | set(${TOOLSET} "vc2013" PARENT_SCOPE) 71 | elseif (MSVC13) 72 | set(${TOOLSET} "vc2014" PARENT_SCOPE) 73 | else() 74 | if (NOT LOCAL_COMPILER_ID STREQUAL "") 75 | set(${TOOLSET} "${LOCAL_COMPILER_ID}" PARENT_SCOPE) 76 | else() 77 | set(${TOOLSET} "msvc" PARENT_SCOPE) 78 | endif() 79 | endif() 80 | elseif (MINGW) 81 | if (NOT LOCAL_COMPILER_ID STREQUAL "") 82 | set(${TOOLSET} "mingw_${LOCAL_COMPILER_ID}" PARENT_SCOPE) 83 | else() 84 | set(${TOOLSET} "mingw" PARENT_SCOPE) 85 | endif() 86 | elseif (CYGWIN) 87 | if (NOT LOCAL_COMPILER_ID STREQUAL "") 88 | set(${TOOLSET} "cygwin_${LOCAL_COMPILER_ID}" PARENT_SCOPE) 89 | else() 90 | set(${TOOLSET} "cygwin" PARENT_SCOPE) 91 | endif() 92 | elseif (BORLAND) 93 | if (NOT LOCAL_COMPILER_ID STREQUAL "") 94 | set(${TOOLSET} "borland_${LOCAL_COMPILER_ID}" PARENT_SCOPE) 95 | else() 96 | set(${TOOLSET} "borland" PARENT_SCOPE) 97 | endif() 98 | elseif (WATCOM) 99 | if (NOT LOCAL_COMPILER_ID STREQUAL "") 100 | set(${TOOLSET} "watcom_${LOCAL_COMPILER_ID}" PARENT_SCOPE) 101 | else() 102 | set(${TOOLSET} "watcom" PARENT_SCOPE) 103 | endif() 104 | else() 105 | set(${TOOLSET} "" PARENT_SCOPE) 106 | endif(MSVC_IDE) 107 | endfunction(GetCompilerToolset) 108 | -------------------------------------------------------------------------------- /disruptor/csharp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | using Disruptor.RingQueueTest; 9 | 10 | namespace Disruptor.RingQueueTest 11 | { 12 | class Program 13 | { 14 | static void Main(string[] args) 15 | { 16 | Console.WriteLine(""); 17 | Console.WriteLine("This is RingBufferPerfTest ..."); 18 | Console.WriteLine(""); 19 | 20 | nPnCRingQueueTest ringQueueTest = new nPnCRingQueueTest(); 21 | ringQueueTest.RunTest(); 22 | 23 | Thread.MemoryBarrier(); 24 | 25 | //Thread.Sleep(500); 26 | Console.Write("Press any key to continue ..."); 27 | Console.ReadKey(false); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /disruptor/csharp/Version.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Ce code a été généré par un outil. 4 | // Version du runtime :4.0.30319.488 5 | // 6 | // Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si 7 | // le code est régénéré. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System; 12 | using System.Reflection; 13 | using System.Runtime.CompilerServices; 14 | using System.Runtime.InteropServices; 15 | 16 | [assembly: AssemblyCompany("http://github.com/odeheurles/Disruptor-net/network")] 17 | [assembly: AssemblyProduct("Disruptor")] 18 | [assembly: AssemblyCopyright("Copyright © disruptor-net")] 19 | [assembly: AssemblyVersion("2.10.0")] 20 | [assembly: AssemblyFileVersion("2.10.0")] 21 | -------------------------------------------------------------------------------- /disruptor/java/RingBufferPerfTest.bat: -------------------------------------------------------------------------------- 1 | 2 | @echo off 3 | @echo on 4 | java -classpath .\build\classes\main;.\build\classes\perf;.\build\classes\test;.\lib\test\HdrHistogram.jar com.lmax.disruptor.queue.RingBufferPerfTest 5 | pause 6 | -------------------------------------------------------------------------------- /disruptor/java/RingBufferPerfTest2.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shines77/RingQueue/c785765b7a516c2c706ec1a1f5495bc4bd55d8ed/disruptor/java/RingBufferPerfTest2.java -------------------------------------------------------------------------------- /douban/a.c: -------------------------------------------------------------------------------- 1 | 2 | #define _GNU_SOURCE 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "q3.h" 11 | //#include "q.h" 12 | //#include "qlock.h" 13 | 14 | static struct msg *msgs; 15 | 16 | #define POP_CNT 7 17 | #define PUSH_CNT 7 18 | 19 | #define MSG_CNT (PUSH_CNT * 1000000) 20 | 21 | static inline uint64_t 22 | rdtsc(void) 23 | { 24 | union { 25 | uint64_t tsc_64; 26 | struct { 27 | uint32_t lo_32; 28 | uint32_t hi_32; 29 | }; 30 | } tsc; 31 | 32 | asm volatile("rdtsc" : 33 | "=a" (tsc.lo_32), 34 | "=d" (tsc.hi_32)); 35 | return tsc.tsc_64; 36 | } 37 | 38 | static volatile int quit = 0; 39 | static volatile int pop_total = 0; 40 | static volatile int push_total = 0; 41 | 42 | static volatile uint64_t push_cycles = 0; 43 | static volatile uint64_t pop_cycles = 0; 44 | 45 | 46 | static void * 47 | pop_task(void *arg) 48 | { 49 | struct queue *q = arg; 50 | uint64_t start = rdtsc(); 51 | int cnt = 0; 52 | 53 | while (!quit) 54 | cnt += !!pop(q); 55 | 56 | pop_cycles += rdtsc() - start; 57 | pop_total += cnt; 58 | 59 | return NULL; 60 | } 61 | 62 | static void * 63 | push_task(void *arg) 64 | { 65 | struct queue *q = arg; 66 | uint64_t start = rdtsc(); 67 | int i; 68 | 69 | for (i = 0; i < MSG_CNT / PUSH_CNT; i++) 70 | while (push(q, msgs + i) == -1); 71 | 72 | push_cycles += rdtsc() - start; 73 | push_total += MSG_CNT / PUSH_CNT; 74 | if (push_total == MSG_CNT) 75 | quit = 1; 76 | 77 | return NULL; 78 | } 79 | 80 | /* topology for Xeon E5-2670 Sandybridge */ 81 | static const int socket_top[] = { 82 | 1, 2, 3, 4, 5, 6, 7, 83 | 16, 17, 18, 19, 20, 21, 22, 23, 84 | 8, 9, 10, 11, 12, 13, 14, 15, 85 | 24, 25, 26, 27, 28, 29, 30, 31 86 | }; 87 | 88 | #define CORE_ID(i) socket_top[(i)] 89 | 90 | 91 | static int 92 | start_thread(int id, 93 | void *(*cb)(void *), 94 | void *arg, 95 | pthread_t *tid) 96 | { 97 | pthread_t kid; 98 | pthread_attr_t attr; 99 | cpu_set_t cpuset; 100 | int core_id; 101 | 102 | if (id < 0 || id >= sizeof(socket_top) / sizeof(int)) 103 | return -1; 104 | 105 | if (pthread_attr_init(&attr)) 106 | return -1; 107 | 108 | CPU_ZERO(&cpuset); 109 | core_id = CORE_ID(id); 110 | CPU_SET(core_id, &cpuset); 111 | 112 | if (pthread_create(&kid, &attr, cb, arg)) 113 | return -1; 114 | if (pthread_setaffinity_np(kid, sizeof(cpu_set_t), &cpuset)) 115 | return -1; 116 | 117 | if (tid) 118 | *tid = kid; 119 | 120 | return 0; 121 | } 122 | 123 | static int 124 | setaffinity(int core_id) 125 | { 126 | cpu_set_t cpuset; 127 | pthread_t me = pthread_self(); 128 | 129 | CPU_ZERO(&cpuset); 130 | CPU_SET(core_id, &cpuset); 131 | 132 | if (pthread_setaffinity_np(me, sizeof(cpu_set_t), &cpuset)) 133 | return -1; 134 | 135 | return 0; 136 | } 137 | 138 | int 139 | main(void) 140 | { 141 | struct queue *q = qinit(); 142 | int i; 143 | pthread_t kids[POP_CNT + PUSH_CNT]; 144 | 145 | setaffinity(0); 146 | 147 | msgs = calloc(MSG_CNT, sizeof(struct msg)); 148 | for (i = 0; i < POP_CNT; i++) 149 | start_thread(i, pop_task, q, &kids[i]); 150 | for (; i < POP_CNT + PUSH_CNT; i++) 151 | start_thread(i, push_task, q, &kids[i]); 152 | for (i = 0; i < POP_CNT + PUSH_CNT; i++) 153 | pthread_join(kids[i], NULL); 154 | 155 | printf("pop total: %d\n", pop_total); 156 | printf("pop cycles/msg: %lu\n", pop_cycles / pop_total); 157 | printf("push cycles/msg: %lu\n", push_cycles / MSG_CNT); 158 | 159 | return 0; 160 | } 161 | -------------------------------------------------------------------------------- /douban/a2.c: -------------------------------------------------------------------------------- 1 | 2 | #define _GNU_SOURCE 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "q3.h" 11 | //#include "q.h" 12 | //#include "qlock.h" 13 | 14 | static struct msg *msgs; 15 | 16 | 17 | #define POP_CNT 7 18 | #define PUSH_CNT 7 19 | 20 | #define MSG_CNT (PUSH_CNT * 1000000) 21 | 22 | static inline uint64_t 23 | rdtsc(void) 24 | { 25 | union { 26 | uint64_t tsc_64; 27 | struct { 28 | uint32_t lo_32; 29 | uint32_t hi_32; 30 | }; 31 | } tsc; 32 | 33 | asm volatile("rdtsc" : 34 | "=a" (tsc.lo_32), 35 | "=d" (tsc.hi_32)); 36 | return tsc.tsc_64; 37 | } 38 | 39 | static volatile int quit = 0; 40 | static volatile int pop_total = 0; 41 | static volatile int push_total = 0; 42 | 43 | static volatile uint64_t push_cycles = 0; 44 | static volatile uint64_t pop_cycles = 0; 45 | 46 | 47 | static void * 48 | pop_task(void *arg) 49 | { 50 | struct queue *q = arg; 51 | uint64_t start = rdtsc(); 52 | int cnt = 0; 53 | 54 | while (!quit) 55 | cnt += !!pop(q); 56 | 57 | pop_cycles += rdtsc() - start; 58 | pop_total += cnt; 59 | 60 | return NULL; 61 | } 62 | 63 | static void * 64 | pop_flush_task(void *arg) 65 | { 66 | struct queue *q = arg; 67 | uint64_t start = rdtsc(); 68 | 69 | while (!quit) { 70 | __sync_fetch_and_add(&pop_total, !!pop(q)); 71 | if (pop_total == MSG_CNT) 72 | quit = 1; 73 | } 74 | 75 | pop_cycles += rdtsc() - start; 76 | 77 | return NULL; 78 | } 79 | 80 | static void * 81 | push_task(void *arg) 82 | { 83 | struct queue *q = arg; 84 | uint64_t start = rdtsc(); 85 | int i; 86 | 87 | for (i = 0; i < MSG_CNT / PUSH_CNT; i++) 88 | while (push(q, msgs + i) == -1); 89 | 90 | push_cycles += rdtsc() - start; 91 | push_total += MSG_CNT / PUSH_CNT; 92 | if (push_total == MSG_CNT) 93 | quit = 1; 94 | 95 | return NULL; 96 | } 97 | 98 | /* topology for Xeon E5-2670 Sandybridge */ 99 | static const int socket_top[] = { 100 | 1, 2, 3, 4, 5, 6, 7, 101 | 16, 17, 18, 19, 20, 21, 22, 23, 102 | 8, 9, 10, 11, 12, 13, 14, 15, 103 | 24, 25, 26, 27, 28, 29, 30, 31 104 | }; 105 | 106 | #define CORE_ID(i) socket_top[(i)] 107 | 108 | static int 109 | start_thread(int id, 110 | void *(*cb)(void *), 111 | void *arg, 112 | pthread_t *tid) 113 | { 114 | pthread_t kid; 115 | pthread_attr_t attr; 116 | cpu_set_t cpuset; 117 | int core_id; 118 | 119 | if (id < 0 || id >= sizeof(socket_top) / sizeof(int)) 120 | return -1; 121 | 122 | if (pthread_attr_init(&attr)) 123 | return -1; 124 | 125 | CPU_ZERO(&cpuset); 126 | core_id = CORE_ID(id); 127 | CPU_SET(core_id, &cpuset); 128 | 129 | if (pthread_create(&kid, &attr, cb, arg)) 130 | return -1; 131 | if (pthread_setaffinity_np(kid, sizeof(cpu_set_t), &cpuset)) 132 | return -1; 133 | 134 | if (tid) 135 | *tid = kid; 136 | 137 | return 0; 138 | } 139 | 140 | static int 141 | setaffinity(int core_id) 142 | { 143 | cpu_set_t cpuset; 144 | pthread_t me = pthread_self(); 145 | 146 | CPU_ZERO(&cpuset); 147 | CPU_SET(core_id, &cpuset); 148 | 149 | if (pthread_setaffinity_np(me, sizeof(cpu_set_t), &cpuset)) 150 | return -1; 151 | 152 | return 0; 153 | } 154 | 155 | int 156 | main(void) 157 | { 158 | struct queue *q = qinit(); 159 | int i; 160 | pthread_t kids[POP_CNT + PUSH_CNT]; 161 | 162 | setaffinity(0); 163 | 164 | msgs = calloc(MSG_CNT, sizeof(struct msg)); 165 | for (i = 0; i < POP_CNT; i++) 166 | start_thread(i, pop_task, q, &kids[i]); 167 | for (; i < POP_CNT + PUSH_CNT; i++) 168 | start_thread(i, push_task, q, &kids[i]); 169 | for (i = 0; i < POP_CNT + PUSH_CNT; i++) 170 | pthread_join(kids[i], NULL); 171 | 172 | quit = 0; 173 | 174 | if (pop_total < MSG_CNT) { 175 | printf("flushing: %d\n", MSG_CNT - pop_total); 176 | for (i = 0; i < POP_CNT; i++) 177 | start_thread(i, pop_flush_task, q, &kids[i]); 178 | for (i = 0; i < POP_CNT; i++) 179 | pthread_join(kids[i], NULL); 180 | } 181 | 182 | printf("pop total: %d\n", pop_total); 183 | printf("pop cycles/msg: %lu\n", pop_cycles / pop_total); 184 | printf("push cycles/msg: %lu\n", push_cycles / MSG_CNT); 185 | 186 | return 0; 187 | } 188 | -------------------------------------------------------------------------------- /douban/a3.c: -------------------------------------------------------------------------------- 1 | 2 | #define _GNU_SOURCE 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "q3.h" 12 | //#include "q.h" 13 | //#include "qlock.h" 14 | 15 | static struct msg *msgs; 16 | static int *msg_flags; 17 | 18 | #define POP_CNT 7 19 | #define PUSH_CNT 7 20 | 21 | #define MSG_CNT (PUSH_CNT * 1000000) 22 | 23 | static inline uint64_t 24 | rdtsc(void) 25 | { 26 | union { 27 | uint64_t tsc_64; 28 | struct { 29 | uint32_t lo_32; 30 | uint32_t hi_32; 31 | }; 32 | } tsc; 33 | 34 | asm volatile("rdtsc" : 35 | "=a" (tsc.lo_32), 36 | "=d" (tsc.hi_32)); 37 | return tsc.tsc_64; 38 | } 39 | 40 | static volatile int quit = 0; 41 | static volatile int pop_total = 0; 42 | static volatile int push_total = 0; 43 | 44 | static volatile uint64_t push_cycles = 0; 45 | static volatile uint64_t pop_cycles = 0; 46 | 47 | #define delay(c) do { \ 48 | if ((c) == 0) break; \ 49 | uint64_t start = rdtsc(); \ 50 | uint64_t now = start; \ 51 | while (now - start < (c)) { \ 52 | _mm_pause(); \ 53 | now = rdtsc(); \ 54 | } \ 55 | } while (0) 56 | 57 | 58 | static void * 59 | pop_task(void *arg) 60 | { 61 | struct queue *q = arg; 62 | uint64_t start = rdtsc(); 63 | int cnt = 0; 64 | 65 | while (!quit) { 66 | struct msg *m = pop(q); 67 | if (m) { 68 | cnt++; 69 | msg_flags[(m - msgs)] = 1; 70 | } 71 | //delay(2000); 72 | } 73 | 74 | pop_cycles += rdtsc() - start; 75 | __sync_fetch_and_add(&pop_total, cnt); 76 | 77 | return NULL; 78 | } 79 | 80 | static void * 81 | pop_flush_task(void *arg) 82 | { 83 | struct queue *q = arg; 84 | uint64_t start = rdtsc(); 85 | 86 | while (!quit) { 87 | struct msg *m = pop(q); 88 | if (m) { 89 | __sync_fetch_and_add(&pop_total, 1); 90 | msg_flags[(m - msgs)] = 1; 91 | } 92 | if (pop_total == MSG_CNT) 93 | quit = 1; 94 | } 95 | 96 | pop_cycles += rdtsc() - start; 97 | 98 | return NULL; 99 | } 100 | 101 | static volatile int push_msg_idx = 0; 102 | 103 | static void * 104 | push_task(void *arg) 105 | { 106 | struct queue *q = arg; 107 | uint64_t start = rdtsc(); 108 | int i; 109 | 110 | for (i = 0; i < MSG_CNT / PUSH_CNT; i++) { 111 | int idx = __sync_fetch_and_add(&push_msg_idx, 1); 112 | while (push(q, msgs + idx) == -1); 113 | } 114 | 115 | push_cycles += rdtsc() - start; 116 | __sync_fetch_and_add(&push_total, MSG_CNT / PUSH_CNT); 117 | if (push_total == MSG_CNT) 118 | quit = 1; 119 | 120 | return NULL; 121 | } 122 | 123 | /* topology for Xeon E5-2670 Sandybridge */ 124 | static const int socket_top[] = { 125 | 1, 2, 3, 4, 5, 6, 7, 126 | 16, 17, 18, 19, 20, 21, 22, 23, 127 | 8, 9, 10, 11, 12, 13, 14, 15, 128 | 24, 25, 26, 27, 28, 29, 30, 31 129 | }; 130 | 131 | #define CORE_ID(i) socket_top[(i)] 132 | 133 | 134 | static int 135 | start_thread(int id, 136 | void *(*cb)(void *), 137 | void *arg, 138 | pthread_t *tid) 139 | { 140 | pthread_t kid; 141 | pthread_attr_t attr; 142 | cpu_set_t cpuset; 143 | int core_id; 144 | 145 | if (id < 0 || id >= sizeof(socket_top) / sizeof(int)) 146 | return -1; 147 | 148 | 149 | if (pthread_attr_init(&attr)) 150 | return -1; 151 | 152 | CPU_ZERO(&cpuset); 153 | core_id = CORE_ID(id); 154 | CPU_SET(core_id, &cpuset); 155 | 156 | if (pthread_create(&kid, &attr, cb, arg)) 157 | return -1; 158 | if (pthread_setaffinity_np(kid, sizeof(cpu_set_t), &cpuset)) 159 | return -1; 160 | 161 | if (tid) 162 | *tid = kid; 163 | 164 | return 0; 165 | } 166 | 167 | static int 168 | setaffinity(int core_id) 169 | { 170 | cpu_set_t cpuset; 171 | pthread_t me = pthread_self(); 172 | 173 | CPU_ZERO(&cpuset); 174 | CPU_SET(core_id, &cpuset); 175 | 176 | if (pthread_setaffinity_np(me, sizeof(cpu_set_t), &cpuset)) 177 | return -1; 178 | 179 | return 0; 180 | } 181 | 182 | int 183 | main(void) 184 | { 185 | struct queue *q = qinit(); 186 | int i; 187 | pthread_t kids[POP_CNT + PUSH_CNT]; 188 | 189 | setaffinity(0); 190 | 191 | msgs = calloc(MSG_CNT, sizeof(struct msg)); 192 | msg_flags = calloc(MSG_CNT, sizeof(int)); 193 | 194 | for (i = 0; i < POP_CNT; i++) 195 | start_thread(i, pop_task, q, &kids[i]); 196 | for (; i < POP_CNT + PUSH_CNT; i++) 197 | start_thread(i, push_task, q, &kids[i]); 198 | for (i = 0; i < POP_CNT + PUSH_CNT; i++) 199 | pthread_join(kids[i], NULL); 200 | 201 | quit = 0; 202 | 203 | if (pop_total < MSG_CNT) { 204 | printf("flushing: %d\n", MSG_CNT - pop_total); 205 | for (i = 0; i < POP_CNT; i++) 206 | start_thread(i, pop_flush_task, q, &kids[i]); 207 | for (i = 0; i < POP_CNT; i++) 208 | pthread_join(kids[i], NULL); 209 | } 210 | 211 | printf("pop total: %d\n", pop_total); 212 | printf("pop cycles/msg: %lu\n", pop_cycles / pop_total); 213 | printf("push cycles/msg: %lu\n", push_cycles / MSG_CNT); 214 | printf("push idx: %d\n", push_msg_idx); 215 | 216 | /* sanity test */ 217 | int miss = 0; 218 | for (i = 0; i < MSG_CNT; i++) { 219 | if (msg_flags[i] != 1) { 220 | miss++; 221 | } 222 | } 223 | printf("total %d miss\n", miss); 224 | 225 | return 0; 226 | } 227 | -------------------------------------------------------------------------------- /douban/mq.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define QSZ (1 << 10) 8 | #define QMSK (QSZ - 1) 9 | 10 | struct queue { 11 | volatile uint32_t head; 12 | volatile uint32_t tail; 13 | void * q[QSZ]; 14 | }; 15 | 16 | struct queue * 17 | queue_create() { 18 | struct queue * q = malloc(sizeof(*q)); 19 | memset(q, 0, sizeof(*q)); 20 | return q; 21 | } 22 | 23 | void * 24 | queue_push(struct queue *q, void *m) { 25 | uint32_t head, tail; 26 | do { 27 | tail = q->tail; 28 | // maybe we don't need memory fence in x86 29 | // __sync_synchronize(); 30 | head = q->head; 31 | if (head + QSZ == tail) { 32 | return NULL; 33 | } 34 | } while (!__sync_bool_compare_and_swap(&q->tail, tail, tail+1)); 35 | q->q[tail & QMSK] = m; 36 | 37 | return m; 38 | } 39 | 40 | void * 41 | queue_pop(struct queue *q) { 42 | uint32_t head, tail, masked; 43 | void * m; 44 | do { 45 | head = q->head; 46 | tail = q->tail; 47 | if (head == tail) { 48 | return NULL; 49 | } 50 | masked = head & QMSK; 51 | m = q->q[masked]; 52 | if (m == NULL) { 53 | return NULL; 54 | } 55 | } while (!__sync_bool_compare_and_swap(&q->q[masked], m, NULL)); 56 | q->head ++; 57 | return m; 58 | } 59 | -------------------------------------------------------------------------------- /douban/q.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | struct msg { 8 | struct msg *next; 9 | }; 10 | 11 | struct queue { 12 | uint32_t head; 13 | uint32_t tail; 14 | struct msg **msgs; 15 | struct msg *list; 16 | }; 17 | 18 | #define CNT 0x10000 19 | #define GP(x) (x % (CNT)) 20 | 21 | static inline struct queue * 22 | qinit(void) 23 | { 24 | struct queue *q = malloc(sizeof(*q)); 25 | 26 | bzero(q, sizeof(*q)); 27 | q->msgs = calloc(sizeof(struct msg *), CNT); 28 | 29 | return q; 30 | } 31 | 32 | static inline int 33 | push(struct queue *q, struct msg *m) 34 | { 35 | uint32_t tail = GP(__sync_fetch_and_add(&q->tail, 1)); 36 | 37 | if (!__sync_bool_compare_and_swap(&q->msgs[tail], NULL, m)) { 38 | struct msg *last; 39 | do { 40 | last = q->list; 41 | m->next = last; 42 | } while (!__sync_bool_compare_and_swap(&q->list, last, m)); 43 | } 44 | return 0; 45 | } 46 | 47 | static inline struct msg * 48 | pop(struct queue *q) 49 | { 50 | uint32_t head = q->head; 51 | uint32_t h2; 52 | struct msg *list; 53 | 54 | if (head == q->tail) 55 | return NULL; 56 | 57 | h2 = GP(head); 58 | list = q->list; 59 | 60 | if (list) { 61 | struct msg *n = list->next; 62 | if (__sync_bool_compare_and_swap(&q->list, list, n)) { 63 | list->next = NULL; 64 | push(q, list); 65 | } 66 | } 67 | struct msg *m = q->msgs[h2]; 68 | if (!m) 69 | return NULL; 70 | if (!__sync_bool_compare_and_swap(&q->head, head, head + 1)) 71 | return NULL; 72 | if (!__sync_bool_compare_and_swap(&q->msgs[h2], m, NULL)) 73 | return NULL; 74 | 75 | return m; 76 | } 77 | -------------------------------------------------------------------------------- /douban/q3.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #ifndef likely 7 | #define likely(x) __builtin_expect((x), 1) 8 | #endif 9 | 10 | #ifndef unlikely 11 | #define unlikely(x) __builtin_expect((x), 0) 12 | #endif 13 | 14 | 15 | #define QSZ (1024 * 1) 16 | #define QMSK (QSZ - 1) 17 | 18 | struct msg { 19 | uint64_t dummy; 20 | }; 21 | 22 | #define CACHE_LINE_SIZE 64 23 | 24 | struct queue { 25 | struct { 26 | uint32_t mask; 27 | uint32_t size; 28 | volatile uint32_t head; 29 | volatile uint32_t tail; 30 | } p; 31 | char pad[CACHE_LINE_SIZE - 4 * sizeof(uint32_t)]; 32 | 33 | struct { 34 | uint32_t mask; 35 | uint32_t size; 36 | volatile uint32_t head; 37 | volatile uint32_t tail; 38 | } c; 39 | char pad2[CACHE_LINE_SIZE - 4 * sizeof(uint32_t)]; 40 | 41 | void *msgs[0]; 42 | }; 43 | 44 | static inline struct queue * 45 | qinit(void) 46 | { 47 | struct queue *q = calloc(1, sizeof(*q) + QSZ * sizeof(void *)); 48 | q->p.size = q->c.size = QSZ; 49 | q->p.mask = q->c.mask = QMSK; 50 | 51 | return q; 52 | } 53 | 54 | 55 | static inline int 56 | push(struct queue *q, void *m) 57 | { 58 | uint32_t head, tail, mask, next; 59 | int ok; 60 | 61 | mask = q->p.mask; 62 | 63 | do { 64 | head = q->p.head; 65 | tail = q->c.tail; 66 | if ((mask + tail - head) < 1U) 67 | return -1; 68 | next = head + 1; 69 | ok = __sync_bool_compare_and_swap(&q->p.head, head, next); 70 | } while (!ok); 71 | 72 | q->msgs[head & mask] = m; 73 | asm volatile ("":::"memory"); 74 | 75 | while (unlikely((q->p.tail != head))) 76 | _mm_pause(); 77 | 78 | q->p.tail = next; 79 | 80 | return 0; 81 | } 82 | 83 | static inline void * 84 | pop(struct queue *q) 85 | { 86 | uint32_t head, tail, mask, next; 87 | int ok; 88 | void *ret; 89 | 90 | mask = q->c.mask; 91 | 92 | do { 93 | head = q->c.head; 94 | tail = q->p.tail; 95 | if ((tail - head) < 1U) 96 | return NULL; 97 | next = head + 1; 98 | ok = __sync_bool_compare_and_swap(&q->c.head, head, next); 99 | } while (!ok); 100 | 101 | ret = q->msgs[head & mask]; 102 | asm volatile ("":::"memory"); 103 | 104 | while (unlikely((q->c.tail != head))) 105 | _mm_pause(); 106 | 107 | q->c.tail = next; 108 | 109 | return ret; 110 | } 111 | -------------------------------------------------------------------------------- /douban/q3_new.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #ifndef likely 7 | #define likely(x) __builtin_expect((x), 1) 8 | #endif 9 | 10 | #ifndef unlikely 11 | #define unlikely(x) __builtin_expect((x), 0) 12 | #endif 13 | 14 | 15 | #define QSZ (1024 * 1) 16 | #define QMSK (QSZ - 1) 17 | 18 | struct msg { 19 | uint64_t dummy; 20 | }; 21 | 22 | #define CACHE_LINE_SIZE 64 23 | 24 | struct queue { 25 | struct { 26 | uint32_t mask; 27 | uint32_t size; 28 | volatile uint32_t first; 29 | volatile uint32_t second; 30 | } head; 31 | char pad1[CACHE_LINE_SIZE - 4 * sizeof(uint32_t)]; 32 | 33 | struct { 34 | uint32_t mask; 35 | uint32_t size; 36 | volatile uint32_t first; 37 | volatile uint32_t second; 38 | } tail; 39 | char pad2[CACHE_LINE_SIZE - 4 * sizeof(uint32_t)]; 40 | 41 | void *msgs[0]; 42 | }; 43 | 44 | static inline struct queue * 45 | qinit(void) 46 | { 47 | struct queue *q = calloc(1, sizeof(*q) + QSZ * sizeof(void *)); 48 | q->head.size = q->tail.size = QSZ; 49 | q->head.mask = q->tail.mask = QMSK; 50 | 51 | return q; 52 | } 53 | 54 | static inline int 55 | push(struct queue *q, void *m) 56 | { 57 | uint32_t head, tail, mask, next; 58 | int ok; 59 | 60 | mask = q->head.mask; 61 | 62 | do { 63 | head = q->head.first; 64 | tail = q->tail.second; 65 | //if ((mask + tail - head) < 1U) 66 | if ((head - tail) > mask) 67 | return -1; 68 | next = head + 1; 69 | ok = __sync_bool_compare_and_swap(&q->head.first, head, next); 70 | } while (!ok); 71 | 72 | q->msgs[head & mask] = m; 73 | asm volatile ("":::"memory"); 74 | 75 | while (unlikely((q->head.second != head))) 76 | _mm_pause(); 77 | 78 | q->head.second = next; 79 | 80 | return 0; 81 | } 82 | 83 | static inline void * 84 | pop(struct queue *q) 85 | { 86 | uint32_t tail, head, mask, next; 87 | int ok; 88 | void *ret; 89 | 90 | mask = q->tail.mask; 91 | 92 | do { 93 | tail = q->tail.first; 94 | head = q->head.second; 95 | //if ((head - tail) < 1U) 96 | if ((tail == head) || (tail > head && (head - tail) > mask)) 97 | return NULL; 98 | next = tail + 1; 99 | ok = __sync_bool_compare_and_swap(&q->tail.first, tail, next); 100 | } while (!ok); 101 | 102 | ret = q->msgs[tail & mask]; 103 | asm volatile ("":::"memory"); 104 | 105 | while (unlikely((q->tail.second != tail))) 106 | _mm_pause(); 107 | 108 | q->tail.second = next; 109 | 110 | return ret; 111 | } 112 | -------------------------------------------------------------------------------- /douban/qlock.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | struct msg { 5 | struct msg *next; 6 | }; 7 | 8 | struct queue { 9 | struct msg *head; 10 | struct msg *tail; 11 | int lock; 12 | }; 13 | 14 | #define LOCK(q) while (__sync_lock_test_and_set(&(q)->lock,1)) {} 15 | #define UNLOCK(q) __sync_lock_release(&(q)->lock); 16 | 17 | static inline struct queue * 18 | qinit(void) 19 | { 20 | struct queue *q = calloc(1, sizeof(*q)); 21 | return q; 22 | } 23 | 24 | static inline int 25 | push(struct queue *q, struct msg *m) 26 | { 27 | LOCK(q) 28 | if (q->tail) { 29 | q->tail->next = m; 30 | q->tail = m; 31 | } else { 32 | q->head = q->tail = m; 33 | } 34 | UNLOCK(q) 35 | 36 | return 0; 37 | } 38 | 39 | static inline struct msg * 40 | pop(struct queue *q) 41 | { 42 | struct msg *m; 43 | 44 | LOCK(q) 45 | m = q->head; 46 | if (m) { 47 | q->head = m->next; 48 | if (q->head == NULL) { 49 | q->tail = NULL; 50 | } 51 | m->next = NULL; 52 | } 53 | UNLOCK(q) 54 | 55 | return m; 56 | } 57 | -------------------------------------------------------------------------------- /include/RingQueue/Attributes.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * See: https://searchfox.org/mozilla-central/source/mfbt/Attributes.h 4 | * 5 | */ 6 | 7 | #ifndef JIMI_ATTRIBUTES_H 8 | #define JIMI_ATTRIBUTES_H 9 | 10 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 11 | #pragma once 12 | #endif 13 | 14 | /* 15 | * JIMI_ALWAYS_INLINE is a macro which expands to tell the compiler that the 16 | * method decorated with it must be inlined, even if the compiler thinks 17 | * otherwise. This is only a (much) stronger version of the inline hint: 18 | * compilers are not guaranteed to respect it (although they're much more likely 19 | * to do so). 20 | * 21 | * The JIMI_ALWAYS_INLINE_EVEN_DEBUG macro is yet stronger. It tells the 22 | * compiler to inline even in DEBUG builds. It should be used very rarely. 23 | */ 24 | #if defined(_MSC_VER) 25 | # define JIMI_ALWAYS_INLINE_EVEN_DEBUG __forceinline 26 | #elif defined(__GNUC__) || defined(__clang__) 27 | # define JIMI_ALWAYS_INLINE_EVEN_DEBUG __attribute__((always_inline)) inline 28 | #else 29 | # define JIMI_ALWAYS_INLINE_EVEN_DEBUG inline 30 | #endif 31 | 32 | #if !defined(DEBUG) 33 | # define JIMI_ALWAYS_INLINE JIMI_ALWAYS_INLINE_EVEN_DEBUG 34 | #elif defined(_MSC_VER) && !defined(__cplusplus) 35 | # define JIMI_ALWAYS_INLINE __inline 36 | #else 37 | # define JIMI_ALWAYS_INLINE inline 38 | #endif 39 | 40 | #if defined(_MSC_VER) 41 | /* 42 | * g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality 43 | * without warnings (functionality used by the macros below). These modes are 44 | * detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or, more 45 | * standardly, by checking whether __cplusplus has a C++11 or greater value. 46 | * Current versions of g++ do not correctly set __cplusplus, so we check both 47 | * for forward compatibility. 48 | */ 49 | # define JIMI_HAVE_NEVER_INLINE __declspec(noinline) 50 | # define JIMI_HAVE_NORETURN __declspec(noreturn) 51 | #elif defined(__clang__) 52 | /* 53 | * Per Clang documentation, "Note that marketing version numbers should not 54 | * be used to check for language features, as different vendors use different 55 | * numbering schemes. Instead, use the feature checking macros." 56 | */ 57 | # ifndef __has_extension 58 | # define __has_extension \ 59 | __has_feature /* compatibility, for older versions of clang */ 60 | # endif 61 | # if __has_attribute(noinline) 62 | # define JIMI_HAVE_NEVER_INLINE __attribute__((noinline)) 63 | # endif 64 | # if __has_attribute(noreturn) 65 | # define JIMI_HAVE_NORETURN __attribute__((noreturn)) 66 | # endif 67 | #elif defined(__GNUC__) 68 | # define JIMI_HAVE_NEVER_INLINE __attribute__((noinline)) 69 | # define JIMI_HAVE_NORETURN __attribute__((noreturn)) 70 | # define JIMI_HAVE_NORETURN_PTR __attribute__((noreturn)) 71 | #endif 72 | 73 | /* 74 | * When built with clang analyzer (a.k.a scan-build), define JIMI_HAVE_NORETURN 75 | * to mark some false positives 76 | */ 77 | #ifdef __clang_analyzer__ 78 | # if __has_extension(attribute_analyzer_noreturn) 79 | # define JIMI_HAVE_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) 80 | # endif 81 | #endif 82 | 83 | /* 84 | * JIMI_NEVER_INLINE is a macro which expands to tell the compiler that the 85 | * method decorated with it must never be inlined, even if the compiler would 86 | * otherwise choose to inline the method. Compilers aren't absolutely 87 | * guaranteed to support this, but most do. 88 | */ 89 | #if defined(JIMI_HAVE_NEVER_INLINE) 90 | # define JIMI_NEVER_INLINE JIMI_HAVE_NEVER_INLINE 91 | #else 92 | # define JIMI_NEVER_INLINE /* no support */ 93 | #endif 94 | 95 | /* 96 | * JIMI_NEVER_INLINE_DEBUG is a macro which expands to JIMI_NEVER_INLINE 97 | * in debug builds, and nothing in opt builds. 98 | */ 99 | #if defined(DEBUG) 100 | # define JIMI_NEVER_INLINE_DEBUG JIMI_NEVER_INLINE 101 | #else 102 | # define JIMI_NEVER_INLINE_DEBUG /* don't inline in opt builds */ 103 | #endif 104 | /* 105 | * JIMI_NORETURN, specified at the start of a function declaration, indicates 106 | * that the given function does not return. (The function definition does not 107 | * need to be annotated.) 108 | * 109 | * JIMI_NORETURN void abort(const char* msg); 110 | * 111 | * This modifier permits the compiler to optimize code assuming a call to such a 112 | * function will never return. It also enables the compiler to avoid spurious 113 | * warnings about not initializing variables, or about any other seemingly-dodgy 114 | * operations performed after the function returns. 115 | * 116 | * There are two variants. The GCC version of NORETURN may be applied to a 117 | * function pointer, while for MSVC it may not. 118 | * 119 | * This modifier does not affect the corresponding function's linking behavior. 120 | */ 121 | #if defined(JIMI_HAVE_NORETURN) 122 | # define JIMI_NORETURN JIMI_HAVE_NORETURN 123 | #else 124 | # define JIMI_NORETURN /* no support */ 125 | #endif 126 | #if defined(JIMI_HAVE_NORETURN_PTR) 127 | # define JIMI_NORETURN_PTR JIMI_HAVE_NORETURN_PTR 128 | #else 129 | # define JIMI_NORETURN_PTR /* no support */ 130 | #endif 131 | 132 | // 133 | // inline & noinline 134 | // See: https://stackoverflow.com/questions/1474030/how-can-i-tell-gcc-not-to-inline-a-function 135 | // 136 | #ifdef __cplusplus 137 | # define JIMI_CRT_INLINE inline 138 | #else 139 | # if __GNUC_STDC_INLINE__ 140 | # define JIMI_CRT_INLINE extern inline __attribute__((__gnu_inline__)) 141 | # else 142 | # define JIMI_CRT_INLINE extern __inline__ 143 | # endif 144 | #endif 145 | 146 | /* JIMI_CRT_FORCEINLINE will be used when we have a function whose purpose is to return 147 | * the value of a similar function. This alias function will contain one line 148 | * of code. 149 | */ 150 | #define JIMI_CRT_FORCEINLINE JIMI_CRT_INLINE __attribute__((__always_inline__)) 151 | 152 | /** 153 | * jimi: for inline and noinline define 154 | */ 155 | #if defined(_MSC_VER) || defined(__INTEL_COMPILER) 156 | 157 | #define JIMI_INLINE __inline 158 | #define JIMI_FORCEINLINE __forceinline 159 | #define JIMI_RESTRICT __restrict 160 | #define JIMI_HAS_INLINE 1 161 | 162 | #elif defined(__GNUC__) || defined(__clang__) 163 | 164 | #define JIMI_INLINE inline 165 | #define JIMI_FORCEINLINE inline 166 | #define JIMI_RESTRICT __restrict 167 | #define JIMI_HAS_INLINE 1 168 | 169 | #else 170 | 171 | #define JIMI_INLINE inline 172 | #define JIMI_FORCEINLINE inline 173 | #define JIMI_RESTRICT /* no support */ 174 | #define JIMI_HAS_INLINE 1 175 | 176 | #endif 177 | 178 | #if defined(_MSC_VER) || defined(__INTEL_COMPILER) 179 | #define JIMI_NOINLINE __declspec(noinline) 180 | #define JIMI_NOINLINE_DECLARE(decl) __declspec(noinline) decl 181 | #elif (defined(__GNUC__) || defined(__clang__) || defined(__MINGW32__)) && __has_attribute(noinline) 182 | #define JIMI_NOINLINE __attribute__((noinline)) 183 | #define JIMI_NOINLINE_DECLARE(decl) decl __attribute__((noinline)) 184 | #else 185 | #define JIMI_NOINLINE /* no support */ 186 | #define JIMI_NOINLINE_DECLARE(decl) decl 187 | #endif 188 | 189 | #endif // JIMI_ATTRIBUTES_H 190 | -------------------------------------------------------------------------------- /include/RingQueue/DisruptorRingQueueEx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shines77/RingQueue/c785765b7a516c2c706ec1a1f5495bc4bd55d8ed/include/RingQueue/DisruptorRingQueueEx.h -------------------------------------------------------------------------------- /include/RingQueue/MessageEvent.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _JIMI_MESSAGE_EVENT_H_ 3 | #define _JIMI_MESSAGE_EVENT_H_ 4 | 5 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 6 | #pragma once 7 | #endif 8 | 9 | #include "vs_stdint.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | struct MessageEvent 16 | { 17 | uint64_t value; 18 | }; 19 | 20 | typedef struct MessageEvent MessageEvent; 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | // Class CValueEvent() use in C++ only 27 | #ifdef __cplusplus 28 | 29 | template 30 | class CValueEvent 31 | { 32 | private: 33 | T value; 34 | 35 | public: 36 | CValueEvent() : value(0) {} 37 | 38 | CValueEvent(const T & value_) : value(value_) {} 39 | 40 | #if 0 41 | // Copy constructor 42 | CValueEvent(const CValueEvent & src) : value(src.value) { 43 | // 44 | } 45 | #endif 46 | // Copy constructor 47 | CValueEvent(const volatile CValueEvent & src) : value(src.value) { 48 | // 49 | } 50 | 51 | #if 0 52 | #if 0 53 | // Copy assignment operator 54 | CValueEvent & operator = (const CValueEvent & rhs) { 55 | this->value = rhs.value; 56 | return *this; 57 | } 58 | #endif 59 | 60 | // Copy assignment operator 61 | CValueEvent & operator = (const volatile CValueEvent & rhs) { 62 | this->value = rhs.value; 63 | return *this; 64 | } 65 | #else 66 | #if 0 67 | // Copy assignment operator 68 | void operator = (const CValueEvent & rhs) { 69 | this->value = rhs.value; 70 | } 71 | #endif 72 | 73 | // Copy assignment operator 74 | void operator = (const volatile CValueEvent & rhs) { 75 | this->value = rhs.value; 76 | } 77 | #endif 78 | 79 | T getValue() const { 80 | return value; 81 | } 82 | 83 | void setValue(T newValue) { 84 | value = newValue; 85 | } 86 | 87 | // Read data from event 88 | void read(CValueEvent & event) const { 89 | event.value = this->value; 90 | } 91 | 92 | // Copy data from src 93 | void copy(const CValueEvent & src) { 94 | value = src.value; 95 | } 96 | 97 | // Update data from event 98 | void update(const CValueEvent & event) { 99 | this->value = event.value; 100 | } 101 | 102 | // Move the data reference only 103 | void move(CValueEvent & event) { 104 | // Do nothing! 105 | } 106 | 107 | //////////////////////////////////////////////////////////////////////////// 108 | // volatile operation 109 | //////////////////////////////////////////////////////////////////////////// 110 | 111 | // Read data from event 112 | void read(volatile CValueEvent & event) { 113 | event.value = this->value; 114 | } 115 | 116 | // Copy data from src 117 | void copy(const volatile CValueEvent & src) { 118 | value = src.value; 119 | } 120 | 121 | // Update data from event 122 | void update(const volatile CValueEvent & event) { 123 | this->value = event.value; 124 | } 125 | 126 | // Move the data reference only 127 | void move(volatile CValueEvent & event) { 128 | // Do nothing! 129 | } 130 | }; 131 | 132 | #endif /* __cplusplus */ 133 | 134 | #endif /* _JIMI_MESSAGE_EVENT_H_ */ 135 | -------------------------------------------------------------------------------- /include/RingQueue/RingQueue.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shines77/RingQueue/c785765b7a516c2c706ec1a1f5495bc4bd55d8ed/include/RingQueue/RingQueue.h -------------------------------------------------------------------------------- /include/RingQueue/SerialRingQueue.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _JIMI_UTIL_SERIALRINGQUEUE_H_ 3 | #define _JIMI_UTIL_SERIALRINGQUEUE_H_ 4 | 5 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 6 | #pragma once 7 | #endif 8 | 9 | #include "vs_stdint.h" 10 | #include "port.h" 11 | #include "sleep.h" 12 | 13 | #ifndef _MSC_VER 14 | #include 15 | #include "msvc/pthread.h" 16 | #else 17 | #include "msvc/pthread.h" 18 | #endif // !_MSC_VER 19 | 20 | #ifdef _MSC_VER 21 | #include // For _ReadWriteBarrier(), InterlockedCompareExchange() 22 | #endif // _MSC_VER 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | #include "dump_mem.h" 29 | 30 | namespace jimi { 31 | 32 | template 33 | class SerialRingQueue 34 | { 35 | public: 36 | typedef T item_type; 37 | typedef item_type value_type; 38 | typedef uint32_t size_type; 39 | typedef uint32_t sequence_type; 40 | typedef uint32_t index_type; 41 | typedef T * pointer; 42 | typedef const T * const_pointer; 43 | typedef T & reference; 44 | typedef const T & const_reference; 45 | 46 | public: 47 | static const bool kIsAllocOnHeap = true; 48 | static const size_type kCapacity = (size_type)JIMI_MAX(JIMI_ROUND_TO_POW2(Capacity), 2); 49 | static const index_type kMask = (index_type)(kCapacity - 1); 50 | 51 | public: 52 | SerialRingQueue(); 53 | ~SerialRingQueue(); 54 | 55 | public: 56 | index_type mask() const { return kMask; }; 57 | size_type capacity() const { return kCapacity; }; 58 | size_type length() const { return sizes(); }; 59 | size_type sizes() const; 60 | 61 | void init(); 62 | 63 | int push(T const & entry); 64 | int pop(T & entry); 65 | 66 | protected: 67 | sequence_type headSequence; 68 | sequence_type tailSequence; 69 | item_type * entries; 70 | }; 71 | 72 | template 73 | SerialRingQueue::SerialRingQueue() 74 | : headSequence(0) 75 | , tailSequence(0) 76 | , entries(NULL) 77 | { 78 | init(); 79 | } 80 | 81 | template 82 | SerialRingQueue::~SerialRingQueue() 83 | { 84 | Jimi_WriteCompilerBarrier(); 85 | 86 | // If the queue is allocated on system heap, release them. 87 | if (SerialRingQueue::kIsAllocOnHeap) { 88 | if (this->entries != NULL) { 89 | delete [] this->entries; 90 | this->entries = NULL; 91 | } 92 | } 93 | } 94 | 95 | template 96 | inline 97 | void SerialRingQueue::init() 98 | { 99 | value_type * newData = new T[kCapacity]; 100 | if (newData != NULL) { 101 | memset((void *)newData, 0, sizeof(value_type) * kCapacity); 102 | this->entries = newData; 103 | } 104 | } 105 | 106 | template 107 | inline 108 | typename SerialRingQueue::size_type 109 | SerialRingQueue::sizes() const 110 | { 111 | sequence_type head, tail; 112 | 113 | Jimi_ReadCompilerBarrier(); 114 | 115 | head = this->headSequence; 116 | tail = this->tailSequence; 117 | 118 | return (size_type)((head - tail) <= kMask) ? (head - tail) : (size_type)(-1); 119 | } 120 | 121 | template 122 | int SerialRingQueue::push(T const & entry) 123 | { 124 | sequence_type head, tail, next; 125 | 126 | Jimi_ReadCompilerBarrier(); 127 | head = this->headSequence; 128 | tail = this->tailSequence; 129 | if ((head - tail) > kMask) { 130 | return -1; 131 | } 132 | 133 | Jimi_WriteCompilerBarrier(); 134 | #if 0 135 | this->entries[((index_type)head) & kMask] = entry; 136 | #else 137 | this->entries[head & (sequence_type)kMask] = entry; 138 | #endif 139 | 140 | next = head + 1; 141 | 142 | Jimi_WriteCompilerBarrier(); 143 | this->headSequence = next; 144 | 145 | return 0; 146 | } 147 | 148 | template 149 | int SerialRingQueue::pop(T & entry) 150 | { 151 | sequence_type head, tail, next; 152 | 153 | Jimi_ReadCompilerBarrier(); 154 | head = this->headSequence; 155 | tail = this->tailSequence; 156 | if ((tail == head) || (tail > head && (head - tail) > kMask)) { 157 | return -1; 158 | } 159 | 160 | Jimi_ReadCompilerBarrier(); 161 | #if 0 162 | entry = this->entries[((index_type)tail) & kMask)]; 163 | #else 164 | entry = this->entries[tail & (sequence_type)kMask]; 165 | #endif 166 | 167 | next = tail + 1; 168 | 169 | Jimi_CompilerBarrier(); 170 | this->tailSequence = next; 171 | 172 | return 0; 173 | } 174 | 175 | } /* namespace jimi */ 176 | 177 | #endif /* _JIMI_UTIL_SERIALRINGQUEUE_H_ */ 178 | -------------------------------------------------------------------------------- /include/RingQueue/SingleRingQueue.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _JIMI_UTIL_SINGLERINGQUEUE_H_ 3 | #define _JIMI_UTIL_SINGLERINGQUEUE_H_ 4 | 5 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 6 | #pragma once 7 | #endif 8 | 9 | #include "vs_stdint.h" 10 | #include "port.h" 11 | #include "sleep.h" 12 | 13 | #ifndef _MSC_VER 14 | #include 15 | #include "msvc/pthread.h" 16 | #else 17 | #include "msvc/pthread.h" 18 | #endif // !_MSC_VER 19 | 20 | #ifdef _MSC_VER 21 | #include // For _ReadWriteBarrier(), InterlockedCompareExchange() 22 | #endif // _MSC_VER 23 | #include 24 | 25 | #include "Sequence.h" 26 | 27 | #include 28 | #include 29 | 30 | #include "dump_mem.h" 31 | 32 | namespace jimi { 33 | 34 | template 35 | class SingleRingQueue 36 | { 37 | public: 38 | typedef T item_type; 39 | typedef item_type value_type; 40 | typedef uint32_t size_type; 41 | typedef SequenceType sequence_type; 42 | typedef uint32_t index_type; 43 | typedef SequenceBase Sequence; 44 | typedef T * pointer; 45 | typedef const T * const_pointer; 46 | typedef T & reference; 47 | typedef const T & const_reference; 48 | 49 | public: 50 | static const bool kIsAllocOnHeap = true; 51 | static const size_type kCapacity = (size_type)JIMI_MAX(JIMI_ROUND_TO_POW2(Capacity), 2); 52 | static const index_type kMask = (index_type)(kCapacity - 1); 53 | 54 | public: 55 | SingleRingQueue(); 56 | ~SingleRingQueue(); 57 | 58 | public: 59 | index_type mask() const { return kMask; }; 60 | size_type capacity() const { return kCapacity; }; 61 | size_type length() const { return sizes(); }; 62 | size_type sizes() const; 63 | 64 | void init(); 65 | 66 | int push(T const & entry); 67 | int pop(T & entry); 68 | 69 | protected: 70 | Sequence headSequence; 71 | Sequence tailSequence; 72 | item_type * entries; 73 | }; 74 | 75 | template 76 | SingleRingQueue::SingleRingQueue() 77 | : headSequence(0) 78 | , tailSequence(0) 79 | , entries(NULL) 80 | { 81 | init(); 82 | } 83 | 84 | template 85 | SingleRingQueue::~SingleRingQueue() 86 | { 87 | Jimi_WriteCompilerBarrier(); 88 | 89 | // If the queue is allocated on system heap, release them. 90 | if (SingleRingQueue::kIsAllocOnHeap) { 91 | if (this->entries != NULL) { 92 | delete [] this->entries; 93 | this->entries = NULL; 94 | } 95 | } 96 | } 97 | 98 | template 99 | inline 100 | void SingleRingQueue::init() 101 | { 102 | value_type * newData = new T[kCapacity]; 103 | if (newData != NULL) { 104 | memset((void *)newData, 0, sizeof(value_type) * kCapacity); 105 | this->entries = newData; 106 | } 107 | } 108 | 109 | template 110 | inline 111 | typename SingleRingQueue::size_type 112 | SingleRingQueue::sizes() const 113 | { 114 | sequence_type head, tail; 115 | 116 | Jimi_ReadCompilerBarrier(); 117 | 118 | head = this->headSequence.get(); 119 | tail = this->tailSequence.get(); 120 | 121 | return (size_type)((head - tail) <= kMask) ? (head - tail) : (size_type)(-1); 122 | } 123 | 124 | template 125 | inline 126 | int SingleRingQueue::push(T const & entry) 127 | { 128 | sequence_type head, tail, next; 129 | 130 | head = this->headSequence.getOrder(); 131 | tail = this->tailSequence.getOrder(); 132 | if ((head - tail) > kMask) { 133 | return -1; 134 | } 135 | 136 | Jimi_CompilerBarrier(); 137 | #if 0 138 | this->entries[((index_type)head) & kMask] = entry; 139 | #else 140 | this->entries[head & (sequence_type)kMask] = entry; 141 | #endif 142 | 143 | next = head + 1; 144 | 145 | //Jimi_WriteMemoryBarrier(); 146 | Jimi_WriteCompilerBarrier(); 147 | this->headSequence.setOrder(next); 148 | 149 | return 0; 150 | } 151 | 152 | template 153 | inline 154 | int SingleRingQueue::pop(T & entry) 155 | { 156 | sequence_type head, tail, next; 157 | 158 | head = this->headSequence.getOrder(); 159 | tail = this->tailSequence.getOrder(); 160 | if ((tail == head) || (tail > head && (head - tail) > kMask)) { 161 | return -1; 162 | } 163 | 164 | Jimi_ReadCompilerBarrier(); 165 | #if 0 166 | entry = this->entries[((index_type)tail) & kMask]; 167 | #else 168 | entry = this->entries[tail & (sequence_type)kMask]; 169 | #endif 170 | 171 | next = tail + 1; 172 | 173 | //Jimi_MemoryBarrier(); 174 | Jimi_CompilerBarrier(); 175 | this->tailSequence.setOrder(next); 176 | 177 | return 0; 178 | } 179 | 180 | } /* namespace jimi */ 181 | 182 | #endif /* _JIMI_UTIL_SINGLERINGQUEUE_H_ */ 183 | -------------------------------------------------------------------------------- /include/RingQueue/SpinMutex.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shines77/RingQueue/c785765b7a516c2c706ec1a1f5495bc4bd55d8ed/include/RingQueue/SpinMutex.h -------------------------------------------------------------------------------- /include/RingQueue/console.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _JIMIC_SYSTEM_CONSOLE_H_ 3 | #define _JIMIC_SYSTEM_CONSOLE_H_ 4 | 5 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 6 | #pragma once 7 | #endif 8 | 9 | #include "vs_stdbool.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | void jimi_cpu_warmup(int delayTime); 16 | 17 | int jimi_console_readkey(bool enabledCpuWarmup, bool displayTips, 18 | bool echoInput); 19 | 20 | int jimi_console_readkeyln(bool enabledCpuWarmup, bool displayTips, 21 | bool echoInput); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif /* !_JIMIC_SYSTEM_CONSOLE_H_ */ 28 | -------------------------------------------------------------------------------- /include/RingQueue/dump_mem.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _RINGQUEUE_DUMP_MEM_H_ 3 | #define _RINGQUEUE_DUMP_MEM_H_ 4 | 5 | #include 6 | #include "vs_stdint.h" 7 | #include "vs_stdbool.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | void dump_memory(void *p, size_t size, bool alignedTo /* = false */, 14 | unsigned int alignment /* = 16 */, 15 | unsigned int extraHead /* = 0 */, 16 | unsigned int extraTail /* = 0 */); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif /* _RINGQUEUE_DUMP_MEM_H_ */ 23 | -------------------------------------------------------------------------------- /include/RingQueue/get_char.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _JIMIC_SYSTEM_GET_CHAR_H_ 3 | #define _JIMIC_SYSTEM_GET_CHAR_H_ 4 | 5 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 6 | #pragma once 7 | #endif 8 | 9 | /// 10 | /// 11 | /// What is equivalent to getch() & getche() in Linux? 12 | /// 13 | /// From: http://stackoverflow.com/questions/7469139/what-is-equivalent-to-getch-getche-in-linux 14 | /// 15 | /// 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | #if defined(__linux__) 22 | 23 | void init_terminal_os(int echo); 24 | void reset_terminal_os(void); 25 | 26 | /* Read 1 character - echo defines echo mode */ 27 | int jimi_getch_term(int echo); 28 | 29 | #endif /* __linux__ */ 30 | 31 | /* Read 1 character without echo */ 32 | int jimi_getch(void); 33 | 34 | /* Read 1 character with echo */ 35 | int jimi_getche(void); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif /* !_JIMIC_SYSTEM_GET_CHAR_H_ */ 42 | -------------------------------------------------------------------------------- /include/RingQueue/mq.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CLOUDWU_MQ_H_ 3 | #define _CLOUDWU_MQ_H_ 4 | 5 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 6 | #pragma once 7 | #endif 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | struct queue; 14 | 15 | struct queue *queue_create(); 16 | 17 | void *queue_push(struct queue *q, void *m); 18 | 19 | void *queue_pop(struct queue *q); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif /* !_CLOUDWU_MQ_H_ */ 26 | -------------------------------------------------------------------------------- /include/RingQueue/msvc/inttypes.h: -------------------------------------------------------------------------------- 1 | // ISO C9x compliant inttypes.h for Microsoft Visual Studio 2 | // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 3 | // 4 | // Copyright (c) 2006 Alexander Chemeris 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are met: 8 | // 9 | // 1. Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // 2. Redistributions in binary form must reproduce the above copyright 13 | // notice, this list of conditions and the following disclaimer in the 14 | // documentation and/or other materials provided with the distribution. 15 | // 16 | // 3. The name of the author may be used to endorse or promote products 17 | // derived from this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 22 | // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 | // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 | // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | /////////////////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef _MSC_VER // [ 33 | #error "Use this header only with Microsoft Visual C++ compilers!" 34 | #endif // _MSC_VER ] 35 | 36 | #ifndef _INTTYPES // [ 37 | #define _INTTYPES 38 | 39 | #if _MSC_VER > 1020 40 | #pragma once 41 | #endif 42 | 43 | #include "stdint.h" 44 | 45 | // 7.8 Format conversion of integer types 46 | 47 | typedef struct { 48 | intmax_t quot; 49 | intmax_t rem; 50 | } imaxdiv_t; 51 | 52 | // 7.8.1 Macros for format specifiers 53 | 54 | #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198 55 | 56 | #ifdef _WIN64 57 | # define __PRI64_PREFIX "l" 58 | # define __PRIPTR_PREFIX "l" 59 | #else 60 | # define __PRI64_PREFIX "ll" 61 | # define __PRIPTR_PREFIX 62 | #endif 63 | 64 | // The fprintf macros for signed integers are: 65 | #define PRId8 "d" 66 | #define PRIi8 "i" 67 | #define PRIdLEAST8 "d" 68 | #define PRIiLEAST8 "i" 69 | #define PRIdFAST8 "d" 70 | #define PRIiFAST8 "i" 71 | 72 | #define PRId16 "hd" 73 | #define PRIi16 "hi" 74 | #define PRIdLEAST16 "hd" 75 | #define PRIiLEAST16 "hi" 76 | #define PRIdFAST16 "hd" 77 | #define PRIiFAST16 "hi" 78 | 79 | #define PRId32 "d" 80 | #define PRIi32 "i" 81 | #define PRIdLEAST32 "d" 82 | #define PRIiLEAST32 "i" 83 | #define PRIdFAST32 "d" 84 | #define PRIiFAST32 "i" 85 | 86 | #define PRId64 __PRI64_PREFIX "d" 87 | #define PRIi64 __PRI64_PREFIX "i" 88 | #define PRIdLEAST64 __PRI64_PREFIX "d" 89 | #define PRIiLEAST64 __PRI64_PREFIX "i" 90 | #define PRIdFAST64 __PRI64_PREFIX "d" 91 | #define PRIiFAST64 __PRI64_PREFIX "i" 92 | 93 | #define PRIdMAX __PRI64_PREFIX "d" 94 | #define PRIiMAX __PRI64_PREFIX "i" 95 | 96 | #define PRIdPTR __PRIPTR_PREFIX "d" 97 | #define PRIiPTR __PRIPTR_PREFIX "i" 98 | 99 | // The fprintf macros for unsigned integers are: 100 | #define PRIo8 "o" 101 | #define PRIu8 "u" 102 | #define PRIx8 "x" 103 | #define PRIX8 "X" 104 | #define PRIoLEAST8 "o" 105 | #define PRIuLEAST8 "u" 106 | #define PRIxLEAST8 "x" 107 | #define PRIXLEAST8 "X" 108 | #define PRIoFAST8 "o" 109 | #define PRIuFAST8 "u" 110 | #define PRIxFAST8 "x" 111 | #define PRIXFAST8 "X" 112 | 113 | #define PRIo16 "ho" 114 | #define PRIu16 "hu" 115 | #define PRIx16 "hx" 116 | #define PRIX16 "hX" 117 | #define PRIoLEAST16 "ho" 118 | #define PRIuLEAST16 "hu" 119 | #define PRIxLEAST16 "hx" 120 | #define PRIXLEAST16 "hX" 121 | #define PRIoFAST16 "ho" 122 | #define PRIuFAST16 "hu" 123 | #define PRIxFAST16 "hx" 124 | #define PRIXFAST16 "hX" 125 | 126 | #define PRIo32 "o" 127 | #define PRIu32 "u" 128 | #define PRIx32 "x" 129 | #define PRIX32 "X" 130 | #define PRIoLEAST32 "o" 131 | #define PRIuLEAST32 "u" 132 | #define PRIxLEAST32 "x" 133 | #define PRIXLEAST32 "X" 134 | #define PRIoFAST32 "o" 135 | #define PRIuFAST32 "u" 136 | #define PRIxFAST32 "x" 137 | #define PRIXFAST32 "X" 138 | 139 | #define PRIo64 __PRI64_PREFIX "o" 140 | #define PRIu64 __PRI64_PREFIX "u" 141 | #define PRIx64 __PRI64_PREFIX "x" 142 | #define PRIX64 __PRI64_PREFIX "X" 143 | #define PRIoLEAST64 __PRI64_PREFIX "o" 144 | #define PRIuLEAST64 __PRI64_PREFIX "u" 145 | #define PRIxLEAST64 __PRI64_PREFIX "x" 146 | #define PRIXLEAST64 __PRI64_PREFIX "X" 147 | #define PRIoFAST64 __PRI64_PREFIX "o" 148 | #define PRIuFAST64 __PRI64_PREFIX "u" 149 | #define PRIxFAST64 __PRI64_PREFIX "x" 150 | #define PRIXFAST64 __PRI64_PREFIX "X" 151 | 152 | #define PRIoMAX __PRI64_PREFIX "o" 153 | #define PRIuMAX __PRI64_PREFIX "u" 154 | #define PRIxMAX __PRI64_PREFIX "x" 155 | #define PRIXMAX __PRI64_PREFIX "X" 156 | 157 | #define PRIoPTR __PRIPTR_PREFIX "o" 158 | #define PRIuPTR __PRIPTR_PREFIX "u" 159 | #define PRIxPTR __PRIPTR_PREFIX "x" 160 | #define PRIXPTR __PRIPTR_PREFIX "X" 161 | 162 | // The fscanf macros for signed integers are: 163 | #define SCNd8 "d" 164 | #define SCNi8 "i" 165 | #define SCNdLEAST8 "d" 166 | #define SCNiLEAST8 "i" 167 | #define SCNdFAST8 "d" 168 | #define SCNiFAST8 "i" 169 | 170 | #define SCNd16 "hd" 171 | #define SCNi16 "hi" 172 | #define SCNdLEAST16 "hd" 173 | #define SCNiLEAST16 "hi" 174 | #define SCNdFAST16 "hd" 175 | #define SCNiFAST16 "hi" 176 | 177 | #define SCNd32 "ld" 178 | #define SCNi32 "li" 179 | #define SCNdLEAST32 "ld" 180 | #define SCNiLEAST32 "li" 181 | #define SCNdFAST32 "ld" 182 | #define SCNiFAST32 "li" 183 | 184 | #define SCNd64 "I64d" 185 | #define SCNi64 "I64i" 186 | #define SCNdLEAST64 "I64d" 187 | #define SCNiLEAST64 "I64i" 188 | #define SCNdFAST64 "I64d" 189 | #define SCNiFAST64 "I64i" 190 | 191 | #define SCNdMAX "I64d" 192 | #define SCNiMAX "I64i" 193 | 194 | #ifdef _WIN64 // [ 195 | # define SCNdPTR "I64d" 196 | # define SCNiPTR "I64i" 197 | #else // _WIN64 ][ 198 | # define SCNdPTR "ld" 199 | # define SCNiPTR "li" 200 | #endif // _WIN64 ] 201 | 202 | // The fscanf macros for unsigned integers are: 203 | #define SCNo8 "o" 204 | #define SCNu8 "u" 205 | #define SCNx8 "x" 206 | #define SCNX8 "X" 207 | #define SCNoLEAST8 "o" 208 | #define SCNuLEAST8 "u" 209 | #define SCNxLEAST8 "x" 210 | #define SCNXLEAST8 "X" 211 | #define SCNoFAST8 "o" 212 | #define SCNuFAST8 "u" 213 | #define SCNxFAST8 "x" 214 | #define SCNXFAST8 "X" 215 | 216 | #define SCNo16 "ho" 217 | #define SCNu16 "hu" 218 | #define SCNx16 "hx" 219 | #define SCNX16 "hX" 220 | #define SCNoLEAST16 "ho" 221 | #define SCNuLEAST16 "hu" 222 | #define SCNxLEAST16 "hx" 223 | #define SCNXLEAST16 "hX" 224 | #define SCNoFAST16 "ho" 225 | #define SCNuFAST16 "hu" 226 | #define SCNxFAST16 "hx" 227 | #define SCNXFAST16 "hX" 228 | 229 | #define SCNo32 "lo" 230 | #define SCNu32 "lu" 231 | #define SCNx32 "lx" 232 | #define SCNX32 "lX" 233 | #define SCNoLEAST32 "lo" 234 | #define SCNuLEAST32 "lu" 235 | #define SCNxLEAST32 "lx" 236 | #define SCNXLEAST32 "lX" 237 | #define SCNoFAST32 "lo" 238 | #define SCNuFAST32 "lu" 239 | #define SCNxFAST32 "lx" 240 | #define SCNXFAST32 "lX" 241 | 242 | #define SCNo64 "I64o" 243 | #define SCNu64 "I64u" 244 | #define SCNx64 "I64x" 245 | #define SCNX64 "I64X" 246 | #define SCNoLEAST64 "I64o" 247 | #define SCNuLEAST64 "I64u" 248 | #define SCNxLEAST64 "I64x" 249 | #define SCNXLEAST64 "I64X" 250 | #define SCNoFAST64 "I64o" 251 | #define SCNuFAST64 "I64u" 252 | #define SCNxFAST64 "I64x" 253 | #define SCNXFAST64 "I64X" 254 | 255 | #define SCNoMAX "I64o" 256 | #define SCNuMAX "I64u" 257 | #define SCNxMAX "I64x" 258 | #define SCNXMAX "I64X" 259 | 260 | #ifdef _WIN64 // [ 261 | # define SCNoPTR "I64o" 262 | # define SCNuPTR "I64u" 263 | # define SCNxPTR "I64x" 264 | # define SCNXPTR "I64X" 265 | #else // _WIN64 ][ 266 | # define SCNoPTR "lo" 267 | # define SCNuPTR "lu" 268 | # define SCNxPTR "lx" 269 | # define SCNXPTR "lX" 270 | #endif // _WIN64 ] 271 | 272 | #endif // __STDC_FORMAT_MACROS ] 273 | 274 | // 7.8.2 Functions for greatest-width integer types 275 | 276 | // 7.8.2.1 The imaxabs function 277 | #define imaxabs _abs64 278 | 279 | // 7.8.2.2 The imaxdiv function 280 | 281 | // This is modified version of div() function from Microsoft's div.c found 282 | // in %MSVC.NET%\crt\src\div.c 283 | #ifdef STATIC_IMAXDIV // [ 284 | static 285 | #else // STATIC_IMAXDIV ][ 286 | _inline 287 | #endif // STATIC_IMAXDIV ] 288 | imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) 289 | { 290 | imaxdiv_t result; 291 | 292 | result.quot = numer / denom; 293 | result.rem = numer % denom; 294 | 295 | if (numer < 0 && result.rem > 0) { 296 | // did division wrong; must fix up 297 | ++result.quot; 298 | result.rem -= denom; 299 | } 300 | 301 | return result; 302 | } 303 | 304 | // 7.8.2.3 The strtoimax and strtoumax functions 305 | #define strtoimax _strtoi64 306 | #define strtoumax _strtoui64 307 | 308 | // 7.8.2.4 The wcstoimax and wcstoumax functions 309 | #define wcstoimax _wcstoi64 310 | #define wcstoumax _wcstoui64 311 | 312 | #endif // _INTTYPES ] 313 | -------------------------------------------------------------------------------- /include/RingQueue/msvc/pthread.h: -------------------------------------------------------------------------------- 1 | 2 | #undef PTW32_API_HAVE_DEFINED 3 | #define PTW32_API_HAVE_DEFINED 0 4 | 5 | #if !(defined(PTHREAD_H) && defined(_PTHREAD_H)) 6 | 7 | #if defined(_MSC_VER) || defined(__INTEL_COMPILER) 8 | 9 | #ifndef _JIMIC_PTHREAD_H_ 10 | #define _JIMIC_PTHREAD_H_ 11 | 12 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 13 | #pragma once 14 | #endif 15 | 16 | #include "msvc/sched.h" 17 | #include "vs_stdint.h" 18 | 19 | #ifndef WIN32_LEAN_AND_MEAN 20 | #define WIN32_LEAN_AND_MEAN 21 | #endif 22 | 23 | #include "msvc/targetver.h" 24 | #include 25 | 26 | #define PTW32_INCLUDE_WINDOWS_H 27 | 28 | /* 29 | * The Open Watcom C/C++ compiler uses a non-standard calling convention 30 | * that passes function args in registers unless __cdecl is explicitly specified 31 | * in exposed function prototypes. 32 | * 33 | * We force all calls to cdecl even though this could slow Watcom code down 34 | * slightly. If you know that the Watcom compiler will be used to build both 35 | * the DLL and application, then you can probably define this as a null string. 36 | * Remember that pthread.h (this file) is used for both the DLL and application builds. 37 | */ 38 | #ifndef PTW32_CDECL 39 | #define PTW32_CDECL __cdecl 40 | #endif // PTW32_CDECL 41 | 42 | #undef PTW32_API 43 | 44 | #ifndef PTW32_API 45 | #define PTW32_API __stdcall 46 | #endif // PTW32_API 47 | 48 | #undef PTW32_API_HAVE_DEFINED 49 | #define PTW32_API_HAVE_DEFINED 1 50 | 51 | /* 52 | * To avoid including windows.h we define only those things that we 53 | * actually need from it. 54 | */ 55 | #if !defined(PTW32_INCLUDE_WINDOWS_H) 56 | #if !defined(HANDLE) 57 | # define PTW32__HANDLE_DEF 58 | # define HANDLE void * 59 | #endif 60 | #if !defined(DWORD) 61 | # define PTW32__DWORD_DEF 62 | # define DWORD unsigned long 63 | #endif 64 | #endif 65 | 66 | #ifdef __cplusplus 67 | extern "C" { 68 | #endif 69 | 70 | #if !defined(HAVE_STRUCT_TIMESPEC) 71 | #define HAVE_STRUCT_TIMESPEC 72 | #if !defined(_TIMESPEC_DEFINED) 73 | #include 74 | #define _TIMESPEC_DEFINED 75 | #if defined(_CRT_NO_TIME_T) 76 | struct timespec { 77 | time_t tv_sec; 78 | long tv_nsec; 79 | }; 80 | typedef struct timespec timespec_t; 81 | #endif /* !_CRT_NO_TIME_T for VC2015's time.h */ 82 | #endif /* !_TIMESPEC_DEFINED */ 83 | #endif /* !HAVE_STRUCT_TIMESPEC */ 84 | 85 | typedef HANDLE handle_t; 86 | 87 | typedef handle_t pthread_t; 88 | typedef handle_t pthread_attr_t; 89 | 90 | typedef CRITICAL_SECTION pthread_mutex_t; 91 | typedef handle_t pthread_mutexattr_t; 92 | 93 | typedef handle_t pthread_spinlock_t; 94 | typedef handle_t pthread_spinlock_attr_t; 95 | 96 | typedef void *(PTW32_API *lpthread_proc_t)(void *); 97 | typedef unsigned int (PTW32_API *pthread_proc_t)(void *); 98 | 99 | int PTW32_CDECL pthread_attr_init(pthread_attr_t * attr); 100 | int PTW32_CDECL pthread_attr_destroy(pthread_attr_t * attr); 101 | 102 | HANDLE PTW32_CDECL pthread_process_self(void); 103 | pthread_t PTW32_CDECL pthread_self(void); 104 | 105 | /* 106 | * PThread Functions 107 | */ 108 | int PTW32_CDECL pthread_create(pthread_t * tid, 109 | const pthread_attr_t * attr, 110 | void *(PTW32_API *start)(void *), 111 | void * arg); 112 | 113 | int PTW32_CDECL pthread_detach(pthread_t tid); 114 | 115 | int PTW32_CDECL pthread_join(pthread_t thread, void **value_ptr); 116 | 117 | /* 118 | * About the thread affinity 119 | */ 120 | int PTW32_CDECL pthread_getaffinity_np(pthread_t thread, size_t cpuset_size, 121 | cpu_set_t * cpuset); 122 | 123 | int PTW32_CDECL pthread_setaffinity_np(pthread_t thread, size_t cpuset_size, 124 | const cpu_set_t * cpuset); 125 | 126 | /* 127 | * Mutex Functions 128 | */ 129 | int PTW32_CDECL pthread_mutex_init(pthread_mutex_t * mutex, 130 | const pthread_mutexattr_t * attr); 131 | 132 | int PTW32_CDECL pthread_mutex_destroy(pthread_mutex_t * mutex); 133 | 134 | int PTW32_CDECL pthread_mutex_lock(pthread_mutex_t * mutex); 135 | 136 | int PTW32_CDECL pthread_mutex_timedlock(pthread_mutex_t * mutex, 137 | const struct timespec *abstime); 138 | 139 | int PTW32_CDECL pthread_mutex_trylock(pthread_mutex_t * mutex); 140 | 141 | int PTW32_CDECL pthread_mutex_unlock(pthread_mutex_t * mutex); 142 | 143 | int PTW32_CDECL pthread_mutex_consistent(pthread_mutex_t * mutex); 144 | 145 | /* 146 | * Spinlock Functions 147 | */ 148 | int PTW32_CDECL pthread_spin_init(pthread_spinlock_t * lock, int pshared); 149 | 150 | int PTW32_CDECL pthread_spin_destroy(pthread_spinlock_t * lock); 151 | 152 | int PTW32_CDECL pthread_spin_lock(pthread_spinlock_t * lock); 153 | 154 | int PTW32_CDECL pthread_spin_trylock(pthread_spinlock_t * lock); 155 | 156 | int PTW32_CDECL pthread_spin_unlock(pthread_spinlock_t * lock); 157 | 158 | #ifdef __cplusplus 159 | } 160 | #endif 161 | 162 | #endif /* !_JIMIC_PTHREAD_H_ */ 163 | 164 | #endif /* (defined(_MSC_VER) || defined(__INTEL_COMPILER)) */ 165 | 166 | #endif /* !(PTHREAD_H && _PTHREAD_H) */ 167 | 168 | #if (!defined(PTW32_API_HAVE_DEFINED)) || (PTW32_API_HAVE_DEFINED == 0) 169 | 170 | #ifndef PTW32_API 171 | #define PTW32_API 172 | #endif 173 | 174 | #if defined(__MINGW32__) || defined(__CYGWIN__) 175 | 176 | #ifndef PTW32_CDECL 177 | #define PTW32_CDECL __cdecl 178 | #endif // PTW32_CDECL 179 | 180 | #include "vs_stdint.h" 181 | #include "msvc/sched.h" 182 | 183 | #ifndef WIN32_LEAN_AND_MEAN 184 | #define WIN32_LEAN_AND_MEAN 185 | #endif 186 | 187 | #include "msvc/targetver.h" 188 | #include 189 | 190 | #ifdef __cplusplus 191 | extern "C" { 192 | #endif 193 | 194 | /* 195 | * About the thread affinity 196 | */ 197 | int PTW32_CDECL pthread_getaffinity_np(pthread_t thread, size_t cpuset_size, 198 | cpu_set_t * cpuset); 199 | 200 | int PTW32_CDECL pthread_setaffinity_np(pthread_t thread, size_t cpuset_size, 201 | const cpu_set_t * cpuset); 202 | 203 | #ifdef __cplusplus 204 | } 205 | #endif 206 | 207 | #endif /* defined(__MINGW32__) || defined(__CYGWIN__) */ 208 | 209 | #endif /* PTW32_API_HAVE_DEFINED */ 210 | -------------------------------------------------------------------------------- /include/RingQueue/msvc/sched.h: -------------------------------------------------------------------------------- 1 | 2 | #undef SCHW32_API_HAVE_DEFINED 3 | #define SCHW32_API_HAVE_DEFINED 0 4 | 5 | //#if !(defined(SCHED_H) && defined(_SCHED_H)) 6 | 7 | #if defined(_MSC_VER) || defined(__INTEL_COMPILER) || defined(__MINGW32__) || defined(__CYGWIN__) 8 | 9 | #ifndef _JIMIC_SCHED_H_ 10 | #define _JIMIC_SCHED_H_ 11 | 12 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 13 | #pragma once 14 | #endif 15 | 16 | #ifndef WIN32_LEAN_AND_MEAN 17 | #define WIN32_LEAN_AND_MEAN 18 | #endif 19 | 20 | #include "msvc/targetver.h" 21 | #include 22 | #define SCHW32_INCLUDE_WINDOWS_H 23 | 24 | /* 25 | * The Open Watcom C/C++ compiler uses a non-standard calling convention 26 | * that passes function args in registers unless __cdecl is explicitly specified 27 | * in exposed function prototypes. 28 | * 29 | * We force all calls to cdecl even though this could slow Watcom code down 30 | * slightly. If you know that the Watcom compiler will be used to build both 31 | * the DLL and application, then you can probably define this as a null string. 32 | * Remember that pthread.h (this file) is used for both the DLL and application builds. 33 | */ 34 | #ifndef SCHW32_CDECL 35 | #define SCHW32_CDECL __cdecl 36 | #endif // SCHW32_CDECL 37 | 38 | #undef SCHW32_API 39 | 40 | #ifndef SCHW32_API 41 | #define SCHW32_API __stdcall 42 | #endif // SCHW32_API 43 | 44 | #undef SCHW32_API_HAVE_DEFINED 45 | #define SCHW32_API_HAVE_DEFINED 1 46 | 47 | /* 48 | * To avoid including windows.h we define only those things that we 49 | * actually need from it. 50 | */ 51 | #if !defined(SCHW32_INCLUDE_WINDOWS_H) 52 | #if !defined(HANDLE) 53 | # define PTW32__HANDLE_DEF 54 | # define HANDLE void * 55 | #endif 56 | #if !defined(DWORD) 57 | # define PTW32__DWORD_DEF 58 | # define DWORD unsigned long 59 | #endif 60 | #endif 61 | 62 | #include "vs_stdint.h" 63 | 64 | /// 65 | /// 66 | /// See: http://www.cnblogs.com/lovevivi/archive/2012/11/16/2773325.html 67 | /// 68 | /// 69 | 70 | #ifndef CPU_ZERO 71 | #define CPU_ZERO(cpuset) schw32_cpu_zero((cpuset)) 72 | #endif /* CPU_ZERO */ 73 | 74 | #ifndef CPU_SET 75 | #define CPU_SET(cpuid, cpuset) schw32_cpu_set((cpuid), (cpuset)) 76 | #endif /* CPU_SET */ 77 | 78 | #ifndef CPU_CLR 79 | #define CPU_CLR(cpuid, cpuset) schw32_cpu_clear((cpuid), (cpuset)) 80 | #endif /* CPU_CLR */ 81 | 82 | #ifndef CPU_ISSET 83 | #define CPU_ISSET(cpuid, cpuset) schw32_cpu_isset((cpuid), (cpuset)) 84 | #endif /* CPU_ISSET */ 85 | 86 | #ifdef __cplusplus 87 | extern "C" { 88 | #endif 89 | 90 | #if 1 91 | struct cpu_set_s { 92 | uint32_t mask; 93 | }; 94 | #else 95 | struct cpu_set_s { 96 | uint64_t mask; 97 | }; 98 | #endif 99 | 100 | typedef struct cpu_set_s cpu_set_t; 101 | 102 | /* 103 | * Set the CPU masks 104 | */ 105 | void SCHW32_CDECL schw32_cpu_zero(cpu_set_t *cpuset); 106 | 107 | void SCHW32_CDECL schw32_cpu_set(int cpuid, cpu_set_t *cpuset); 108 | 109 | void SCHW32_CDECL schw32_cpu_clear(int cpuid, cpu_set_t *cpuset); 110 | 111 | int SCHW32_CDECL schw32_cpu_isset(int cpuid, const cpu_set_t *cpuset); 112 | 113 | #ifdef __cplusplus 114 | } 115 | #endif 116 | 117 | #endif /* !_JIMIC_SCHED_H_ */ 118 | 119 | #endif /* (defined(_MSC_VER) || defined(__INTEL_COMPILER) || defined(__MINGW32__) || defined(__CYGWIN__)) */ 120 | 121 | //#endif /* !(SCHED_H && _SCHED_H) */ 122 | 123 | #if (!defined(SCHW32_API_HAVE_DEFINED)) || (SCHW32_API_HAVE_DEFINED == 0) 124 | 125 | #ifndef SCHW32_API 126 | #define SCHW32_API 127 | #endif 128 | 129 | #endif /* PTW32_API_HAVE_DEFINED */ 130 | -------------------------------------------------------------------------------- /include/RingQueue/msvc/stdbool.h: -------------------------------------------------------------------------------- 1 | /* stdbool.h standard header */ 2 | 3 | #ifndef _STDBOOL 4 | #define _STDBOOL 5 | 6 | /* MSVC doesn't define _Bool or bool in C, but does have BOOL */ 7 | /* Note this doesn't pass autoconf's test because (bool) 0.5 != true */ 8 | #if defined(_MSC_VER) && (_MSC_VER < 1700) 9 | #include 10 | #include 11 | 12 | typedef BOOL _Bool; 13 | #endif 14 | 15 | #if (defined(_MSC_VER) && (_MSC_VER < 1700)) 16 | 17 | #define __bool_true_false_are_defined 1 18 | 19 | #ifndef __cplusplus 20 | 21 | #define bool _Bool 22 | #define false 0 23 | #define true 1 24 | 25 | #endif /* __cplusplus */ 26 | 27 | #endif /* _MSC_VER */ 28 | 29 | #endif /* _STDBOOL */ 30 | 31 | /* 32 | * Copyright (c) 1992-2010 by P.J. Plauger. ALL RIGHTS RESERVED. 33 | * Consult your license regarding permissions and restrictions. 34 | V5.30:0009 */ 35 | -------------------------------------------------------------------------------- /include/RingQueue/msvc/stdint.h: -------------------------------------------------------------------------------- 1 | // ISO C9x compliant stdint.h for Microsoft Visual Studio 2 | // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 3 | // 4 | // Copyright (c) 2006-2008 Alexander Chemeris 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are met: 8 | // 9 | // 1. Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // 2. Redistributions in binary form must reproduce the above copyright 13 | // notice, this list of conditions and the following disclaimer in the 14 | // documentation and/or other materials provided with the distribution. 15 | // 16 | // 3. The name of the author may be used to endorse or promote products 17 | // derived from this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 22 | // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 | // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 | // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | /////////////////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef _MSC_VER // [ 33 | #error "Use this header only with Microsoft Visual C++ compilers!" 34 | #endif // _MSC_VER ] 35 | 36 | #if !defined(_STDINT) && !defined(_STDINT_H) // [ 37 | 38 | #ifndef _STDINT 39 | #define _STDINT 40 | #endif 41 | 42 | #ifndef _STDINT_H 43 | #define _STDINT_H 44 | #endif 45 | 46 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 47 | #pragma once 48 | #endif 49 | 50 | #ifndef RC_INVOKED 51 | 52 | #include 53 | #include 54 | 55 | // For Visual Studio 6 in C++ mode wrap include with 'extern "C++" {}' 56 | // or compiler give many errors like this: 57 | // error C2733: second C linkage of overloaded function 'wmemchr' not allowed 58 | #if (_MSC_VER < 1300) && defined(__cplusplus) 59 | extern "C++" { 60 | #endif 61 | #include 62 | #if (_MSC_VER < 1300) && defined(__cplusplus) 63 | } 64 | #endif 65 | 66 | // Define _W64 macros to mark types changing their size, like intptr_t. 67 | #ifndef _W64 68 | # if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 69 | # define _W64 __w64 70 | # else 71 | # define _W64 72 | # endif 73 | #endif 74 | 75 | 76 | // 7.18.1 Integer types 77 | 78 | // 7.18.1.1 Exact-width integer types 79 | typedef __int8 int8_t; 80 | typedef __int16 int16_t; 81 | typedef __int32 int32_t; 82 | typedef __int64 int64_t; 83 | typedef unsigned __int8 uint8_t; 84 | typedef unsigned __int16 uint16_t; 85 | typedef unsigned __int32 uint32_t; 86 | typedef unsigned __int64 uint64_t; 87 | 88 | typedef __int8 int8; 89 | typedef __int16 int16; 90 | typedef __int32 int32; 91 | typedef __int64 int64; 92 | typedef unsigned __int8 uint8; 93 | typedef unsigned __int16 uint16; 94 | typedef unsigned __int32 uint32; 95 | typedef unsigned __int64 uint64; 96 | 97 | typedef unsigned __int8 U8; 98 | typedef unsigned __int16 U16; 99 | typedef unsigned __int32 U32; 100 | typedef unsigned __int64 U64; 101 | 102 | // 7.18.1.2 Minimum-width integer types 103 | typedef int8_t int_least8_t; 104 | typedef int16_t int_least16_t; 105 | typedef int32_t int_least32_t; 106 | typedef int64_t int_least64_t; 107 | typedef uint8_t uint_least8_t; 108 | typedef uint16_t uint_least16_t; 109 | typedef uint32_t uint_least32_t; 110 | typedef uint64_t uint_least64_t; 111 | 112 | // 7.18.1.3 Fastest minimum-width integer types 113 | typedef int8_t int_fast8_t; 114 | typedef int16_t int_fast16_t; 115 | typedef int32_t int_fast32_t; 116 | typedef int64_t int_fast64_t; 117 | typedef uint8_t uint_fast8_t; 118 | typedef uint16_t uint_fast16_t; 119 | typedef uint32_t uint_fast32_t; 120 | typedef uint64_t uint_fast64_t; 121 | 122 | // 7.18.1.4 Integer types capable of holding object pointers 123 | #ifndef _INTPTR_T_DEFINED 124 | #define _INTPTR_T_DEFINED 125 | #ifdef _WIN64 126 | typedef __int64 intptr_t; 127 | #else /* _WIN64 */ 128 | typedef _W64 int intptr_t; 129 | #endif /* _WIN64 */ 130 | #endif /* _INTPTR_T_DEFINED */ 131 | 132 | #ifndef _UINTPTR_T_DEFINED 133 | #define _UINTPTR_T_DEFINED 134 | #ifdef _WIN64 135 | typedef unsigned __int64 uintptr_t; 136 | #else /* _WIN64 */ 137 | typedef _W64 unsigned int uintptr_t; 138 | #endif /* _WIN64 */ 139 | #endif /* _UINTPTR_T_DEFINED */ 140 | 141 | // 7.18.1.5 Greatest-width integer types 142 | typedef int64_t intmax_t; 143 | typedef uint64_t uintmax_t; 144 | 145 | 146 | // 7.18.2 Limits of specified-width integer types 147 | 148 | #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 149 | 150 | // 7.18.2.1 Limits of exact-width integer types 151 | #define INT8_MIN ((int8_t)_I8_MIN) 152 | #define INT8_MAX _I8_MAX 153 | #define INT16_MIN ((int16_t)_I16_MIN) 154 | #define INT16_MAX _I16_MAX 155 | #define INT32_MIN ((int32_t)_I32_MIN) 156 | #define INT32_MAX _I32_MAX 157 | #define INT64_MIN ((int64_t)_I64_MIN) 158 | #define INT64_MAX _I64_MAX 159 | #define UINT8_MAX _UI8_MAX 160 | #define UINT16_MAX _UI16_MAX 161 | #define UINT32_MAX _UI32_MAX 162 | #define UINT64_MAX _UI64_MAX 163 | 164 | // 7.18.2.2 Limits of minimum-width integer types 165 | #define INT_LEAST8_MIN INT8_MIN 166 | #define INT_LEAST8_MAX INT8_MAX 167 | #define INT_LEAST16_MIN INT16_MIN 168 | #define INT_LEAST16_MAX INT16_MAX 169 | #define INT_LEAST32_MIN INT32_MIN 170 | #define INT_LEAST32_MAX INT32_MAX 171 | #define INT_LEAST64_MIN INT64_MIN 172 | #define INT_LEAST64_MAX INT64_MAX 173 | #define UINT_LEAST8_MAX UINT8_MAX 174 | #define UINT_LEAST16_MAX UINT16_MAX 175 | #define UINT_LEAST32_MAX UINT32_MAX 176 | #define UINT_LEAST64_MAX UINT64_MAX 177 | 178 | // 7.18.2.3 Limits of fastest minimum-width integer types 179 | #define INT_FAST8_MIN INT8_MIN 180 | #define INT_FAST8_MAX INT8_MAX 181 | #define INT_FAST16_MIN INT16_MIN 182 | #define INT_FAST16_MAX INT16_MAX 183 | #define INT_FAST32_MIN INT32_MIN 184 | #define INT_FAST32_MAX INT32_MAX 185 | #define INT_FAST64_MIN INT64_MIN 186 | #define INT_FAST64_MAX INT64_MAX 187 | #define UINT_FAST8_MAX UINT8_MAX 188 | #define UINT_FAST16_MAX UINT16_MAX 189 | #define UINT_FAST32_MAX UINT32_MAX 190 | #define UINT_FAST64_MAX UINT64_MAX 191 | 192 | // 7.18.2.4 Limits of integer types capable of holding object pointers 193 | #ifdef _WIN64 // [ 194 | # define INTPTR_MIN INT64_MIN 195 | # define INTPTR_MAX INT64_MAX 196 | # define UINTPTR_MAX UINT64_MAX 197 | #else // _WIN64 ][ 198 | # define INTPTR_MIN INT32_MIN 199 | # define INTPTR_MAX INT32_MAX 200 | # define UINTPTR_MAX UINT32_MAX 201 | #endif // _WIN64 ] 202 | 203 | // 7.18.2.5 Limits of greatest-width integer types 204 | #define INTMAX_MIN INT64_MIN 205 | #define INTMAX_MAX INT64_MAX 206 | #define UINTMAX_MAX UINT64_MAX 207 | 208 | // 7.18.3 Limits of other integer types 209 | 210 | #ifdef _WIN64 // [ 211 | # define PTRDIFF_MIN _I64_MIN 212 | # define PTRDIFF_MAX _I64_MAX 213 | #else // _WIN64 ][ 214 | # define PTRDIFF_MIN _I32_MIN 215 | # define PTRDIFF_MAX _I32_MAX 216 | #endif // _WIN64 ] 217 | 218 | #define SIG_ATOMIC_MIN INT_MIN 219 | #define SIG_ATOMIC_MAX INT_MAX 220 | 221 | #ifndef SIZE_MAX // [ 222 | # ifdef _WIN64 // [ 223 | # define SIZE_MAX _UI64_MAX 224 | # else // _WIN64 ][ 225 | # define SIZE_MAX _UI32_MAX 226 | # endif // _WIN64 ] 227 | #endif // SIZE_MAX ] 228 | 229 | // WCHAR_MIN and WCHAR_MAX are also defined in 230 | #ifndef WCHAR_MIN // [ 231 | # define WCHAR_MIN 0 232 | #endif // WCHAR_MIN ] 233 | #ifndef WCHAR_MAX // [ 234 | # define WCHAR_MAX _UI16_MAX 235 | #endif // WCHAR_MAX ] 236 | 237 | #define WINT_MIN 0 238 | #define WINT_MAX _UI16_MAX 239 | 240 | #endif // __STDC_LIMIT_MACROS ] 241 | 242 | 243 | // 7.18.4 Limits of other integer types 244 | 245 | #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 246 | 247 | // 7.18.4.1 Macros for minimum-width integer constants 248 | 249 | #define INT8_C(val) val##i8 250 | #define INT16_C(val) val##i16 251 | #define INT32_C(val) val##i32 252 | #define INT64_C(val) val##i64 253 | 254 | #define UINT8_C(val) val##ui8 255 | #define UINT16_C(val) val##ui16 256 | #define UINT32_C(val) val##ui32 257 | #define UINT64_C(val) val##ui64 258 | 259 | // 7.18.4.2 Macros for greatest-width integer constants 260 | #define INTMAX_C INT64_C 261 | #define UINTMAX_C UINT64_C 262 | 263 | #endif // __STDC_CONSTANT_MACROS ] 264 | 265 | #endif /* RC_INVOKED */ 266 | 267 | #endif // _STDINT ] 268 | -------------------------------------------------------------------------------- /include/RingQueue/msvc/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shines77/RingQueue/c785765b7a516c2c706ec1a1f5495bc4bd55d8ed/include/RingQueue/msvc/targetver.h -------------------------------------------------------------------------------- /include/RingQueue/q.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include "vs_stdint.h" 6 | 7 | struct msg { 8 | struct msg *next; 9 | }; 10 | 11 | struct queue { 12 | uint32_t head; 13 | uint32_t tail; 14 | struct msg **msgs; 15 | struct msg *list; 16 | }; 17 | 18 | #define CNT 0x10000 19 | #define GP(x) (x % (CNT)) 20 | 21 | static inline struct queue * 22 | qinit(void) 23 | { 24 | struct queue *q = (struct queue *)malloc(sizeof(*q)); 25 | 26 | bzero(q, sizeof(*q)); 27 | q->msgs = (struct msg **)calloc(sizeof(struct msg *), CNT); 28 | 29 | return q; 30 | } 31 | 32 | static inline int 33 | push(struct queue *q, struct msg *m) 34 | { 35 | uint32_t tail = GP(__sync_fetch_and_add(&q->tail, 1)); 36 | 37 | if (!__sync_bool_compare_and_swap(&q->msgs[tail], NULL, m)) { 38 | struct msg *last; 39 | do { 40 | last = q->list; 41 | m->next = last; 42 | } while (!__sync_bool_compare_and_swap(&q->list, last, m)); 43 | } 44 | return 0; 45 | } 46 | 47 | static inline struct msg * 48 | pop(struct queue *q) 49 | { 50 | uint32_t head = q->head; 51 | uint32_t h2; 52 | struct msg *list; 53 | 54 | if (head == q->tail) 55 | return NULL; 56 | 57 | h2 = GP(head); 58 | list = q->list; 59 | 60 | if (list) { 61 | struct msg *n = list->next; 62 | if (__sync_bool_compare_and_swap(&q->list, list, n)) { 63 | list->next = NULL; 64 | push(q, list); 65 | } 66 | } 67 | struct msg *m = q->msgs[h2]; 68 | if (!m) 69 | return NULL; 70 | if (!__sync_bool_compare_and_swap(&q->head, head, head + 1)) 71 | return NULL; 72 | if (!__sync_bool_compare_and_swap(&q->msgs[h2], m, NULL)) 73 | return NULL; 74 | 75 | return m; 76 | } 77 | -------------------------------------------------------------------------------- /include/RingQueue/q3.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shines77/RingQueue/c785765b7a516c2c706ec1a1f5495bc4bd55d8ed/include/RingQueue/q3.h -------------------------------------------------------------------------------- /include/RingQueue/sleep.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _JIMIC_SYSTEM_SLEEP_H_ 3 | #define _JIMIC_SYSTEM_SLEEP_H_ 4 | 5 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 6 | #pragma once 7 | #endif 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #if defined(_MSC_VER) || defined(__INTEL_COMPILER) || defined(__MINGW32__) || defined(__CYGWIN__) 14 | __declspec(dllimport) int __stdcall SwitchToThread(void); 15 | //__declspec(dllimport) void __stdcall Sleep(DWORD); 16 | #endif 17 | 18 | /* Sleep for the platform */ 19 | void jimi_sleep(unsigned int millisec); 20 | 21 | /* Sleep for Linux or MinGW */ 22 | void jimi_usleep(unsigned int usec); 23 | 24 | /* Sleep for Windows or MinGW */ 25 | void jimi_wsleep(unsigned int millisec); 26 | 27 | /* Yield(): On Windows: Switch to the other threads in the same CPU core. */ 28 | /* On Linux: Switch to the other threads in all cores. */ 29 | /* On success, jimi_yield() returns 1. On error, 0 is returned. */ 30 | int jimi_yield(); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif /* !_JIMIC_SYSTEM_SLEEP_H_ */ 37 | -------------------------------------------------------------------------------- /include/RingQueue/sys_timer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shines77/RingQueue/c785765b7a516c2c706ec1a1f5495bc4bd55d8ed/include/RingQueue/sys_timer.h -------------------------------------------------------------------------------- /include/RingQueue/test.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shines77/RingQueue/c785765b7a516c2c706ec1a1f5495bc4bd55d8ed/include/RingQueue/test.h -------------------------------------------------------------------------------- /include/RingQueue/vs_inttypes.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _JIMI_INTTYPES_H_ 3 | #define _JIMI_INTTYPES_H_ 4 | 5 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 6 | #pragma once 7 | #endif 8 | 9 | #if defined(_MSC_VER) && (_MSC_VER < 1700) 10 | #include "msvc/inttypes.h" 11 | #else 12 | #include 13 | #endif /* _MSC_VER */ 14 | 15 | #endif /* _JIMI_INTTYPES_H_ */ 16 | -------------------------------------------------------------------------------- /include/RingQueue/vs_stdbool.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _JIMI_STDBOOL_H_ 3 | #define _JIMI_STDBOOL_H_ 4 | 5 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 6 | #pragma once 7 | #endif 8 | 9 | #if defined(_MSC_VER) && (_MSC_VER < 1700) 10 | #include "msvc/stdbool.h" 11 | #else 12 | #include 13 | #endif /* _MSC_VER */ 14 | 15 | #endif /* _JIMI_STDBOOL_H_ */ 16 | -------------------------------------------------------------------------------- /include/RingQueue/vs_stdint.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _JIMI_STDINT_H_ 3 | #define _JIMI_STDINT_H_ 4 | 5 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 6 | #pragma once 7 | #endif 8 | 9 | #if defined(_MSC_VER) && (_MSC_VER < 1700) 10 | #include "msvc/stdint.h" 11 | #else 12 | #include 13 | #endif /* _MSC_VER */ 14 | 15 | #endif /* _JIMI_STDINT_H_ */ 16 | -------------------------------------------------------------------------------- /projects/RingQueue/vc2008/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:RingQueue 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 RingQueue 应用程序。 6 | 7 | 本文件概要介绍组成 RingQueue 应用程序的 8 | 的每个文件的内容。 9 | 10 | 11 | RingQueue.vcproj 12 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件, 13 | 其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 14 | 15 | RingQueue.cpp 16 | 这是主应用程序源文件。 17 | 18 | ///////////////////////////////////////////////////////////////////////////// 19 | 其他标准文件: 20 | 21 | StdAfx.h, StdAfx.cpp 22 | 这些文件用于生成名为 RingQueue.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | 其他注释: 26 | 27 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 28 | 29 | ///////////////////////////////////////////////////////////////////////////// -------------------------------------------------------------------------------- /projects/RingQueue/vc2008/RingQueue.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 26 | 29 | 32 | 35 | 38 | 41 | 53 | 56 | 59 | 62 | 69 | 72 | 75 | 78 | 81 | 84 | 87 | 90 | 91 | 99 | 102 | 105 | 108 | 111 | 114 | 128 | 131 | 134 | 137 | 147 | 150 | 153 | 156 | 159 | 162 | 165 | 168 | 169 | 170 | 171 | 172 | 173 | 178 | 181 | 182 | 185 | 186 | 189 | 190 | 193 | 194 | 197 | 198 | 201 | 202 | 205 | 206 | 209 | 212 | 213 | 216 | 217 | 218 | 219 | 224 | 227 | 228 | 231 | 232 | 235 | 236 | 239 | 240 | 243 | 244 | 247 | 248 | 251 | 252 | 255 | 256 | 259 | 260 | 263 | 264 | 267 | 268 | 271 | 272 | 275 | 276 | 279 | 280 | 283 | 284 | 287 | 288 | 291 | 292 | 295 | 296 | 299 | 300 | 303 | 306 | 307 | 310 | 311 | 314 | 315 | 318 | 319 | 322 | 323 | 326 | 327 | 328 | 329 | 334 | 335 | 338 | 339 | 340 | 341 | 342 | 343 | -------------------------------------------------------------------------------- /projects/RingQueue/vc2010/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:RingQueue 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 RingQueue 应用程序。 6 | 7 | 本文件概要介绍组成 RingQueue 应用程序的 8 | 的每个文件的内容。 9 | 10 | 11 | RingQueue.vcproj 12 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件, 13 | 其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 14 | 15 | RingQueue.cpp 16 | 这是主应用程序源文件。 17 | 18 | ///////////////////////////////////////////////////////////////////////////// 19 | 其他标准文件: 20 | 21 | StdAfx.h, StdAfx.cpp 22 | 这些文件用于生成名为 RingQueue.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | 其他注释: 26 | 27 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 28 | 29 | ///////////////////////////////////////////////////////////////////////////// -------------------------------------------------------------------------------- /projects/RingQueue/vc2010/RingQueue.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2} 23 | RingQueue 24 | Win32Proj 25 | 26 | 27 | 28 | Application 29 | MultiByte 30 | true 31 | 32 | 33 | Application 34 | MultiByte 35 | true 36 | 37 | 38 | Application 39 | MultiByte 40 | 41 | 42 | Application 43 | MultiByte 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | <_ProjectFileVersion>10.0.40219.1 63 | $(SolutionDir)bin\vc2010\$(ProjectName)\x86-$(Configuration)\ 64 | $(SolutionDir)bin\vc2010\$(ProjectName)\x64-$(Configuration)\ 65 | $(SolutionDir)gen\tmp\vc2010\$(ProjectName)\x86-$(Configuration)\ 66 | $(SolutionDir)gen\tmp\vc2010\$(ProjectName)\x64-$(Configuration)\ 67 | true 68 | true 69 | $(SolutionDir)bin\vc2010\$(ProjectName)\x86-$(Configuration)\ 70 | $(SolutionDir)bin\vc2010\$(ProjectName)\x64-$(Configuration)\ 71 | $(SolutionDir)gen\tmp\vc2010\$(ProjectName)\x86-$(Configuration)\ 72 | $(SolutionDir)gen\tmp\vc2010\$(ProjectName)\x64-$(Configuration)\ 73 | false 74 | false 75 | AllRules.ruleset 76 | AllRules.ruleset 77 | 78 | 79 | 80 | 81 | AllRules.ruleset 82 | AllRules.ruleset 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | Disabled 91 | ..\..\..\include;..\..\..\include\RingQueue;..\..\..\src;..\..\..\src\RingQueue;%(AdditionalIncludeDirectories) 92 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 93 | true 94 | EnableFastChecks 95 | MultiThreadedDebugDLL 96 | 97 | 98 | Level3 99 | EditAndContinue 100 | 101 | 102 | true 103 | Console 104 | MachineX86 105 | 106 | 107 | 108 | 109 | Disabled 110 | ..\..\..\include;..\..\..\include\RingQueue;..\..\..\src;..\..\..\src\RingQueue;%(AdditionalIncludeDirectories) 111 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 112 | EnableFastChecks 113 | MultiThreadedDebugDLL 114 | 115 | 116 | Level3 117 | ProgramDatabase 118 | 119 | 120 | true 121 | Console 122 | 123 | 124 | 125 | 126 | MaxSpeed 127 | Default 128 | true 129 | true 130 | ..\..\..\include;..\..\..\include\RingQueue;..\..\..\src;..\..\..\src\RingQueue;%(AdditionalIncludeDirectories) 131 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | MultiThreadedDLL 133 | true 134 | 135 | 136 | Level3 137 | ProgramDatabase 138 | 139 | 140 | false 141 | $(TargetDir)$(TargetName).pdb 142 | Console 143 | true 144 | true 145 | MachineX86 146 | 147 | 148 | 149 | 150 | MaxSpeed 151 | Default 152 | true 153 | true 154 | ..\..\..\include;..\..\..\include\RingQueue;..\..\..\src;..\..\..\src\RingQueue;%(AdditionalIncludeDirectories) 155 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 156 | MultiThreadedDLL 157 | true 158 | 159 | 160 | Level3 161 | ProgramDatabase 162 | 163 | 164 | false 165 | $(TargetDir)$(TargetName).pdb 166 | Console 167 | true 168 | true 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | -------------------------------------------------------------------------------- /projects/RingQueue/vc2010/RingQueue.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {97026717-a785-48a4-9dd5-67cc6eaac6a8} 10 | 11 | 12 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 13 | h;hpp;hxx;hm;inl;inc;xsd 14 | 15 | 16 | {175c8cbe-04b0-4972-8eab-df576d60acdb} 17 | 18 | 19 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 20 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 21 | 22 | 23 | 24 | 25 | src 26 | 27 | 28 | src 29 | 30 | 31 | src 32 | 33 | 34 | src 35 | 36 | 37 | src 38 | 39 | 40 | src 41 | 42 | 43 | src 44 | 45 | 46 | src\msvc 47 | 48 | 49 | src\msvc 50 | 51 | 52 | 53 | 54 | include 55 | 56 | 57 | include 58 | 59 | 60 | include 61 | 62 | 63 | include 64 | 65 | 66 | include 67 | 68 | 69 | include 70 | 71 | 72 | include 73 | 74 | 75 | include 76 | 77 | 78 | include 79 | 80 | 81 | include 82 | 83 | 84 | include 85 | 86 | 87 | include 88 | 89 | 90 | include 91 | 92 | 93 | include\msvc 94 | 95 | 96 | include\msvc 97 | 98 | 99 | include\msvc 100 | 101 | 102 | include\msvc 103 | 104 | 105 | include\msvc 106 | 107 | 108 | include 109 | 110 | 111 | include\msvc 112 | 113 | 114 | include 115 | 116 | 117 | include 118 | 119 | 120 | include 121 | 122 | 123 | include 124 | 125 | 126 | include 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /projects/RingQueue/vc2013/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:RingQueue 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 RingQueue 应用程序。 6 | 7 | 本文件概要介绍组成 RingQueue 应用程序的 8 | 的每个文件的内容。 9 | 10 | 11 | RingQueue.vcproj 12 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件, 13 | 其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 14 | 15 | RingQueue.cpp 16 | 这是主应用程序源文件。 17 | 18 | ///////////////////////////////////////////////////////////////////////////// 19 | 其他标准文件: 20 | 21 | StdAfx.h, StdAfx.cpp 22 | 这些文件用于生成名为 RingQueue.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | 其他注释: 26 | 27 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 28 | 29 | ///////////////////////////////////////////////////////////////////////////// -------------------------------------------------------------------------------- /projects/RingQueue/vc2013/RingQueue.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2} 23 | RingQueue 24 | Win32Proj 25 | 26 | 27 | 28 | Application 29 | v120 30 | MultiByte 31 | true 32 | 33 | 34 | Application 35 | v120 36 | MultiByte 37 | true 38 | 39 | 40 | Application 41 | v120 42 | MultiByte 43 | 44 | 45 | Application 46 | v120 47 | MultiByte 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | <_ProjectFileVersion>12.0.30501.0 67 | 68 | 69 | $(SolutionDir)bin\vc2013\$(ProjectName)\x86-$(Configuration)\ 70 | $(SolutionDir)gen\tmp\vc2013\$(ProjectName)\x86-$(Configuration)\ 71 | true 72 | 73 | 74 | true 75 | $(SolutionDir)bin\vc2013\$(ProjectName)\x64-$(Configuration)\ 76 | $(SolutionDir)gen\tmp\vc2013\$(ProjectName)\x64-$(Configuration)\ 77 | 78 | 79 | $(SolutionDir)bin\vc2013\$(ProjectName)\x86-$(Configuration)\ 80 | $(SolutionDir)gen\tmp\vc2013\$(ProjectName)\x86-$(Configuration)\ 81 | false 82 | 83 | 84 | false 85 | $(SolutionDir)bin\vc2013\$(ProjectName)\x64-$(Configuration)\ 86 | $(SolutionDir)gen\tmp\vc2013\$(ProjectName)\x64-$(Configuration)\ 87 | 88 | 89 | 90 | Disabled 91 | ..\..\..\include;..\..\..\include\RingQueue;..\..\..\src;..\..\..\src\RingQueue;%(AdditionalIncludeDirectories) 92 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 93 | true 94 | EnableFastChecks 95 | MultiThreadedDebugDLL 96 | 97 | Level3 98 | EditAndContinue 99 | 100 | 101 | true 102 | Console 103 | MachineX86 104 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;winmm.lib;%(AdditionalDependencies) 105 | 106 | 107 | 108 | 109 | Disabled 110 | ..\..\..\include;..\..\..\include\RingQueue;..\..\..\src;..\..\..\src\RingQueue;%(AdditionalIncludeDirectories) 111 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 112 | EnableFastChecks 113 | MultiThreadedDebugDLL 114 | 115 | 116 | Level3 117 | ProgramDatabase 118 | 119 | 120 | true 121 | Console 122 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;winmm.lib;%(AdditionalDependencies) 123 | 124 | 125 | 126 | 127 | MaxSpeed 128 | Default 129 | true 130 | true 131 | ..\..\..\include;..\..\..\include\RingQueue;..\..\..\src;..\..\..\src\RingQueue;%(AdditionalIncludeDirectories) 132 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 133 | MultiThreadedDLL 134 | true 135 | 136 | Level3 137 | ProgramDatabase 138 | 139 | 140 | true 141 | $(TargetDir)$(TargetName).pdb 142 | Console 143 | true 144 | true 145 | MachineX86 146 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;winmm.lib;%(AdditionalDependencies) 147 | 148 | 149 | 150 | 151 | MaxSpeed 152 | Default 153 | true 154 | true 155 | ..\..\..\include;..\..\..\include\RingQueue;..\..\..\src;..\..\..\src\RingQueue;%(AdditionalIncludeDirectories) 156 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 157 | MultiThreadedDLL 158 | true 159 | 160 | 161 | Level3 162 | ProgramDatabase 163 | 164 | 165 | true 166 | $(TargetDir)$(TargetName).pdb 167 | Console 168 | true 169 | true 170 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;winmm.lib;%(AdditionalDependencies) 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | -------------------------------------------------------------------------------- /projects/RingQueue/vc2013/RingQueue.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {06ccbd35-9def-4969-a843-49421fc7945a} 10 | 11 | 12 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 13 | h;hpp;hxx;hm;inl;inc;xsd 14 | 15 | 16 | {c868144f-9adf-461a-aa5a-1368db56c53d} 17 | 18 | 19 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 20 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 21 | 22 | 23 | 24 | 25 | src 26 | 27 | 28 | src 29 | 30 | 31 | src 32 | 33 | 34 | src 35 | 36 | 37 | src 38 | 39 | 40 | src 41 | 42 | 43 | src 44 | 45 | 46 | src\msvc 47 | 48 | 49 | src\msvc 50 | 51 | 52 | 53 | 54 | include 55 | 56 | 57 | include 58 | 59 | 60 | include 61 | 62 | 63 | include 64 | 65 | 66 | include 67 | 68 | 69 | include 70 | 71 | 72 | include 73 | 74 | 75 | include 76 | 77 | 78 | include 79 | 80 | 81 | include 82 | 83 | 84 | include 85 | 86 | 87 | include 88 | 89 | 90 | include 91 | 92 | 93 | include\msvc 94 | 95 | 96 | include\msvc 97 | 98 | 99 | include\msvc 100 | 101 | 102 | include\msvc 103 | 104 | 105 | include\msvc 106 | 107 | 108 | include 109 | 110 | 111 | include\msvc 112 | 113 | 114 | include 115 | 116 | 117 | include 118 | 119 | 120 | include 121 | 122 | 123 | include 124 | 125 | 126 | include 127 | 128 | 129 | include 130 | 131 | 132 | include 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /projects/RingQueue/vc2015/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:RingQueue 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 RingQueue 应用程序。 6 | 7 | 本文件概要介绍组成 RingQueue 应用程序的 8 | 的每个文件的内容。 9 | 10 | 11 | RingQueue.vcproj 12 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件, 13 | 其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 14 | 15 | RingQueue.cpp 16 | 这是主应用程序源文件。 17 | 18 | ///////////////////////////////////////////////////////////////////////////// 19 | 其他标准文件: 20 | 21 | StdAfx.h, StdAfx.cpp 22 | 这些文件用于生成名为 RingQueue.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | 其他注释: 26 | 27 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 28 | 29 | ///////////////////////////////////////////////////////////////////////////// -------------------------------------------------------------------------------- /projects/RingQueue/vc2015/RingQueue.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {BB407950-C4DD-446C-A3FD-E2985DD83FD2} 23 | RingQueue 24 | Win32Proj 25 | 26 | 27 | 28 | Application 29 | v140 30 | MultiByte 31 | true 32 | 33 | 34 | Application 35 | v140 36 | MultiByte 37 | true 38 | 39 | 40 | Application 41 | v140 42 | MultiByte 43 | 44 | 45 | Application 46 | v140 47 | MultiByte 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | <_ProjectFileVersion>12.0.30501.0 67 | 68 | 69 | $(SolutionDir)bin\vc2015\$(ProjectName)\x86-$(Configuration)\ 70 | $(SolutionDir)gen\tmp\vc2015\$(ProjectName)\x86-$(Configuration)\ 71 | true 72 | 73 | 74 | true 75 | $(SolutionDir)bin\vc2015\$(ProjectName)\x64-$(Configuration)\ 76 | $(SolutionDir)gen\tmp\vc2015\$(ProjectName)\x64-$(Configuration)\ 77 | 78 | 79 | $(SolutionDir)bin\vc2015\$(ProjectName)\x86-$(Configuration)\ 80 | $(SolutionDir)gen\tmp\vc2015\$(ProjectName)\x86-$(Configuration)\ 81 | false 82 | 83 | 84 | false 85 | $(SolutionDir)bin\vc2015\$(ProjectName)\x64-$(Configuration)\ 86 | $(SolutionDir)gen\tmp\vc2015\$(ProjectName)\x64-$(Configuration)\ 87 | 88 | 89 | 90 | Disabled 91 | ..\..\..\include;..\..\..\include\RingQueue;..\..\..\src;..\..\..\src\RingQueue;%(AdditionalIncludeDirectories) 92 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 93 | true 94 | EnableFastChecks 95 | MultiThreadedDebugDLL 96 | 97 | Level3 98 | EditAndContinue 99 | 100 | 101 | true 102 | Console 103 | MachineX86 104 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;winmm.lib;%(AdditionalDependencies) 105 | 106 | 107 | 108 | 109 | Disabled 110 | ..\..\..\include;..\..\..\include\RingQueue;..\..\..\src;..\..\..\src\RingQueue;%(AdditionalIncludeDirectories) 111 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 112 | EnableFastChecks 113 | MultiThreadedDebugDLL 114 | 115 | 116 | Level3 117 | ProgramDatabase 118 | 119 | 120 | true 121 | Console 122 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;winmm.lib;%(AdditionalDependencies) 123 | 124 | 125 | 126 | 127 | MaxSpeed 128 | Default 129 | true 130 | true 131 | ..\..\..\include;..\..\..\include\RingQueue;..\..\..\src;..\..\..\src\RingQueue;%(AdditionalIncludeDirectories) 132 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 133 | MultiThreadedDLL 134 | true 135 | 136 | Level3 137 | ProgramDatabase 138 | 139 | 140 | true 141 | $(TargetDir)$(TargetName).pdb 142 | Console 143 | true 144 | true 145 | MachineX86 146 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;winmm.lib;%(AdditionalDependencies) 147 | 148 | 149 | 150 | 151 | MaxSpeed 152 | Default 153 | true 154 | true 155 | ..\..\..\include;..\..\..\include\RingQueue;..\..\..\src;..\..\..\src\RingQueue;%(AdditionalIncludeDirectories) 156 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 157 | MultiThreadedDLL 158 | true 159 | 160 | 161 | Level3 162 | ProgramDatabase 163 | 164 | 165 | true 166 | $(TargetDir)$(TargetName).pdb 167 | Console 168 | true 169 | true 170 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;winmm.lib;%(AdditionalDependencies) 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | -------------------------------------------------------------------------------- /projects/RingQueue/vc2015/RingQueue.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {06ccbd35-9def-4969-a843-49421fc7945a} 10 | 11 | 12 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 13 | h;hpp;hxx;hm;inl;inc;xsd 14 | 15 | 16 | {c868144f-9adf-461a-aa5a-1368db56c53d} 17 | 18 | 19 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 20 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 21 | 22 | 23 | 24 | 25 | src 26 | 27 | 28 | src 29 | 30 | 31 | src 32 | 33 | 34 | src 35 | 36 | 37 | src 38 | 39 | 40 | src 41 | 42 | 43 | src 44 | 45 | 46 | src\msvc 47 | 48 | 49 | src\msvc 50 | 51 | 52 | 53 | 54 | include 55 | 56 | 57 | include 58 | 59 | 60 | include 61 | 62 | 63 | include 64 | 65 | 66 | include 67 | 68 | 69 | include 70 | 71 | 72 | include 73 | 74 | 75 | include 76 | 77 | 78 | include 79 | 80 | 81 | include 82 | 83 | 84 | include 85 | 86 | 87 | include 88 | 89 | 90 | include 91 | 92 | 93 | include\msvc 94 | 95 | 96 | include\msvc 97 | 98 | 99 | include\msvc 100 | 101 | 102 | include\msvc 103 | 104 | 105 | include\msvc 106 | 107 | 108 | include 109 | 110 | 111 | include\msvc 112 | 113 | 114 | include 115 | 116 | 117 | include 118 | 119 | 120 | include 121 | 122 | 123 | include 124 | 125 | 126 | include 127 | 128 | 129 | include 130 | 131 | 132 | include 133 | 134 | 135 | include 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /src/RingQueue/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) 3 | set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) 4 | set(CMAKE_CXX_COMPILER g++) 5 | set(CMAKE_C_COMPILER gcc) 6 | 7 | # 8 | # Use sse, sse2 in gcc 9 | # Reference: http://stackoverflow.com/questions/5217812/c-compilation-issue-with-emmintrin-h-on-linux-gcc 10 | # 11 | if (NOT MSVC_IDE) 12 | add_definitions("-D_GNU_SOURCE") 13 | 14 | add_definitions("-msse") 15 | add_definitions("-msse2") 16 | 17 | add_definitions("-D__MMX__") 18 | add_definitions("-D__SSE__") 19 | add_definitions("-D__SSE2__") 20 | add_definitions("-D__SSE3__") 21 | 22 | # add_definitions("-lpthread") 23 | endif() 24 | 25 | if (CMAKE_COMPILER_IS_GNUCC) 26 | # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 27 | # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lpthread") 28 | # set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -lpthread") 29 | # set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -lpthread") 30 | elseif (CMAKE_COMPILER_IS_GNUCXX) 31 | # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror") 32 | # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lpthread") 33 | # set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -lpthread") 34 | # set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -lpthread") 35 | endif() 36 | 37 | # set(SRC_RINGQUEUE_LIST main.cpp console.c dump_mem.c get_char.c sleep.c sys_timer.c ${SRC_RINGQUEUE_COLMAJOR_LIST} ${SRC_RINGQUEUE_ROWMAJOR_LIST}) 38 | 39 | file(GLOB_RECURSE SRC_RINGQUEUE_LIST "${PROJECT_SOURCE_DIR}/src/RingQueue/*.cpp" "${PROJECT_SOURCE_DIR}/src/RingQueue/*.c") 40 | 41 | # aux_source_directory(. SRC_RINGQUEUE_LIST) 42 | # aux_source_directory(./msvc SRC_RINGQUEUE_MSVC_LIST) 43 | 44 | file(GLOB_RECURSE SRC_RINGQUEUE_INCLUDE_LIST "${PROJECT_SOURCE_DIR}/include/RingQueue/*.h") 45 | 46 | # list(APPEND SRC_RINGQUEUE_LIST ${SRC_RINGQUEUE_MSVC_LIST} ${SRC_RINGQUEUE_INCLUDE_LIST}) 47 | 48 | # aux_source_directory(./colmajor SRC_RINGQUEUE_COLMAJOR_LIST) 49 | # aux_source_directory(./rowmajor SRC_RINGQUEUE_ROWMAJOR_LIST) 50 | 51 | include_directories(${PROJECT_SOURCE_DIR}/include) 52 | include_directories(${PROJECT_SOURCE_DIR}/include/RingQueue) 53 | 54 | # add_library(util STATIC ${SRC_LIST}) 55 | # add_library(libhello SHARED ${LIB_SRC}) 56 | # link_directories(${PROJECT_SOURCE_DIR}/lib) 57 | 58 | message(STATUS "This is BINARY dir " ${PROJECT_BINARY_DIR}) 59 | message(STATUS "This is SOURCE dir " ${PROJECT_SOURCE_DIR}) 60 | 61 | # message(STATUS "This is SOURCE colmajor dir " ${SRC_RINGQUEUE_COLMAJOR_LIST}) 62 | # message(STATUS "This is SOURCE rowmajor dir " ${SRC_RINGQUEUE_ROWMAJOR_LIST}) 63 | 64 | # message(STATUS "This is SOURCE RingQueue dir " ${SRC_RINGQUEUE_LIST}) 65 | 66 | # message(STATUS "CMAKE_STANDARD_LIBRARIES = " ${CMAKE_STANDARD_LIBRARIES}) 67 | 68 | # 69 | # cmake and lib pthread 70 | # See: http://stackoverflow.com/questions/5395309/cmake-and-threads 71 | # 72 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) 73 | 74 | find_package(Threads REQUIRED) 75 | # find_package(Kernel32 REQUIRED) 76 | 77 | if (CMAKE_USE_PTHREADS_INIT) 78 | set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-lpthread") 79 | endif() 80 | 81 | add_executable(RingQueue ${SRC_RINGQUEUE_LIST} ${SRC_RINGQUEUE_INCLUDE_LIST}) 82 | # add_executable(RingQueue ${SRC_RINGQUEUE_LIST} ${SRC_RINGQUEUE_COLMAJOR_LIST} ${SRC_RINGQUEUE_ROWMAJOR_LIST}) 83 | 84 | if (CMAKE_USE_PTHREADS_INIT) 85 | target_link_libraries(RingQueue ${CMAKE_THREAD_LIBS_INIT}) 86 | endif() 87 | 88 | #if (MINGW OR CYGWIN OR MSVC_IDE) 89 | # msvcrt.lib 90 | target_link_libraries(RingQueue kernel32 user32 gdi32 comdlg32 shell32 uuid winmm) 91 | #endif() 92 | 93 | # target_link_libraries(hello util) 94 | 95 | # 96 | # See: http://yang3wei.github.io/blog/2013/02/15/cmake-xue-xi-bi-ji-1/ 97 | # 98 | # See: http://blog.csdn.net/dbzhang800/article/details/6314073 99 | # 100 | # set_target_properties(libhello PROPERTIES OUTPUT_NAME "hello") 101 | -------------------------------------------------------------------------------- /src/RingQueue/console.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shines77/RingQueue/c785765b7a516c2c706ec1a1f5495bc4bd55d8ed/src/RingQueue/console.c -------------------------------------------------------------------------------- /src/RingQueue/dump_mem.c: -------------------------------------------------------------------------------- 1 | 2 | #include "dump_mem.h" 3 | 4 | #include 5 | #include 6 | 7 | #ifndef jimic_assert 8 | #define jimic_assert assert 9 | #endif // jimic_assert 10 | 11 | #if defined(_WIN64) || defined(_M_X64) || defined(_M_AMD64) || defined(_M_IA64) || defined(__amd64__) || defined(__x86_64__) 12 | #define UNINITIALIAZE_DATA 0xCCCCCCCCCCCCCCCCULL 13 | #else 14 | #define UNINITIALIAZE_DATA 0xCCCCCCCCUL 15 | #endif 16 | 17 | /** 18 | * macro for address aligned to n bytes 19 | */ 20 | #define JIMI_ALIGNED_TO(n, alignment) \ 21 | (((n) + ((alignment) - 1)) & ~(size_t)((alignment) - 1)) 22 | 23 | #define JIMI_ADDR_ALIGNED_TO(p, alignment) \ 24 | ((void *)((((size_t)(void *)(p)) + ((alignment) - 1)) & ~(size_t)((alignment) - 1))) 25 | 26 | #define JIMI_ADDR_ALIGNED_DOWNTO(p, alignment) \ 27 | ((void *)(((size_t)(void *)(p)) & ~(size_t)((alignment) - 1))) 28 | 29 | #define JIMI_PVOID_INC(p, n) ((void *)((size_t)(p) + 1)) 30 | #define JIMI_PVOID_DEC(p, n) ((void *)((size_t)(p) - 1)) 31 | 32 | #define JIMI_PVOID_ADD(p, n) ((void *)((size_t)(p) + (n))) 33 | #define JIMI_PVOID_SUB(p, n) ((void *)((size_t)(p) - (n))) 34 | 35 | void dump_memory(void *p, size_t size, bool alignedTo /* = false */, 36 | unsigned int alignment /* = 16 */, 37 | unsigned int extraHead /* = 0 */, 38 | unsigned int extraTail /* = 0 */) 39 | { 40 | // display memory dump 41 | size_t i, j; 42 | size_t addr; 43 | size_t lineTotal; 44 | unsigned char *cur; 45 | void *startAddr, *endAddr; 46 | 47 | jimic_assert(p != NULL); 48 | //jimic_assert(p != (void *)0xCCCCCCCC); 49 | 50 | // Whether the start address aligned to alignment? 51 | if (alignedTo) { 52 | startAddr = (void *)JIMI_ADDR_ALIGNED_DOWNTO(p, alignment); 53 | endAddr = (void *)JIMI_ADDR_ALIGNED_TO((size_t)p + size, alignment); 54 | } 55 | else { 56 | startAddr = p; 57 | endAddr = (void *)((size_t)p + size); 58 | } 59 | 60 | // Extend the extra lines at head or tail 61 | if (extraHead > 0) 62 | startAddr = JIMI_PVOID_SUB(startAddr, alignment * extraHead); 63 | if (extraTail > 0) 64 | endAddr = JIMI_PVOID_ADD(endAddr, alignment * extraTail); 65 | 66 | // Get the total of display lines 67 | lineTotal = ((size_t)endAddr - (size_t)startAddr + (alignment - 1)) / alignment; 68 | 69 | printf("--------------------------------------------------------------\n"); 70 | printf(" Addr = 0x%016p, Size = %u bytes\n", p, (unsigned int)size); 71 | printf("--------------------------------------------------------------\n"); 72 | printf("\n"); 73 | 74 | if (p == NULL || p == (void *)UNINITIALIAZE_DATA) { 75 | printf(" Can not read the data from the address.\n"); 76 | printf("\n"); 77 | return; 78 | } 79 | 80 | printf(" Address 0 1 2 3 4 5 6 7 | 8 9 A B C D E F\n"); 81 | printf("--------------------------------------------------------------\n"); 82 | printf("\n"); 83 | 84 | addr = (size_t)startAddr; 85 | for (i = 0; i < lineTotal; ++i) { 86 | // display format preview 87 | //printf(" %08X 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n", (unsigned int)addr); 88 | printf(" %08X ", (unsigned int)addr); 89 | cur = (unsigned char *)addr; 90 | for (j = 0; j < alignment; ++j) { 91 | printf("%02X", (unsigned int)(*cur)); 92 | if (j < alignment - 1) { 93 | if ((j & 7) != 7) 94 | printf(" "); 95 | else 96 | printf(" "); 97 | } 98 | cur++; 99 | } 100 | printf(" "); 101 | cur = (unsigned char *)addr; 102 | for (j = 0; j < alignment; ++j) { 103 | if (*cur >= 128) 104 | printf("?"); 105 | else if (*cur >= 32) 106 | printf("%c", (unsigned char)(*cur)); 107 | else 108 | printf("."); 109 | cur++; 110 | } 111 | printf("\n"); 112 | addr += alignment; 113 | } 114 | 115 | printf("\n"); 116 | } 117 | -------------------------------------------------------------------------------- /src/RingQueue/get_char.c: -------------------------------------------------------------------------------- 1 | 2 | #include "get_char.h" 3 | 4 | #include 5 | 6 | #if defined(__MINGW32__) 7 | #include 8 | #elif defined(__linux__) || defined(__GNUC__) 9 | #include 10 | #endif /* __MINGW32__ */ 11 | 12 | #if defined(_MSC_VER) || defined(__INTEL_COMPILER) 13 | #include 14 | #endif /* _MSC_VER */ 15 | 16 | #if defined(__MINGW32__) 17 | 18 | /* Read 1 character without echo */ 19 | int jimi_getch(void) 20 | { 21 | return _getch(); 22 | } 23 | 24 | /* Read 1 character with echo */ 25 | int jimi_getche(void) 26 | { 27 | int ch = _getch(); 28 | if (ch != EOF) 29 | printf("%c", (char)ch); 30 | else 31 | printf("EOF: (%d)", ch); 32 | return ch; 33 | } 34 | 35 | #elif defined(__linux__) || defined(__GNUC__) 36 | 37 | /// 38 | /// 39 | /// What is equivalent to getch() & getche() in Linux? 40 | /// 41 | /// From: http://stackoverflow.com/questions/7469139/what-is-equivalent-to-getch-getche-in-linux 42 | /// 43 | /// 44 | 45 | static struct termios s_term_old, s_term_new; 46 | 47 | /* Initialize new terminal i/o settings */ 48 | void init_terminal_os(int echo) 49 | { 50 | tcgetattr(0, &s_term_old); /* grab old terminal i/o settings */ 51 | s_term_new = s_term_old; /* make new settings same as old settings */ 52 | s_term_new.c_lflag &= ~ICANON; /* disable buffered i/o */ 53 | s_term_new.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */ 54 | tcsetattr(0, TCSANOW, &s_term_new); /* use these new terminal i/o settings now */ 55 | } 56 | 57 | /* Restore old terminal i/o settings */ 58 | void reset_terminal_os(void) 59 | { 60 | tcsetattr(0, TCSANOW, &s_term_old); 61 | } 62 | 63 | /* Read 1 character - echo defines echo mode */ 64 | int jimi_getch_term(int echo) 65 | { 66 | int ch; 67 | init_terminal_os(echo); 68 | ch = getchar(); 69 | reset_terminal_os(); 70 | return ch; 71 | } 72 | 73 | /* Read 1 character without echo */ 74 | int jimi_getch(void) 75 | { 76 | return jimi_getch_term(0); 77 | } 78 | 79 | /* Read 1 character with echo */ 80 | int jimi_getche(void) 81 | { 82 | return jimi_getch_term(1); 83 | } 84 | 85 | #elif defined(_MSC_VER) || defined(__INTEL_COMPILER) 86 | 87 | /* Read 1 character without echo */ 88 | int jimi_getch(void) 89 | { 90 | return _getch(); 91 | } 92 | 93 | /* Read 1 character with echo */ 94 | int jimi_getche(void) 95 | { 96 | int ch = _getch(); 97 | if (ch != EOF) 98 | printf("%c", (char)ch); 99 | else 100 | printf("EOF: (%d)", ch); 101 | return ch; 102 | } 103 | 104 | #else /* other unknown os */ 105 | 106 | /* Read 1 character without echo */ 107 | int jimi_getch(void) 108 | { 109 | return (int)-1; 110 | } 111 | 112 | /* Read 1 character with echo */ 113 | int jimi_getche(void) 114 | { 115 | return (int)-1; 116 | } 117 | 118 | #endif /* __linux__ */ 119 | -------------------------------------------------------------------------------- /src/RingQueue/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shines77/RingQueue/c785765b7a516c2c706ec1a1f5495bc4bd55d8ed/src/RingQueue/main.cpp -------------------------------------------------------------------------------- /src/RingQueue/mq.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "vs_stdint.h" 8 | 9 | #include "mq.h" 10 | #include "port.h" 11 | 12 | #define QSZ (1 << 10) 13 | #define QMSK (QSZ - 1) 14 | 15 | struct queue { 16 | volatile uint32_t head; 17 | volatile uint32_t tail; 18 | void * q[QSZ]; 19 | }; 20 | 21 | struct queue * 22 | queue_create() { 23 | struct queue * q = (struct queue *)malloc(sizeof(*q)); 24 | memset(q, 0, sizeof(*q)); 25 | return q; 26 | } 27 | 28 | void * 29 | queue_push(struct queue *q, void *m) { 30 | uint32_t head, tail; 31 | do { 32 | tail = q->tail; 33 | // maybe we don't need memory fence in x86 34 | // __sync_synchronize(); 35 | head = q->head; 36 | if (head + QSZ == tail) { 37 | return NULL; 38 | } 39 | } while (!jimi_bool_compare_and_swap32(&q->tail, tail, tail+1)); 40 | q->q[tail & QMSK] = m; 41 | 42 | return m; 43 | } 44 | 45 | void * 46 | queue_pop(struct queue *q) { 47 | uint32_t head, tail, masked; 48 | void * m; 49 | do { 50 | head = q->head; 51 | tail = q->tail; 52 | if (head == tail) { 53 | return NULL; 54 | } 55 | masked = head & QMSK; 56 | m = q->q[masked]; 57 | if (m == NULL) { 58 | return NULL; 59 | } 60 | #if defined(__clang__) || defined(__CLANG__) || defined(__APPLE__) || defined(__FreeBSD__) 61 | } while (0); 62 | #else 63 | #if defined(_WIN64) || defined(_M_X64) || defined(_M_AMD64) || defined(_M_IA64) || defined(__amd64__) || defined(__x86_64__) 64 | } while (!jimi_bool_compare_and_swap64(&q->q[masked], m, NULL)); 65 | #else 66 | } while (!jimi_bool_compare_and_swap32(&q->q[masked], m, NULL)); 67 | #endif 68 | #endif 69 | q->head ++; 70 | return m; 71 | } 72 | -------------------------------------------------------------------------------- /src/RingQueue/msvc/pthread.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shines77/RingQueue/c785765b7a516c2c706ec1a1f5495bc4bd55d8ed/src/RingQueue/msvc/pthread.c -------------------------------------------------------------------------------- /src/RingQueue/msvc/sched.c: -------------------------------------------------------------------------------- 1 | 2 | #if defined(_MSC_VER) || defined(__INTEL_COMPILER) || defined(__MINGW32__) || defined(__CYGWIN__) 3 | 4 | #include "msvc/sched.h" 5 | 6 | #ifndef WIN32_LEAN_AND_MEAN 7 | #define WIN32_LEAN_AND_MEAN 8 | #endif 9 | #include "msvc/targetver.h" 10 | #include 11 | #include /* _beginthreadex(), _endthreadex() */ 12 | 13 | #include 14 | #include 15 | 16 | void SCHW32_CDECL schw32_cpu_zero(cpu_set_t *cpuset) 17 | { 18 | assert(cpuset != NULL); 19 | 20 | memset((void *)cpuset, 0, sizeof(*cpuset)); 21 | } 22 | 23 | void SCHW32_CDECL schw32_cpu_set(int cpuid, cpu_set_t *cpuset) 24 | { 25 | assert(cpuset != NULL); 26 | assert(cpuid >= 0 && cpuid <= 255); 27 | 28 | cpuset->mask |= 1U << (unsigned int)cpuid; 29 | } 30 | 31 | void SCHW32_CDECL schw32_cpu_clear(int cpuid, cpu_set_t *cpuset) 32 | { 33 | assert(cpuset != NULL); 34 | assert(cpuid >= 0 && cpuid <= 255); 35 | 36 | cpuset->mask &= ~(1U << (unsigned int)cpuid); 37 | } 38 | 39 | int SCHW32_CDECL schw32_cpu_isset(int cpuid, const cpu_set_t *cpuset) 40 | { 41 | assert(cpuset != NULL); 42 | assert(cpuid >= 0 && cpuid <= 255); 43 | 44 | return ((cpuset->mask & (1U << (unsigned int)cpuid)) != 0); 45 | } 46 | 47 | #endif // defined(_MSC_VER) || defined(__INTERL_COMPILER) || defined(__MINGW32__) || defined(__CYGWIN__) 48 | -------------------------------------------------------------------------------- /src/RingQueue/sleep.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shines77/RingQueue/c785765b7a516c2c706ec1a1f5495bc4bd55d8ed/src/RingQueue/sleep.c -------------------------------------------------------------------------------- /src/RingQueue/sys_timer.c: -------------------------------------------------------------------------------- 1 | 2 | #include "sys_timer.h" 3 | --------------------------------------------------------------------------------