Pol  Revision:4b29d2b
script_internals.h
Go to the documentation of this file.
1 #ifndef GLOBALS_SCRIPT_INTERNALS_H
2 #define GLOBALS_SCRIPT_INTERNALS_H
3 
4 #include <boost/noncopyable.hpp>
5 #include <deque>
6 #include <map>
7 #include <set>
8 
9 #include "../../bscript/eprog.h"
10 #include "../../clib/maputil.h"
11 #include "../polclock.h"
12 #include "../reftypes.h"
13 
14 namespace Pol
15 {
16 namespace Core
17 {
18 class UOExecutor;
19 
20 typedef std::deque<UOExecutor*> ExecList;
21 typedef std::set<UOExecutor*> NoTimeoutHoldList;
22 typedef std::multimap<Core::polclock_t, Core::UOExecutor*> HoldList;
23 typedef std::map<std::string, ref_ptr<Bscript::EScriptProgram>, Clib::ci_cmp_pred> ScriptStorage;
24 typedef std::map<unsigned int, UOExecutor*> PidList;
25 typedef HoldList::iterator TimeoutHandle;
26 
27 class ScriptScheduler : boost::noncopyable
28 {
29 public:
30  static const unsigned int PID_MIN;
31 
33 
34  // Consider moving the ScriptStorage to a different class.
35  // It's not even used here besides to calculate how much memory is used.
36  ScriptStorage scrstore;
37 
40  void deinitialize();
41 
42  struct Memory
43  {
44  size_t script_count;
45  size_t script_size;
48  };
49  Memory estimateSize() const;
50 
51  void run_ready();
52 
53  const ExecList& getRanlist();
54  const ExecList& getRunlist();
55  const HoldList& getHoldlist();
56  const NoTimeoutHoldList& getNoTimeoutHoldlist();
57 
58  const PidList& getPidlist();
59 
60  // void revive_timeout(UOExecutor* exec);
61  void revive_timeout( UOExecutor* exec, TimeoutHandle hold_itr );
62  void revive_notimeout( UOExecutor* exec );
63  void revive_debugged( UOExecutor* exec );
64 
65  // Adds a new executor to the queue directly
66  void enqueue( UOExecutor* exec );
67 
68  // Sets up the executor before adding to the queue
69  void schedule( UOExecutor* exec );
70 
71 
72  // The following methods should go to a different class,
73  // together with the pidlist and new_pid.
74 
75  // Gets new PID and store the executor in the pidlist
76  unsigned int get_new_pid( UOExecutor* exec );
77 
78  void free_pid( unsigned int pid );
79 
80  // Finds an UOExecutor from a pid. Returns false if not found.
81  bool find_exec( unsigned int pid, UOExecutor** exec );
82 
83 
84 private:
85  ExecList runlist;
86  ExecList ranlist;
87  HoldList holdlist;
88  NoTimeoutHoldList notimeoutholdlist;
89  NoTimeoutHoldList debuggerholdlist;
90 
91  PidList pidlist;
92  unsigned int next_pid;
93 };
94 
95 const inline ExecList& ScriptScheduler::getRanlist()
96 {
97  return ranlist;
98 }
99 const inline ExecList& ScriptScheduler::getRunlist()
100 {
101  return runlist;
102 }
103 const inline HoldList& ScriptScheduler::getHoldlist()
104 {
105  return holdlist;
106 }
107 const inline NoTimeoutHoldList& ScriptScheduler::getNoTimeoutHoldlist()
108 {
109  return notimeoutholdlist;
110 }
111 const inline PidList& ScriptScheduler::getPidlist()
112 {
113  return pidlist;
114 }
115 
117 {
118  debuggerholdlist.erase( exec );
119  enqueue( exec );
120 }
121 
122 inline void ScriptScheduler::revive_timeout( UOExecutor* exec, TimeoutHandle hold_itr )
123 {
124  holdlist.erase( hold_itr );
125  enqueue( exec );
126 }
127 
129 {
130  notimeoutholdlist.erase( exec );
131  enqueue( exec );
132 }
133 
135 {
136  runlist.push_back( exec );
137 }
138 
139 inline void ScriptScheduler::free_pid( unsigned int pid )
140 {
141  pidlist.erase( pid );
142 }
143 
145 }
146 }
147 #endif
std::set< UOExecutor * > NoTimeoutHoldList
const ExecList & getRanlist()
std::map< std::string, ref_ptr< Bscript::EScriptProgram >, Clib::ci_cmp_pred > ScriptStorage
const HoldList & getHoldlist()
std::map< unsigned int, UOExecutor * > PidList
void enqueue(UOExecutor *exec)
bool find_exec(unsigned int pid, UOExecutor **exec)
u64 pid
Definition: osmod.cpp:945
const ExecList & getRunlist()
HoldList::iterator TimeoutHandle
NoTimeoutHoldList debuggerholdlist
NoTimeoutHoldList notimeoutholdlist
void revive_timeout(UOExecutor *exec, TimeoutHandle hold_itr)
std::multimap< Core::polclock_t, Core::UOExecutor * > HoldList
void revive_notimeout(UOExecutor *exec)
std::deque< UOExecutor * > ExecList
ScriptScheduler scriptScheduler
const PidList & getPidlist()
unsigned int get_new_pid(UOExecutor *exec)
void schedule(UOExecutor *exec)
void revive_debugged(UOExecutor *exec)
const NoTimeoutHoldList & getNoTimeoutHoldlist()
Definition: berror.cpp:12
void free_pid(unsigned int pid)
static const unsigned int PID_MIN