diff --git a/include/openmc/openmp_interface.h b/include/openmc/openmp_interface.h index dac03ac5916..b489df0c9ad 100644 --- a/include/openmc/openmp_interface.h +++ b/include/openmc/openmp_interface.h @@ -29,11 +29,26 @@ class OpenMPMutex { #endif } - // Mutexes cannot be copied. We need to explicitly delete the copy - // constructor and copy assignment operator to ensure the compiler doesn't - // "help" us by implicitly trying to copy the underlying mutexes. - OpenMPMutex(const OpenMPMutex&) = delete; - OpenMPMutex& operator=(const OpenMPMutex&) = delete; + // omp_lock_t objects cannot be deep copied, they can only be shallow + // copied. Thus, while shallow copying of an omp_lock_t object is + // completely valid (provided no race conditions exist), true copying + // of an OpenMPMutex object is not valid due to the action of the + // destructor. However, since locks are fungible, we can simply replace + // copying operations with default construction. This allows storage of + // OpenMPMutex objects within containers that may need to move/copy them + // (e.g., std::vector). It is left to the caller to understand that + // copying of OpenMPMutex does not produce two handles to the same mutex, + // rather, it produces two different mutexes. + + // Copy constructor + OpenMPMutex(const OpenMPMutex& other) { OpenMPMutex(); } + + // Copy assignment operator + OpenMPMutex& operator=(const OpenMPMutex& other) + { + OpenMPMutex(); + return *this; + } //! Lock the mutex. //