Skip to content

Commit d3c233f

Browse files
committed
---
yaml --- r: 107657 b: refs/heads/dist-snap c: 75af1e5 h: refs/heads/master i: 107655: 779aa39 v: v3
1 parent 9d72635 commit d3c233f

File tree

3 files changed

+11
-106
lines changed

3 files changed

+11
-106
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: f64fdf524a434f0e5cd0bc91d09c144723f3c90d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: b85fe01b94f876a5db698db10e43ffdf2116c0a3
9+
refs/heads/dist-snap: 75af1e504a5745ab7f05dbecd43f79cbef75a1c1
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/doc/guide-ffi.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,15 @@ which would call back to `callback()` in Rust.
303303

304304
## Targetting callbacks to Rust objects
305305

306-
The former example showed how a global function can be called from C-Code.
306+
The former example showed how a global function can be called from C code.
307307
However it is often desired that the callback is targetted to a special
308308
Rust object. This could be the object that represents the wrapper for the
309309
respective C object.
310310

311311
This can be achieved by passing an unsafe pointer to the object down to the
312312
C library. The C library can then include the pointer to the Rust object in
313-
the notification. This will provide a unsafe possibility to access the
314-
referenced Rust object in callback.
313+
the notification. This will allow the callback to unsafely access the
314+
referenced Rust object.
315315

316316
Rust code:
317317
~~~~ {.xfail-test}
@@ -364,25 +364,25 @@ void trigger_callback() {
364364

365365
## Asynchronous callbacks
366366

367-
In the already given examples the callbacks are invoked as a direct reaction
367+
In the previously given examples the callbacks are invoked as a direct reaction
368368
to a function call to the external C library.
369-
The control over the current thread switched from Rust to C to Rust for the
369+
The control over the current thread is switched from Rust to C to Rust for the
370370
execution of the callback, but in the end the callback is executed on the
371371
same thread (and Rust task) that lead called the function which triggered
372372
the callback.
373373

374-
Things get more complicated when the external library spawns it's own threads
374+
Things get more complicated when the external library spawns its own threads
375375
and invokes callbacks from there.
376-
In these cases access to Rust data structures inside he callbacks is
376+
In these cases access to Rust data structures inside the callbacks is
377377
especially unsafe and proper synchronization mechanisms must be used.
378-
Besides classical synchronization mechanisms like mutexes one possibility in
378+
Besides classical synchronization mechanisms like mutexes, one possibility in
379379
Rust is to use channels (in `std::comm`) to forward data from the C thread
380380
that invoked the callback into a Rust task.
381381

382382
If an asychronous callback targets a special object in the Rust address space
383383
it is also absolutely necessary that no more callbacks are performed by the
384-
C library after the respective Rust object get's destroyed.
385-
This can be achieved by unregistering the callback it the object's
384+
C library after the respective Rust object gets destroyed.
385+
This can be achieved by unregistering the callback in the object's
386386
destructor and designing the library in a way that guarantees that no
387387
callback will be performed after unregistration.
388388

branches/dist-snap/src/libextra/sync.rs

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ use std::unstable::finally::Finally;
2727
use std::util;
2828
use std::util::NonCopyable;
2929

30-
use arc::MutexArc;
31-
3230
/****************************************************************************
3331
* Internals
3432
****************************************************************************/
@@ -684,67 +682,6 @@ impl<'a> RWLockReadMode<'a> {
684682
pub fn read<U>(&self, blk: || -> U) -> U { blk() }
685683
}
686684

687-
/// A barrier enables multiple tasks to synchronize the beginning
688-
/// of some computation.
689-
/// ```rust
690-
/// use extra::sync::Barrier;
691-
///
692-
/// let barrier = Barrier::new(10);
693-
/// 10.times(|| {
694-
/// let c = barrier.clone();
695-
/// // The same messages will be printed together.
696-
/// // You will NOT see any interleaving.
697-
/// do spawn {
698-
/// println!("before wait");
699-
/// c.wait();
700-
/// println!("after wait");
701-
/// }
702-
/// });
703-
/// ```
704-
#[deriving(Clone)]
705-
pub struct Barrier {
706-
priv arc: MutexArc<BarrierState>,
707-
priv num_tasks: uint,
708-
}
709-
710-
// The inner state of a double barrier
711-
struct BarrierState {
712-
priv count: uint,
713-
priv generation_id: uint,
714-
}
715-
716-
impl Barrier {
717-
/// Create a new barrier that can block a given number of tasks.
718-
pub fn new(num_tasks: uint) -> Barrier {
719-
Barrier {
720-
arc: MutexArc::new(BarrierState {
721-
count: 0,
722-
generation_id: 0,
723-
}),
724-
num_tasks: num_tasks,
725-
}
726-
}
727-
728-
/// Block the current task until a certain number of tasks is waiting.
729-
pub fn wait(&self) {
730-
self.arc.access_cond(|state, cond| {
731-
let local_gen = state.generation_id;
732-
state.count += 1;
733-
if state.count < self.num_tasks {
734-
// We need a while loop to guard against spurious wakeups.
735-
// http://en.wikipedia.org/wiki/Spurious_wakeup
736-
while local_gen == state.generation_id && state.count < self.num_tasks {
737-
cond.wait();
738-
}
739-
} else {
740-
state.count = 0;
741-
state.generation_id += 1;
742-
cond.broadcast();
743-
}
744-
});
745-
}
746-
}
747-
748685
/****************************************************************************
749686
* Tests
750687
****************************************************************************/
@@ -756,7 +693,6 @@ mod tests {
756693
use std::cast;
757694
use std::result;
758695
use std::task;
759-
use std::comm::{SharedChan, Empty};
760696

761697
/************************************************************************
762698
* Semaphore tests
@@ -1379,35 +1315,4 @@ mod tests {
13791315
})
13801316
})
13811317
}
1382-
1383-
/************************************************************************
1384-
* Barrier tests
1385-
************************************************************************/
1386-
#[test]
1387-
fn test_barrier() {
1388-
let barrier = Barrier::new(10);
1389-
let (port, chan) = SharedChan::new();
1390-
1391-
9.times(|| {
1392-
let c = barrier.clone();
1393-
let chan = chan.clone();
1394-
do spawn {
1395-
c.wait();
1396-
chan.send(true);
1397-
}
1398-
});
1399-
1400-
// At this point, all spawned tasks should be blocked,
1401-
// so we shouldn't get anything from the port
1402-
assert!(match port.try_recv() {
1403-
Empty => true,
1404-
_ => false,
1405-
});
1406-
1407-
barrier.wait();
1408-
// Now, the barrier is cleared and we should get data.
1409-
9.times(|| {
1410-
port.recv();
1411-
});
1412-
}
14131318
}

0 commit comments

Comments
 (0)