You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			67 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C++
		
	
			
		
		
	
	
			67 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C++
		
	
| // vim: set noet ts=4 sw=4:
 | |
| 
 | |
| /*! \file
 | |
|  *  \brief \ref Dispatcher for \ref Thread threads
 | |
|  */
 | |
| #pragma once
 | |
| #include "../thread/thread.h"
 | |
| #include "../types.h"
 | |
| 
 | |
| /*! \brief The dispatcher dispatches threads and puts the scheduler's
 | |
|  *  decisions into action.
 | |
|  *  \ingroup thread
 | |
|  *
 | |
|  *  The dispatcher manages the life pointer that refers to the currently
 | |
|  *  active thread and performs the actual switching of processes.
 | |
|  *  For single-core systems, a single life pointer is sufficient, as only a
 | |
|  *  single thread can be active at any one time. On multi-core systems,
 | |
|  *  every CPU core needs its own life pointer.
 | |
|  */
 | |
| class Dispatcher {
 | |
|   /*! \brief set the currently active thread
 | |
|    *  \param thread active Thread
 | |
|    */
 | |
|   void setActive(Thread* thread) { (void)thread; }
 | |
| 
 | |
|  public:
 | |
|   /*! \brief constructor
 | |
|    *
 | |
|    *	\todo(14) Implement Method
 | |
|    */
 | |
|   Dispatcher();
 | |
| 
 | |
|   /*! \brief Returns the thread currently running on the CPU core calling
 | |
|    *  this method
 | |
|    *
 | |
|    *  \todo(14) Implement Method
 | |
|    */
 | |
|   Thread* active();
 | |
| 
 | |
|   /*! \brief Check if thread is currently active
 | |
|    *  \param thread Pointer to the thread in question
 | |
|    *  \param cpu will receive the core number if `cpu` pointer is not `nullptr`
 | |
|    *             and the thread is currently active
 | |
|    *  \return `true` if currently running, false otherwise
 | |
|    *
 | |
|    *  \todo(15) Implement method for kill IPI (in \MPStuBS only)
 | |
|    */
 | |
|   bool isActive(const Thread* thread, unsigned* cpu = nullptr);
 | |
| 
 | |
|   /*! \brief This method stores first as life pointer for this CPU core and
 | |
|    *  triggers the execution of first. Only to be used for the first thread
 | |
|    *  running on a CPU.
 | |
|    *  \param first First thread to be executed on this CPU core.
 | |
|    *
 | |
|    *  \todo(14) Implement Method
 | |
|    */
 | |
|   void go(Thread* first);
 | |
| 
 | |
|   /*! \brief Updates the life pointer to next and issues a thread change from
 | |
|    *  the old to the new life pointer.
 | |
|    *  \param next Next thread to be executed.
 | |
|    *
 | |
|    *  \todo(14) Implement Method
 | |
|    */
 | |
|   void dispatch(Thread* next);
 | |
| };
 |