00001 #ifndef SCHEDULER_CLASS
00002 #define SCHEDULER_CLASS
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "scheduling_common.h"
00019
00020
00021 class actor_mapper;
00022 class int_averager;
00023 class mailbox;
00024 class memory_limiter;
00025 class schedulable;
00026 class schedule_actor;
00027 class schedule_driver;
00028 class schedule_iterator;
00029 class scheduling_id;
00030
00031 namespace nodes {
00032 class safe_list;
00033 class safe_list_write_iterator;
00034 }
00035
00037
00042 class SCHEDULING_CLASS_STYLE scheduler : public scheduling_common
00043 {
00044 public:
00045 scheduler(actor_mapper &mapper, int time_per_activation,
00046 int maximum_weight, int max_actor_weight,
00047 int snooze_interval = 64);
00049
00061 virtual ~scheduler();
00062
00063 IMPLEMENT_CLASS_NAME("scheduler");
00064
00065
00066
00067 const int_averager &processing_durations() const;
00069
00072 const int_averager &activation_durations() const;
00074
00076 const int_averager &item_durations() const;
00078
00079 const int_averager &bandwidths() const;
00081
00084 int snooze_interval() const { return _snooze_interval; }
00086
00087 void reset_stats();
00089
00092
00093
00094
00095
00096 outcome add(schedulable *to_schedule, bool single_file);
00098
00108
00109
00110
00111 void start_scheduling();
00112 void stop_scheduling();
00113
00115
00116
00117
00118
00119 outcome remove_by_id(scheduling_id id);
00121
00125 outcome remove_by_actor(int actor_id);
00127
00130 outcome mark_dead(scheduling_id to_mark);
00132
00136 void filter_missing_actors(const int_set &valid_actors);
00138
00140
00141 void schedule_text_form(string_array &info, int indent = 0);
00143
00145 void pending_text_form(istring &info, int indent = 0);
00147
00152 void memory_text_form(istring &info, int indent = 2);
00154
00156
00157 schedule_iterator *open_iterator(common::list_positions where = common::HEAD);
00159
00161 schedule_iterator *find(scheduling_id to_find);
00163
00165 void close_iterator(schedule_iterator * &to_close);
00167
00169 const schedulable *active_item(schedule_iterator &to_use) const;
00171
00175 bool items_scheduled(schedule_iterator &to_use, int actor);
00177
00180 void zap(schedule_iterator &to_use);
00182
00184 private:
00185 actor_mapper &_mapper;
00186 int _time_per_item;
00187 nodes::safe_list *_schedule;
00188 int_averager *_processing_durations;
00189 int_averager *_activation_durations;
00190 int_averager *_item_durations;
00191 int_averager *_bandwidths;
00192 schedulable *_active_item;
00193 memory_limiter *_weight_tracker;
00194 mailbox *_pending_sends;
00195 int_set *_timely_to_run;
00196 int_set *_queued_actors;
00197 int _snooze_interval;
00198
00199 friend class schedule_driver;
00200 schedule_driver *_driver;
00202
00203 outcome process_schedule(int schedulings_allowed);
00205
00218 bool time_to_schedule(schedulable &to_check);
00220
00221 outcome check_expiration(schedulable &to_check, schedule_actor &actor);
00223
00225 outcome do_preprocess(schedulable &to_preprocess);
00227
00230 void promote_queued_items();
00232
00235 void promote_actor(int actor_id);
00237
00238 bool find_timely_items(int_set &timely);
00240
00242 outcome schedule_item(int &hits, schedulable &to_process);
00244
00250 void crunch_on_timely_items(int &hits, int hits_allowed, int_set &timely);
00252
00254
00255 scheduler(const scheduler &to_copy);
00256 scheduler &operator =(const scheduler &to_copy);
00257 };
00258
00260
00262
00263 class SCHEDULING_CLASS_STYLE schedule_iterator
00264 {
00265 public:
00266 ~schedule_iterator();
00268
00271 void next();
00272 void previous();
00273
00274 schedulable *access();
00275
00276 bool is_head();
00277 bool is_tail();
00278
00279 void jump_head();
00280 void jump_tail();
00281
00282 private:
00283 friend class scheduler;
00284 const scheduler &_manager;
00285 nodes::safe_list_write_iterator *_hidden_iterator;
00286
00287 schedule_iterator(const scheduler &mgr);
00289
00290
00291 schedule_iterator(const schedule_iterator &to_copy);
00292 schedule_iterator &operator =(const schedule_iterator &to_copy);
00293 };
00294
00295 #endif
00296