blob: 94860f5d3c0c033b71bf7981fdc07cdb79714c20 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/*
* Copyright (C) 2012 Tobias Brunner
* Copyright (C) 2005-2007 Martin Willi
* Copyright (C) 2005 Jan Hutter
* Hochschule fuer Technik Rapperswil
*
* 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. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* 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.
*/
/**
* @defgroup processor processor
* @{ @ingroup processing
*/
#ifndef PROCESSOR_H_
#define PROCESSOR_H_
typedef struct processor_t processor_t;
#include <stdlib.h>
#include <library.h>
#include <processing/jobs/job.h>
/**
* The processor uses threads to process queued jobs.
*/
struct processor_t {
/**
* Get the total number of threads used by the processor.
*
* @return size of thread pool
*/
u_int (*get_total_threads) (processor_t *this);
/**
* Get the number of threads currently waiting for work.
*
* @return number of idle threads
*/
u_int (*get_idle_threads) (processor_t *this);
/**
* Get the number of threads currently working, per priority class.
*
* @param priority to check
* @return number of threads in priority working
*/
u_int (*get_working_threads)(processor_t *this, job_priority_t prio);
/**
* Get the number of queued jobs for a specified priority.
*
* @param prio priority class to get job load for
* @return number of items in queue
*/
u_int (*get_job_load) (processor_t *this, job_priority_t prio);
/**
* Adds a job to the queue.
*
* This function is non blocking and adds a job_t to the queue.
*
* @param job job to add to the queue
*/
void (*queue_job) (processor_t *this, job_t *job);
/**
* Set the number of threads to use in the processor.
*
* If the number of threads is smaller than number of currently running
* threads, thread count is decreased. Use 0 to disable the processor.
*
* This call does not block and wait for threads to terminate if the number
* of threads is reduced. Instead use cancel() for that during shutdown.
*
* @param count number of threads to allocate
*/
void (*set_threads)(processor_t *this, u_int count);
/**
* Sets the number of threads to 0 and cancels all blocking jobs, then waits
* for all threads to be terminated.
*/
void (*cancel)(processor_t *this);
/**
* Destroy a processor object.
*/
void (*destroy) (processor_t *processor);
};
/**
* Create the thread pool without any threads.
*
* Use the set_threads method to start processing jobs.
*
* @return processor_t object
*/
processor_t *processor_create();
#endif /** PROCESSOR_H_ @}*/
|