2023-06-24 03:14:17 +02:00
/*
SCHEDULER - INVOCATION . hpp - invocation layer of the render engine scheduler
Copyright ( C ) Lumiera . org
2023 , Hermann Vosseler < Ichthyostega @ web . de >
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation ; either version 2 of
the License , or ( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
/** @file scheduler-invocation.hpp
* * Layer - 1 of the Scheduler : dispatch and invocation of activities .
* * This is the lower layer of the implementation and provides low - level functionality .
* *
* * @ note as of X / 2023 this is complete bs
* * @ see ////TODO_test usage example
* * @ see scheduler . cpp implementation
* *
* * @ todo WIP - WIP - WIP 6 / 2023 » Playback Vertical Slice «
* *
*/
# ifndef SRC_VAULT_GEAR_SCHEDULER_INVOCATION_H_
# define SRC_VAULT_GEAR_SCHEDULER_INVOCATION_H_
# include "vault/common.hpp"
# include "lib/nocopy.hpp"
//#include "lib/symbol.hpp"
2023-06-25 01:02:12 +02:00
# include "vault/gear/activity.hpp"
2023-06-24 03:14:17 +02:00
//#include "lib/util.hpp"
//#include <string>
2023-06-25 01:02:12 +02:00
# include <queue>
# include <boost/lockfree/queue.hpp>
2023-06-26 02:16:50 +02:00
# include <utility>
2023-06-24 03:14:17 +02:00
namespace vault {
namespace gear {
2023-06-26 02:16:50 +02:00
namespace error = lumiera : : error ;
2023-06-24 03:14:17 +02:00
// using util::isnil;
// using std::string;
2023-06-26 02:16:50 +02:00
using std : : move ;
2023-06-24 03:14:17 +02:00
/**
* Scheduler Layer - 2 : invocation .
*
* @ see SomeSystem
* @ see NA_test
*/
class SchedulerInvocation
: util : : NonCopyable
{
2023-06-25 01:02:12 +02:00
struct ActOrder
{
size_t waterlevel { 0 } ;
Activity * activity { nullptr } ;
2023-06-26 02:16:50 +02:00
/** @internal ordering function for time based scheduling
* @ note reversed order as required by std : : priority_queue
* to get the earliest element at top of the queue
*/
bool
operator < ( ActOrder const & o ) const
{
return waterlevel > o . waterlevel ;
}
2023-06-25 01:02:12 +02:00
} ;
using InstructQueue = boost : : lockfree : : queue < ActOrder > ;
using PriorityQueue = std : : priority_queue < ActOrder > ;
InstructQueue instruct_ ;
PriorityQueue priority_ ;
2023-06-24 03:14:17 +02:00
public :
2023-06-26 02:16:50 +02:00
// explicit
SchedulerInvocation ( )
2023-06-24 03:14:17 +02:00
{ }
2023-06-26 02:16:50 +02:00
/**
* Accept an Activity for time - bound execution
*/
void
instruct ( Activity & activity )
{
size_t waterLevel = 123 ; /////////////////////////////////////////////////////OOO derive water level from time window
bool success = instruct_ . push ( ActOrder { waterLevel , & activity } ) ;
if ( not success )
throw error : : Fatal { " Scheduler entrance: memory allocation failed " } ;
}
/**
* Pick up a new Activity and enqueue it according to time order
*/
void
prioriseNext ( )
{
ActOrder actOrder ;
bool hasInput = instruct_ . pop ( actOrder ) ;
if ( not hasInput )
return ;
priority_ . push ( move ( actOrder ) ) ;
}
/**
* If there is an Activity to process now , pick it from the scheduling queue
*/
Activity &
acceptHead ( )
{
Activity * activity = priority_ . top ( ) . activity ;
///////////////////////////////////////////////////////////////////////////////OOO need to handle an empty queue or an Activity not ready to schedule yet
priority_ . pop ( ) ;
return * activity ;
}
2023-06-24 03:14:17 +02:00
} ;
} } // namespace vault::gear
# endif /*SRC_VAULT_GEAR_SCHEDULER_INVOCATION_H_*/