This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Implement Guard::safepoint() #43
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
73fb735
Implement Guard::safepoint()
jeehoonkang d020edd
Add a comment in safepoint()
jeehoonkang 07c5fd1
Remove the SeqCst fence from repin()
jeehoonkang a629930
Rename safepoint() into repin()
jeehoonkang 7bac8cf
Fix a glitch in documentation
jeehoonkang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,43 @@ impl Guard { | |
} | ||
} | ||
|
||
/// Unpins and then immediately re-pins the thread. | ||
/// | ||
/// This method is useful when you don't want delay the advancement of the global epoch by | ||
/// holding an old epoch. For safety, you should not maintain any guard-based reference across | ||
/// the call (the latter is enforced by `&mut self`). The thread will only be repinned if this | ||
/// is the only active guard for the current thread. | ||
/// | ||
/// If this method is called from an [`unprotected`] guard, then the call will be just no-op. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// use crossbeam_epoch::{self as epoch, Atomic}; | ||
/// use std::sync::atomic::Ordering::SeqCst; | ||
/// use std::thread; | ||
/// use std::time::Duration; | ||
/// | ||
/// let a = Atomic::new(777); | ||
/// let mut guard = epoch::pin(); | ||
/// { | ||
/// let p = a.load(SeqCst, &guard); | ||
/// assert_eq!(unsafe { p.as_ref() }, Some(&777)); | ||
/// } | ||
/// guard.repin(); | ||
/// { | ||
/// let p = a.load(SeqCst, &guard); | ||
/// assert_eq!(unsafe { p.as_ref() }, Some(&777)); | ||
/// } | ||
/// ``` | ||
/// | ||
/// [`unprotected`]: fn.unprotected.html | ||
pub fn repin(&mut self) { | ||
if let Some(local) = unsafe { self.local.as_ref() } { | ||
local.repin(); | ||
} | ||
} | ||
|
||
/// Temporarily unpins the thread, executes the given function and then re-pins the thread. | ||
/// | ||
/// This method is useful when you need to perform a long-running operation (e.g. sleeping) | ||
|
@@ -203,10 +240,6 @@ impl Guard { | |
/// | ||
/// If this method is called from an [`unprotected`] guard, then the passed function is called | ||
/// directly without unpinning the thread. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You accidentally deleted part of a comment here. |
||
/// use crossbeam_epoch::{self as epoch, Atomic}; | ||
/// use std::sync::atomic::Ordering::SeqCst; | ||
/// use std::thread; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably also mention that the current thread will be repinned only if this is the only active guard.