Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

sched_context.h

Go to the documentation of this file.
00001 // AUTOMATICALLY GENERATED -- DO NOT EDIT!         -*- c++ -*-
00002 
00003 #ifndef sched_context_h
00004 #define sched_context_h
00005 
00006 #include "types.h"
00007 
00008 //
00009 // INTERFACE definition follows 
00010 //
00011 
00012 
00013 class Context;
00014 class slab_cache_anon;
00015 
00016 /*
00017  * Timeslice infrastructure
00018  */
00019 
00020 
00021 class Sched_context
00022 {
00023   friend class Jdb_list_timeouts;
00024 
00025 public:
00029   enum Preemption_type {
00030     None,
00031     Timeslice_overrun,
00032     Deadline_miss
00033   };
00034 
00035 private:
00036   Context * const       _owner;
00037   unsigned short const  _id;
00038   unsigned short        _prio;
00039   Unsigned64            _quantum;
00040   Unsigned64            _left;
00041   Preemption_type       _preemption_type;
00042   Cpu_time              _preemption_time;
00043   unsigned              _preemption_count;
00044   Sched_context *       _prev;
00045   Sched_context *       _next;
00046 
00050   static slab_cache_anon * _slabs;
00051   friend void allocator_init();
00052 
00053 public:  
00057   Sched_context(Context * const owner, unsigned short const id, unsigned short prio, Unsigned64 quantum);
00058   
00062   inline void * operator new (size_t);
00063   
00067   inline void operator delete (void * const ptr);
00068   
00072   inline Sched_context * next() const;
00073   
00077   inline Sched_context * prev() const;
00078   
00082   inline void enqueue_before(Sched_context * const sibling);
00083   
00087   inline void dequeue();
00088   
00092   inline Context * owner() const;
00093   
00097   inline unsigned short id() const;
00098   
00102   inline unsigned short prio() const;
00103   
00107   inline void set_prio(unsigned short const prio);
00108   
00112   inline Unsigned64 quantum() const;
00113   
00117   inline void set_quantum(Unsigned64 const quantum);
00118   
00122   inline Unsigned64 left() const;
00123   
00127   inline void set_left(Unsigned64 const left);
00128   
00132   inline Sched_context::Preemption_type preemption_type() const;
00133   
00137   inline Cpu_time preemption_time() const;
00138   
00142   inline unsigned preemption_count() const;
00143   
00147   inline void set_preemption_event(Preemption_type const type, Cpu_time const clock);
00148   
00149   inline void clear_preemption_event();
00150   
00154   inline Sched_context * find_next_preemption();
00155 };
00156 
00157 //
00158 // IMPLEMENTATION includes follow (for use by inline functions)
00159 //
00160 
00161 
00162 #include <cassert>
00163 #include "cpu_lock.h"
00164 #include "kdb_ke.h"
00165 #include "lock_guard.h"
00166 #include "slab_cache_anon.h"
00167 
00168 //
00169 // IMPLEMENTATION of inline functions (and needed classes)
00170 //
00171 
00172 
00173 
00178 inline void *
00179 Sched_context::operator new (size_t)
00180 {
00181   void *ptr = _slabs->alloc();
00182 
00183   if (!ptr)
00184     kdb_ke ("Sched_context: Out of slab memory!");
00185 
00186   return ptr;
00187 }
00188 
00189 
00194 inline void
00195 Sched_context::operator delete (void * const ptr)
00196 {
00197   _slabs->free (ptr);
00198 }
00199 
00200 
00205 inline Sched_context *
00206 Sched_context::next() const
00207 {
00208   return _next;
00209 }
00210 
00211 
00216 inline Sched_context *
00217 Sched_context::prev() const
00218 {
00219   return _prev;
00220 }
00221 
00222 
00227 inline void
00228 Sched_context::enqueue_before(Sched_context * const sibling)
00229 {
00230   Lock_guard <Cpu_lock> guard (&cpu_lock);
00231 
00232   _next = sibling;
00233   _prev = sibling->prev();
00234 
00235   assert (_prev);
00236 
00237   _prev->_next = sibling->_prev = this;
00238 }
00239 
00240 
00245 inline void
00246 Sched_context::dequeue()
00247 {
00248   Lock_guard <Cpu_lock> guard (&cpu_lock);
00249 
00250   _prev->_next = _next;
00251   _next->_prev = _prev;
00252 }
00253 
00254 
00259 inline Context *
00260 Sched_context::owner() const
00261 {
00262   return _owner;
00263 }
00264 
00265 
00270 inline unsigned short
00271 Sched_context::id() const
00272 {
00273   return _id;
00274 }
00275 
00276 
00281 inline unsigned short
00282 Sched_context::prio() const
00283 {
00284   return _prio;
00285 }
00286 
00287 
00292 inline void
00293 Sched_context::set_prio(unsigned short const prio)
00294 {
00295   _prio = prio;
00296 }
00297 
00298 
00303 inline Unsigned64
00304 Sched_context::quantum() const
00305 {
00306   return _quantum;
00307 }
00308 
00309 
00314 inline void
00315 Sched_context::set_quantum(Unsigned64 const quantum)
00316 {
00317   _quantum = quantum;
00318 }
00319 
00320 
00325 inline Unsigned64
00326 Sched_context::left() const
00327 {
00328   return _left;
00329 }
00330 
00331 
00336 inline void
00337 Sched_context::set_left(Unsigned64 const left)
00338 {
00339   _left = left;
00340 }
00341 
00342 
00347 inline Sched_context::Preemption_type
00348 Sched_context::preemption_type() const
00349 {
00350   return _preemption_type;
00351 }
00352 
00353 
00358 inline Cpu_time
00359 Sched_context::preemption_time() const
00360 {
00361   return _preemption_time;
00362 }
00363 
00364 
00369 inline unsigned
00370 Sched_context::preemption_count() const
00371 {
00372   return _preemption_count;
00373 }
00374 
00375 
00380 inline void
00381 Sched_context::set_preemption_event(Preemption_type const type,
00382                                      Cpu_time const clock)
00383 {
00384   _preemption_type = type;
00385   _preemption_time = clock;
00386   _preemption_count++;
00387 }
00388 
00389 
00390 
00391 inline void
00392 Sched_context::clear_preemption_event()
00393 {
00394   _preemption_type  = None;
00395   _preemption_count = 0;
00396 }
00397 
00398 
00403 inline Sched_context *
00404 Sched_context::find_next_preemption()
00405 {
00406   // Clear preemption event for this Sched_context
00407   clear_preemption_event();
00408 
00409   // Now find the next Sched_context with a pending preemption event
00410   for (Sched_context *tmp = next(); tmp != this; tmp = tmp->next())
00411     if (tmp->preemption_type() != None)
00412       return tmp;
00413 
00414   return 0;
00415 }
00416 
00417 #endif // sched_context_h

Generated on Mon Sep 26 14:20:12 2005 for Fiasco by  doxygen 1.4.2