Replace shmctl with waiting on all on-Linux platforms
This commit is contained in:
		
							parent
							
								
									dbd70d4884
								
							
						
					
					
						commit
						70e899378d
					
				| @ -107,6 +107,7 @@ class SharedMemory | |||||||
|         return Remove(key); |         return Remove(key); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | #ifdef __linux__ | ||||||
|     void WaitForDetach() |     void WaitForDetach() | ||||||
|     { |     { | ||||||
|         auto shmid = shm.get_shmid(); |         auto shmid = shm.get_shmid(); | ||||||
| @ -134,10 +135,12 @@ class SharedMemory | |||||||
| 
 | 
 | ||||||
|         do |         do | ||||||
|         { |         { | ||||||
|  |             // On OSX this returns EINVAL for whatever reason, hence we need to disable it
 | ||||||
|             int ret = ::shmctl(shmid, IPC_STAT, &xsi_ds); |             int ret = ::shmctl(shmid, IPC_STAT, &xsi_ds); | ||||||
|             if (ret < 0) |             if (ret < 0) | ||||||
|             { |             { | ||||||
|                 throw util::exception("shmctl encountered an error: " + errorToMessage(ret) + |                 auto error_code = errno; | ||||||
|  |                 throw util::exception("shmctl encountered an error: " + errorToMessage(error_code) + | ||||||
|                                       SOURCE_REF); |                                       SOURCE_REF); | ||||||
|             } |             } | ||||||
|             BOOST_ASSERT(ret >= 0); |             BOOST_ASSERT(ret >= 0); | ||||||
| @ -145,6 +148,15 @@ class SharedMemory | |||||||
|             std::this_thread::sleep_for(std::chrono::microseconds(100)); |             std::this_thread::sleep_for(std::chrono::microseconds(100)); | ||||||
|         } while (xsi_ds.shm_nattch > 1); |         } while (xsi_ds.shm_nattch > 1); | ||||||
|     } |     } | ||||||
|  | #else | ||||||
|  |     void WaitForDetach() | ||||||
|  |     { | ||||||
|  |         util::Log(logWARNING) | ||||||
|  |             << "Shared memory support for non-Linux systems does not wait for clients to " | ||||||
|  |                "dettach. Going to sleep for 50ms."; | ||||||
|  |         std::this_thread::sleep_for(std::chrono::milliseconds(50)); | ||||||
|  |     } | ||||||
|  | #endif | ||||||
| 
 | 
 | ||||||
|   private: |   private: | ||||||
|     static bool RegionExists(const boost::interprocess::xsi_key &key) |     static bool RegionExists(const boost::interprocess::xsi_key &key) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user