11/* *******************************************************************************
2- * Copyright (c) 2020-0201, SlickTech
2+ * Copyright (c) 2020-2025 SlickTech
33 * All rights reserved
44 *
55 * This file is part of the SlickQueue. Redistribution and use in source and
@@ -83,15 +83,15 @@ class SlickQueue {
8383 CloseHandle (hMapFile_);
8484 hMapFile_ = nullptr ;
8585 }
86-
86+ #endif
87+
8788 if (!use_shm_) {
8889 delete[] data_;
8990 data_ = nullptr ;
9091
9192 delete[] control_;
9293 control_ = nullptr ;
9394 }
94- #endif
9595 }
9696
9797 bool own_buffer () const noexcept { return own_; }
@@ -172,21 +172,21 @@ class SlickQueue {
172172#if defined(_MSC_VER)
173173 void allocate_shm_data (const char * const shm_name, bool open_only) {
174174 SIZE_T BF_SZ;
175- HANDLE hMapFile = NULL ;
175+ hMapFile_ = NULL ;
176176 if (open_only) {
177- hMapFile = OpenFileMapping (FILE_MAP_ALL_ACCESS, FALSE , (LPCWSTR)shm_name);
177+ hMapFile_ = OpenFileMapping (FILE_MAP_ALL_ACCESS, FALSE , (LPCWSTR)shm_name);
178178 own_ = false ;
179179 auto err = GetLastError ();
180- if (hMapFile == NULL ) {
180+ if (hMapFile_ == NULL ) {
181181 throw std::runtime_error (" Failed to open shm. err=" + std::to_string (err));
182182 }
183183
184- void * lpvMem = MapViewOfFile (hMapFile , FILE_MAP_ALL_ACCESS, 0 , 0 , 64 );
185- if (!lpvMem ) {
184+ lpvMem_ = MapViewOfFile (hMapFile_ , FILE_MAP_ALL_ACCESS, 0 , 0 , 64 );
185+ if (!lpvMem_ ) {
186186 auto err = GetLastError ();
187187 throw std::runtime_error (" Failed to map shm. err=" + std::to_string (err));
188188 }
189- mask_ = *reinterpret_cast <uint32_t *>(reinterpret_cast <uint8_t *>(lpvMem ) + sizeof (std::atomic_uint_fast64_t )) - 1 ;
189+ mask_ = *reinterpret_cast <uint32_t *>(reinterpret_cast <uint8_t *>(lpvMem_ ) + sizeof (std::atomic_uint_fast64_t )) - 1 ;
190190 size_ = mask_ + 1025 ;
191191 BF_SZ = 64 + sizeof (slot) * size_ + sizeof (T) * size_;
192192 UnmapViewOfFile (lpvMem_);
@@ -195,7 +195,7 @@ class SlickQueue {
195195 else {
196196 BF_SZ = 64 + sizeof (slot) * size_ + sizeof (T) * size_;
197197
198- hMapFile = CreateFileMapping (
198+ hMapFile_ = CreateFileMapping (
199199 INVALID_HANDLE_VALUE, // use paging file
200200 NULL , // default security
201201 PAGE_READWRITE, // read/write access
@@ -206,7 +206,7 @@ class SlickQueue {
206206
207207 own_ = false ;
208208 auto err = GetLastError ();
209- if (hMapFile == NULL ) {
209+ if (hMapFile_ == NULL ) {
210210 throw std::runtime_error (" Failed to create shm. err=" + std::to_string (err));
211211 }
212212
@@ -215,22 +215,22 @@ class SlickQueue {
215215 }
216216 }
217217
218- void * lpvMem = MapViewOfFile (hMapFile , FILE_MAP_ALL_ACCESS, 0 , 0 , BF_SZ);
219- if (!lpvMem ) {
218+ lpvMem_ = MapViewOfFile (hMapFile_ , FILE_MAP_ALL_ACCESS, 0 , 0 , BF_SZ);
219+ if (!lpvMem_ ) {
220220 auto err = GetLastError ();
221221 throw std::runtime_error (" Failed to map shm. err=" + std::to_string (err));
222222 }
223223
224224 if (own_) {
225- reserved_ = new (lpvMem ) std::atomic_uint_fast64_t { 0 };
226- *reinterpret_cast <uint32_t *>(reinterpret_cast <uint8_t *>(lpvMem ) + sizeof (std::atomic_uint_fast64_t )) = mask_ + 1 ;
227- control_ = new ((uint8_t *)lpvMem + 64 ) slot[size_];
228- data_ = new ((uint8_t *)lpvMem + 64 + sizeof (slot) * size_) T[size_];
225+ reserved_ = new (lpvMem_ ) std::atomic_uint_fast64_t { 0 };
226+ *reinterpret_cast <uint32_t *>(reinterpret_cast <uint8_t *>(lpvMem_ ) + sizeof (std::atomic_uint_fast64_t )) = mask_ + 1 ;
227+ control_ = new ((uint8_t *)lpvMem_ + 64 ) slot[size_];
228+ data_ = new ((uint8_t *)lpvMem_ + 64 + sizeof (slot) * size_) T[size_];
229229 }
230230 else {
231- reserved_ = reinterpret_cast <std::atomic_uint_fast64_t *>(lpvMem );
232- control_ = reinterpret_cast <slot*>((uint8_t *)lpvMem + 64 );
233- data_ = reinterpret_cast <T*>((uint8_t *)lpvMem + 64 + sizeof (slot) * size_);
231+ reserved_ = reinterpret_cast <std::atomic_uint_fast64_t *>(lpvMem_ );
232+ control_ = reinterpret_cast <slot*>((uint8_t *)lpvMem_ + 64 );
233+ data_ = reinterpret_cast <T*>((uint8_t *)lpvMem_ + 64 + sizeof (slot) * size_);
234234 }
235235 }
236236#else
0 commit comments