2012-02-17 01:54:51 +01:00
/*
Job - render job closure
Copyright ( C ) Lumiera . org
2012 , 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 .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-02-19 00:43:35 +01:00
/** @file job.cpp
* * Implementation of render job invocation .
2013-08-30 02:00:35 +02:00
* * Within this translation unit , the actual invocation of a frame rendering job
* * takes place , after reconstruction of the job ' s execution environment ( closure ) .
2012-02-19 00:43:35 +01:00
* *
* * @ see JobTicket
* * @ see ProcNode
* * @ see nodeinvocation . hpp
* *
*/
2018-11-15 23:42:43 +01:00
# include "vault/engine/job.h"
2023-05-01 01:48:36 +02:00
# include "vault/engine/nop-job-functor.hpp"
2013-09-07 02:37:17 +02:00
# include "lib/util.hpp"
2012-02-17 01:54:51 +01:00
2013-09-01 02:30:14 +02:00
# include <boost/functional/hash.hpp>
# include <typeinfo>
2012-02-17 01:54:51 +01:00
2018-11-15 23:55:13 +01:00
namespace vault {
2012-02-17 01:54:51 +01:00
namespace engine {
namespace { // Details...
2012-02-19 00:43:35 +01:00
inline JobClosure &
myClosure ( const Job * const self )
{
ASSERT ( self ) ;
ASSERT ( self - > jobClosure ) ;
return * static_cast < JobClosure * > ( self - > jobClosure ) ;
}
2012-02-17 01:54:51 +01:00
} // (END) Details...
2013-09-07 02:37:17 +02:00
using lib : : HashVal ;
using util : : isSameObject ;
2012-02-17 01:54:51 +01:00
2013-05-31 02:59:32 +02:00
/**
2023-04-20 23:55:02 +02:00
* emit the VTable for JobFunctor within this compilation unit ,
2018-11-15 21:13:52 +01:00
* which is still part of the Vault . The actual job implementation
* classes are defined in the Steam - Layer
2013-05-31 02:59:32 +02:00
*/
2023-04-20 23:55:02 +02:00
JobFunctor : : ~ JobFunctor ( ) { }
JobClosure : : ~ JobClosure ( ) { } ///< @deprecated 4/23 refactoring to retract C-structs from the Scheduler interface
2013-05-31 02:59:32 +02:00
2023-05-01 01:48:36 +02:00
NopJobFunctor : : NopJobFunctor ( ) { }
2013-05-31 02:59:32 +02:00
2012-02-17 01:54:51 +01:00
void
2013-08-17 03:37:36 +02:00
Job : : triggerJob ( ) const
2012-02-17 01:54:51 +01:00
{
2013-08-18 03:16:49 +02:00
myClosure ( this ) . invokeJobOperation ( parameter ) ;
2012-02-17 01:54:51 +01:00
}
void
2013-08-30 02:00:35 +02:00
Job : : signalFailure ( JobFailureReason reason ) const
2012-02-17 01:54:51 +01:00
{
2013-08-30 02:00:35 +02:00
myClosure ( this ) . signalFailure ( parameter , reason ) ;
2012-02-17 01:54:51 +01:00
}
2012-02-19 00:43:35 +01:00
2012-04-27 18:59:08 +02:00
/** find out about the classification of this job.
* Typically its not necessary for the normal scheduling of
* Jobs to know anything beyond the contents of the # lumiera_jobDescriptor ,
* but the JobClosure is able to answer any additional introspection queries
*/
JobKind
Job : : getKind ( ) const
{
REQUIRE ( isValid ( ) ) ;
2012-04-28 04:18:00 +02:00
return myClosure ( this ) . getJobKind ( ) ;
2012-04-27 18:59:08 +02:00
}
2012-02-19 00:43:35 +01:00
/** Render Job self verification.
* performs a parameter consistency check
* including a call - back to the defining JobTicket
*/
bool
Job : : isValid ( ) const
{
return this - > jobClosure
2018-11-17 17:25:10 +01:00
and myClosure ( this ) . verify ( getNominalTime ( ) ,
2013-09-02 00:26:04 +02:00
getInvocationInstanceID ( ) ) ;
2012-02-19 00:43:35 +01:00
}
2012-02-17 01:54:51 +01:00
2013-09-07 02:37:17 +02:00
bool
Job : : usesClosure ( JobClosure const & otherClosure ) const
{
return isSameObject ( myClosure ( this ) , otherClosure ) ;
}
2013-09-01 02:30:14 +02:00
/** hash value based on all relevant job data.
* Job records hashing to the same value shall be considered equivalent .
* Since the interpretation of the # InvocationInstanceID is a private detail
* of the JobClosure , calculating this hash requires a virtual call into the
* concrete JobClosure . This is not considered problematic , as the normal
* job operation and scheduling doesn ' t rely on the job ' s hash . Only some
* diagnostic facilities do . */
2013-09-07 02:37:17 +02:00
HashVal
2013-09-01 02:30:14 +02:00
hash_value ( Job const & job )
{
2013-09-07 02:37:17 +02:00
return myClosure ( & job ) . hash_value ( job . parameter ) ;
2013-09-01 02:30:14 +02:00
}
2013-09-07 02:37:17 +02:00
HashVal
JobClosure : : hash_value ( JobParameter parameter ) const
{
HashVal hash = this - > hashOfInstance ( parameter . invoKey ) ;
2016-01-10 11:21:34 +01:00
boost : : hash_combine ( hash , typeid ( * this ) . hash_code ( ) ) ;
2013-09-07 02:37:17 +02:00
boost : : hash_combine ( hash , parameter . nominalTime ) ;
return hash ;
}
2013-09-01 02:30:14 +02:00
2018-11-15 23:55:13 +01:00
} } // namespace vault::engine
2012-02-17 01:54:51 +01:00
namespace {
2018-11-15 23:59:23 +01:00
using vault : : engine : : Job ;
2012-02-17 01:54:51 +01:00
inline Job &
2012-02-19 00:43:35 +01:00
forwardInvocation ( lumiera_jobDefinition & jobDef )
2012-02-17 01:54:51 +01:00
{
2012-02-19 00:43:35 +01:00
Job & job = static_cast < Job & > ( jobDef ) ;
2012-02-17 01:54:51 +01:00
2012-02-19 00:43:35 +01:00
REQUIRE ( job . isValid ( ) ) ;
return job ;
2012-02-17 01:54:51 +01:00
}
}
2012-02-19 00:43:35 +01:00
2012-02-17 01:54:51 +01:00
extern " C " { /* ==== implementation C interface for job invocation ======= */
void
2013-08-24 15:29:00 +02:00
lumiera_job_invoke ( LumieraJobDefinition jobDef )
2012-02-17 01:54:51 +01:00
{
2013-08-24 15:29:00 +02:00
REQUIRE ( jobDef ) ;
forwardInvocation ( * jobDef ) . triggerJob ( ) ;
2012-02-17 01:54:51 +01:00
}
void
2013-08-30 02:00:35 +02:00
lumiera_job_failure ( LumieraJobDefinition jobDef , JobFailureReason reason )
2012-02-17 01:54:51 +01:00
{
2013-08-24 15:29:00 +02:00
REQUIRE ( jobDef ) ;
2013-08-30 02:00:35 +02:00
forwardInvocation ( * jobDef ) . signalFailure ( reason ) ;
2012-02-17 01:54:51 +01:00
}
2013-09-08 19:19:02 +02:00
size_t
lumiera_job_get_hash ( LumieraJobDefinition jobDef )
{
REQUIRE ( jobDef ) ;
return hash_value ( forwardInvocation ( * jobDef ) ) ;
}
2023-05-01 14:07:21 +02:00
/////////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1287 : temporary workaround until we get rid of the C base structs
# include "lib/luid.h"
int
lumiera_invokey_eq ( void * l , void * r )
{
return lumiera_uid_eq ( ( LumieraUid ) l , ( LumieraUid ) r ) ;
}
2012-02-17 01:54:51 +01:00
}