Changeset 312 in pacpusframework for trunk/src/PacpusTools
- Timestamp:
- Jul 28, 2014, 4:11:30 PM (10 years ago)
- Location:
- trunk/src/PacpusTools/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/PacpusTools/src/PosixShMem.cpp
r162 r312 66 66 result = true; 67 67 } 68 68 69 69 ///////////////////////////////////////// 70 70 if (result) { -
trunk/src/PacpusTools/src/SharedMemory.cpp
r303 r312 62 62 << ". Message: " << (const char *) lpMsgBuf 63 63 << ". Program will exit" 64 ); 65 ::exit(-1); 64 ); 65 ::exit(-1); 66 66 } 67 67 68 68 // create the event - autoreset mode 69 event_ = CreateEvent(NULL, false, false, eventName.c_str()); 69 event_ = CreateEvent(NULL, false, false, eventName.c_str()); 70 70 71 71 // lock the semaphore and try to create the shared memory 72 lockMemory(); 73 shMemHandle_ = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, name); 72 lockMemory(); 73 shMemHandle_ = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, name); 74 74 if (shMemHandle_ == NULL) { 75 75 LOG_FATAL("cannot create shared memory segment '" << name << "'" 76 76 << ". Error: " << GetLastError() 77 77 << ". Program will exit" 78 ); 78 ); 79 79 ::exit(-1); 80 80 } 81 81 82 82 // Map the memory to a local pointer 83 shMem_ = MapViewOfFile(shMemHandle_, FILE_MAP_ALL_ACCESS, 0, 0, 0); 83 shMem_ = MapViewOfFile(shMemHandle_, FILE_MAP_ALL_ACCESS, 0, 0, 0); 84 84 if (shMem_ == NULL) { 85 85 LOG_FATAL("cannot map the view of file of the shared memory segment '" << name << "'" 86 86 << ". Error: " << GetLastError() 87 87 << ". Program will exit" 88 ); 88 ); 89 89 ::exit(-1); 90 90 } 91 91 92 LOG_INFO("created Win32 shared memory '" << name << "'"); 92 LOG_INFO("created Win32 shared memory '" << name << "'"); 93 93 94 94 unlockMemory(); … … 135 135 result = true; 136 136 } 137 137 138 138 ///////////////////////////////////////// 139 139 if (result) { … … 168 168 LOG_TRACE("destructor"); 169 169 #if PACPUS_OS_WINDOWS 170 // free the semaphore 171 CloseHandle(semaphore_); 172 UnmapViewOfFile(shMem_); 173 CloseHandle(shMemHandle_); 170 // free the semaphore 171 CloseHandle(semaphore_); 172 UnmapViewOfFile(shMem_); 173 CloseHandle(shMemHandle_); 174 174 #elif PACPUS_OS_UNIX 175 175 // detach this process from the shared memory … … 186 186 #if PACPUS_OS_WINDOWS 187 187 if (timeout == 0) { 188 timeout = INFINITE; 189 } 190 191 DWORD status = 0; 192 status = WaitForSingleObject(event_, timeout); 188 timeout = INFINITE; 189 } 190 191 DWORD status = 0; 192 status = WaitForSingleObject(event_, timeout); 193 193 194 194 if (status == WAIT_OBJECT_0) { 195 return true; 195 return true; 196 196 } else { 197 return false; 197 return false; 198 198 } 199 199 #elif PACPUS_OS_UNIX … … 209 209 void* shMem; 210 210 #if PACPUS_OS_WINDOWS 211 lockMemory(); 211 lockMemory(); 212 212 #endif 213 213 shMem = shMem_; 214 214 #if PACPUS_OS_WINDOWS 215 unlockMemory(); 215 unlockMemory(); 216 216 #endif 217 217 return shMem; … … 221 221 { 222 222 lockMemory(); 223 memcpy(dst, shMem_, size); 223 memcpy(dst, shMem_, size); 224 224 unlockMemory(); 225 225 } … … 228 228 { 229 229 #if PACPUS_OS_WINDOWS 230 return event_; 230 return event_; 231 231 #elif PACPUS_OS_UNIX 232 232 LOG_TRACE("no event identifier"); … … 241 241 LOG_TRACE("writing " << size << " bytes to shared memory at offset " << offset); 242 242 #if PACPUS_OS_WINDOWS 243 lockMemory(); 243 lockMemory(); 244 244 //unsigned long * dest = (unsigned long *)shMem_ + offset; 245 245 char * dest = (char *)shMem_ + offset; 246 //printf("adresses : shm : %x dest : %x offset : %x \n",shMem_, dest, offset); 246 //printf("adresses : shm : %x dest : %x offset : %x \n",shMem_, dest, offset); 247 247 memcpy(dest, data, size); 248 248 unlockMemory(); 249 SetEvent(event_); 249 SetEvent(event_); 250 250 #elif PACPUS_OS_UNIX 251 251 lockMemory(); … … 267 267 { 268 268 #if PACPUS_OS_WINDOWS 269 WaitForSingleObject(semaphore_, INFINITE); 269 WaitForSingleObject(semaphore_, INFINITE); 270 270 #elif PACPUS_OS_UNIX 271 271 BOOST_ASSERT(memory_); … … 279 279 { 280 280 #if PACPUS_OS_WINDOWS 281 ReleaseSemaphore(semaphore_, 1, NULL); 281 ReleaseSemaphore(semaphore_, 1, NULL); 282 282 #elif PACPUS_OS_UNIX 283 283 BOOST_ASSERT(memory_);
Note:
See TracChangeset
for help on using the changeset viewer.