Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenMPMutex "Copying" #2794

Merged
merged 2 commits into from
Dec 4, 2023
Merged

OpenMPMutex "Copying" #2794

merged 2 commits into from
Dec 4, 2023

Conversation

jtramm
Copy link
Contributor

@jtramm jtramm commented Dec 1, 2023

Description

The original OpenMPMutex class definition deletes the copy operator and copy assignment operators. This was a reasonable strategy, as if we copy this object then only a shallow copy is performed (i.e., destroying the original object will uninitialize the omp_lock_t within the new copied object). While deletion of these operators works, it also precludes the class from being stored in various STL containers that might need to copy or move the objects (e.g., std::vector).

Given that omp_lock_t objects are inherently fungible, we can just define the copy operators with default construction. I.e., copying just creates a new object, it does not copy anything from the original object. This allows for usage of the object in STL containers like vectors.

For performance, we might also want to implement move operators, but I'm hesitant to introduce even more code that may not be used and likely isn't going to be covered by testing. Additionally, as movement of locks would only ever be done during program initialization, there is no tangible benefit to the move semantics, so probably not worth the extra code.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) on any C++ source files (if applicable)

@jtramm jtramm requested a review from pshriwise December 1, 2023 16:27
Copy link
Contributor

@pshriwise pshriwise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this update @jtramm!

@pshriwise pshriwise merged commit ec8850d into openmc-dev:develop Dec 4, 2023
18 checks passed
church89 pushed a commit to openmsr/openmc that referenced this pull request Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants