File tree 3 files changed +22
-5
lines changed
3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -1403,11 +1403,9 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) {
1403
1403
1404
1404
let num_threads = match opts. mode {
1405
1405
SingleThreaded => 1 u,
1406
- ThreadPerCore => {
1407
- fail ~"thread_per_core scheduling mode unimplemented"
1408
- }
1406
+ ThreadPerCore => rustrt:: rust_num_threads( ) ,
1409
1407
ThreadPerTask => {
1410
- fail ~"thread_per_task scheduling mode unimplemented"
1408
+ fail ~"ThreadPerTask scheduling mode unimplemented"
1411
1409
}
1412
1410
ManualThreads ( threads) => {
1413
1411
if threads == 0 u {
@@ -1657,6 +1655,8 @@ extern mod rustrt {
1657
1655
1658
1656
fn rust_get_sched_id( ) -> sched_id;
1659
1657
fn rust_new_sched( num_threads: libc:: uintptr_t) -> sched_id;
1658
+ fn sched_threads( ) -> libc:: size_t;
1659
+ fn rust_num_threads( ) -> libc:: uintptr_t;
1660
1660
1661
1661
fn get_task_id( ) -> task_id;
1662
1662
#[ rust_stack]
@@ -2422,3 +2422,13 @@ fn test_tls_cleanup_on_failure() unsafe {
2422
2422
local_data_set( int_key, @31337 ) ;
2423
2423
fail;
2424
2424
}
2425
+
2426
+ #[ test]
2427
+ fn test_sched_thread_per_core( ) {
2428
+ let cores = rustrt:: rust_num_threads( ) ;
2429
+ let mut reported_threads = 0 u;
2430
+ do spawn_sched( ThreadPerCore ) {
2431
+ reported_threads = rustrt:: sched_threads( ) ;
2432
+ }
2433
+ assert( cores == reported_threads) ;
2434
+ }
Original file line number Diff line number Diff line change @@ -572,6 +572,12 @@ rust_get_sched_id() {
572
572
return task->sched ->get_id ();
573
573
}
574
574
575
+ extern " C" CDECL uintptr_t
576
+ rust_num_threads () {
577
+ rust_task *task = rust_get_current_task ();
578
+ return task->kernel ->env ->num_sched_threads ;
579
+ }
580
+
575
581
extern " C" CDECL rust_sched_id
576
582
rust_new_sched (uintptr_t threads) {
577
583
rust_task *task = rust_get_current_task ();
@@ -620,7 +626,7 @@ start_task(rust_task *target, fn_env_pair *f) {
620
626
target->start (f->f , f->env , NULL );
621
627
}
622
628
623
- extern " C" CDECL int
629
+ extern " C" CDECL size_t
624
630
sched_threads () {
625
631
rust_task *task = rust_get_current_task ();
626
632
return task->sched ->number_of_threads ();
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ rand_seed
32
32
rust_get_sched_id
33
33
rust_new_sched
34
34
rust_new_task_in_sched
35
+ rust_num_threads
35
36
rust_path_is_dir
36
37
rust_path_exists
37
38
rust_getcwd
You can’t perform that action at this time.
0 commit comments