Skip to content

Commit

Permalink
Document arc::unwrap. Close #3123.
Browse files Browse the repository at this point in the history
  • Loading branch information
bblum committed Aug 21, 2012
1 parent 71ec545 commit 3b09c3d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/libstd/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ fn clone<T: const send>(rc: &arc<T>) -> arc<T> {
arc { x: unsafe { clone_shared_mutable_state(&rc.x) } }
}

/**
* Retrieve the data back out of the ARC. This function blocks until the
* reference given to it is the last existing one, and then unwrap the data
* instead of destroying it.
*
* If multiple tasks call unwrap, all but the first will fail. Do not call
* unwrap from a task that holds another reference to the same ARC; it is
* guaranteed to deadlock.
*/
fn unwrap<T: const send>(+rc: arc<T>) -> T {
let arc { x: x } = rc;
unsafe { unwrap_shared_mutable_state(x) }
Expand Down Expand Up @@ -186,6 +195,12 @@ impl<T: send> &mutex_arc<T> {
}
}

/**
* Retrieves the data, blocking until all other references are dropped,
* exactly as arc::unwrap.
*
* Will additionally fail if another task has failed while accessing the arc.
*/
// FIXME(#2585) make this a by-move method on the arc
fn unwrap_mutex_arc<T: send>(+arc: mutex_arc<T>) -> T {
let mutex_arc { x: x } = arc;
Expand Down Expand Up @@ -363,6 +378,13 @@ impl<T: const send> &rw_arc<T> {
}
}
/**
* Retrieves the data, blocking until all other references are dropped,
* exactly as arc::unwrap.
*
* Will additionally fail if another task has failed while accessing the arc
* in write mode.
*/
// FIXME(#2585) make this a by-move method on the arc
fn unwrap_rw_arc<T: const send>(+arc: rw_arc<T>) -> T {
let rw_arc { x: x, _ } = arc;
Expand Down

0 comments on commit 3b09c3d

Please sign in to comment.