1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 The rust scheduler. Schedulers may be added to the kernel
13 dynamically and they run until there are no more tasks to
14 schedule. Most of the scheduler work is carried out in worker
15 threads by rust_sched_loop.
18 #ifndef RUST_SCHEDULER_H
19 #define RUST_SCHEDULER_H
21 #include "rust_globals.h"
22 #include "util/array_list.h"
23 #include "rust_kernel.h"
24 #include "rust_refcount.h"
26 class rust_sched_launcher
;
27 class rust_sched_launcher_factory
;
29 class rust_scheduler
: public kernel_owned
<rust_scheduler
> {
30 RUST_ATOMIC_REFCOUNT();
31 // FIXME (#2693): Make these private
35 // Protects live_threads, live_tasks, cur_thread, may_exit
37 // When this hits zero we'll tell the kernel to release us
38 uintptr_t live_threads
;
39 // When this hits zero we'll tell the threads to exit
45 rust_sched_launcher_factory
*launchfac
;
46 array_list
<rust_sched_launcher
*> threads
;
47 const size_t max_num_threads
;
51 void destroy_task_threads();
53 rust_sched_launcher
*create_task_thread(int id
);
54 void destroy_task_thread(rust_sched_launcher
*thread
);
58 // Called when refcount reaches zero
62 // private and undefined to disable copying
63 rust_scheduler(const rust_scheduler
& rhs
);
64 rust_scheduler
& operator=(const rust_scheduler
& rhs
);
67 rust_scheduler(rust_kernel
*kernel
, size_t max_num_threads
,
68 rust_sched_id id
, bool allow_exit
, bool killed
,
69 rust_sched_launcher_factory
*launchfac
);
71 void start_task_threads();
72 void join_task_threads();
73 void kill_all_tasks();
74 rust_task
* create_task(rust_task
*spawner
, const char *name
);
78 size_t max_number_of_threads();
79 size_t number_of_threads();
80 // Called by each thread when it terminates. When all threads
81 // terminate the scheduler does as well.
82 void release_task_thread();
84 rust_sched_id
get_id() { return id
; }
85 // Tells the scheduler that as soon as it runs out of tasks
86 // to run it should exit
91 #endif /* RUST_SCHEDULER_H */