Skip to content

Commit

Permalink
OpenMPMutex "Copying" (#2794)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtramm committed Dec 4, 2023
1 parent e0d0381 commit ec8850d
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions include/openmc/openmp_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down

0 comments on commit ec8850d

Please sign in to comment.