![]() |
Oyranos
git-devel
Oyranos is a full featured Color Management System
|
Asynchron processing support. More...
![]() |
Data Structures | |
struct | oyJob_s |
Asynchron job ticket. More... | |
Typedefs | |
typedef int(* | oyJob_Add_f) (oyJob_s **job, int finished, int flags) |
Add one unique oyJob_s to the job qeue. More... | |
typedef int(* | oyJob_Get_f) (oyJob_s **job, int finished) |
Get one unique oyJob_s from the job qeue. More... | |
typedef int(* | oyMsg_Add_f) (oyJob_s *job, double progress_zero_till_one, char **status_text) |
Add one unique message from the message qeue. More... | |
typedef void(* | oyJobResult_f) (void) |
Poll for new Jobs. More... | |
typedef int(* | oyThreadId_f) (void) |
Get one unique thread ID. More... | |
typedef void(* | oyJobCallback_f) (double progress_zero_till_one, char *status_text, int thread_id_, int job_id, oyStruct_s *cb_progress_context) |
Progress callback for parallel job processing. More... | |
Functions | |
void | oyThreadLockingSet (oyStruct_LockCreate_f createLockFunc, oyLockRelease_f releaseLockFunc, oyLock_f lockFunc, oyUnLock_f unlockFunc) |
set locking functions for threaded applications More... | |
void | oyThreadLockingReset () |
unset locking functions for threaded applications More... | |
int | oyThreadLockingReady (void) |
tell if thread locking is ready More... | |
void | oyJob_s::oyJobHandlingSet (oyJob_Add_f jadd, oyJob_Get_f jget, oyMsg_Add_f madd, oyJobResult_f result, const char *nick) |
Initialise the oyJob_s APIs. More... | |
void | oyJob_s::oyJobHandlingReset () |
Reset the oyJob_s APIs. More... | |
oyJob_s * | oyJob_s::oyJob_New (oyObject_s object OY_UNUSED) |
Allocate a new oyJob_s object. More... | |
void | oyJob_s::oyJob_Release (oyJob_s **job) |
Deallocate a oyJob_s object. More... | |
Variables | |
oyJob_Add_f | oyJob_s::oyJob_Add = oyJob_AddInit |
Add one unique oyJob_s to the job qeue. More... | |
oyJob_Get_f | oyJob_s::oyJob_Get = oyJob_GetInit |
Get one unique oyJob_s from the job qeue. More... | |
oyMsg_Add_f | oyJob_s::oyMsg_Add = oyMsg_AddInit |
Add one unique message from the message qeue. More... | |
oyJobResult_f | oyJob_s::oyJobResult = oyJobResultInit |
Poll for messages and finished jobs. More... | |
oyThreadId_f | oyThreadId = oyThreadIdInit |
Get one unique thread Id. More... | |
Asynchron processing support.
Threading support in Oyranos is kept intentionally simple. Object level locking is available. Eigther avoid Oyranos locking by encapsulating it into a own locking model. Or provide locking functions in oyThreadLockingSet(), which can detect recursive lock conditions. Recursive locks might not be a problem with POSIX systems and pthreads PTHREAD_MUTEX_RECURSIVE.
Job handling is more complex. A version is provided in the "trds" module and will be initialised by default during first use of the APIs. This version used a threading model as is available during compilation. In case you want a own threading model you can provide it through oyJobHandlingSet().
Some expensive workload is good to load off to a background job and continue in the foreground for non interupted user interaction. E.g. the user should be able to continue interacting with the image/movie, even while changed options need computing of the current DAG contexts.
The background jobs tend to be related to tasks inside the Oyranos DAG and can not easily be handled outside the DAG. For instance it is not easy to replace a expensive DAG while performing a expensive option change - big image or movie + switching on/off proofing/effects.
Threading models can very easily conflict and linking can become a night mare. Thus threading from "trds" plug-in must be replaceable on the descretion of users.
Call oyThreadLockingSet() in order to use own thread locking functions. Call oyJobHandlingSet() to replace by own Job handling functions. The functions must be used before any call to Oyranos.
A oyJob_New() creates a new oyJob_s object which can be added to the job qeue by oyJob_Add(). Job creation and Job adding belongs to the managing thread. Calling oyJob_Add() for the first time in the process initialises the API's and starts the worker threads. oyJob_s::work() is called from inside the worker thread.
oyJob_s::work() does the asynchron oyJob_s::context processing. It can add messages with oyMsg_Add() to the message qeue. After returning from oyJob_s::work() the job object is placed back into the job qeue and marked as done (finished == 1) by the thread handling plug-in.
Calling oyJobResult() in managing thread, usually the main GUI thread, allows to obtain progress status from the Oyranos worker threads. jobPrintfCallback() is the default message callback and just does printing a status information, which were previously add inside the oyJob_s::work() inside the worker thread with oyMsg_Add(). The oyJob_s object, including the processed data, is placed into the job qeue after oyJob_s::work() returned. To access the oyJob_s use the oyJob_s::finish() callback. oyJobResult() is as well responsible to call oyJob_s::finish() from the managing/UI thread for that.
See Environment Variables .
oyJob_Add_f |
Add one unique oyJob_s to the job qeue.
oyJob_Get_f |
Get one unique oyJob_s from the job qeue.
oyJobCallback_f |
Progress callback for parallel job processing.
progress_zero_till_one | will be called by the work thread with 0.0 before start of oyJob_s::work() and after with 1.0 between oyMsg_Add() can be used inside oyJob_s::work() to add more fine grained status info |
status_text | textual description of the work progress |
thread_id_ | work thread info |
job_id | id of the job |
cb_progress_context | GUI context; e.g. gauge/progress bar ... (unused) |
oyJobResult_f |
Poll for new Jobs.
oyMsg_Add_f |
Add one unique message from the message qeue.
oyThreadId_f |
Get one unique thread ID.
oyJob_s * oyJob_New | ( | oyObject_s object | OY_UNUSED | ) |
Allocate a new oyJob_s object.
Function oyJob_New
A object argument is ignored.
void oyJob_Release | ( | oyJob_s ** | job | ) |
Deallocate a oyJob_s object.
Function oyJob_Release
References oyOBJECT_JOB_S, and oyJob_s::type_.
void oyJobHandlingReset | ( | ) |
Reset the oyJob_s APIs.
Clean all functions for new initialisation. Otherwise the behaviour is undefined.
References oyJob_s::oyJobHandlingSet().
void oyJobHandlingSet | ( | oyJob_Add_f | jadd, |
oyJob_Get_f | jget, | ||
oyMsg_Add_f | madd, | ||
oyJobResult_f | result, | ||
const char * | nick | ||
) |
Initialise the oyJob_s APIs.
Be careful to set the APIs only before any call to the oyJob_s functions. Otherwise the behaviour is undefined.
References oyJob_s::oyJob_Add, oyJob_s::oyJob_Get, oyJob_s::oyJobResult, and oyJob_s::oyMsg_Add.
Referenced by oyJob_s::oyJobHandlingReset().
int oyThreadLockingReady | ( | void | ) |
tell if thread locking is ready
void oyThreadLockingReset | ( | ) |
unset locking functions for threaded applications
Function: oyThreadLockingReset
Use this after threads ended to remove resources.
void oyThreadLockingSet | ( | oyStruct_LockCreate_f | createLockFunc, |
oyLockRelease_f | releaseLockFunc, | ||
oyLock_f | lockFunc, | ||
oyUnLock_f | unlockFunc | ||
) |
set locking functions for threaded applications
Function: oyThreadLockingSet
oyJob_Add_f oyJob_Add = oyJob_AddInit |
Add one unique oyJob_s to the job qeue.
job | the job object |
finished | mark the job in the queue
|
flags | hint on how to process the job
|
Referenced by oyJob_s::oyJobHandlingSet().
oyJob_Get_f oyJob_Get = oyJob_GetInit |
Get one unique oyJob_s from the job qeue.
Referenced by oyJob_s::oyJobHandlingSet().
oyJobResult_f oyJobResult = oyJobResultInit |
Poll for messages and finished jobs.
The function does two things. It calls oyJob_s::cb_progress() from a filled message qeue. And it takes jobs out of the job qeue, which are marked as finalised. oyJob_s::finish() is optionally called. After the oyJob_s::finish() callback the job is released.
The function is usually called from the managing-and main UI thread.
Referenced by oyJob_s::oyJobHandlingSet().
oyMsg_Add_f oyMsg_Add = oyMsg_AddInit |
Add one unique message from the message qeue.
Referenced by oyJob_s::oyJobHandlingSet().
oyThreadId_f oyThreadId = oyThreadIdInit |
Get one unique thread Id.