UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
ThreadPool_if.hpp
1
2#ifndef INTERFACE_THREADPOOL_HPP
3#define INTERFACE_THREADPOOL_HPP
4// Copyright (C) 2021+ GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
5// Redistribution only with this Copyright remark. Last modified: 2025-05-30
6
7// Not used at time but have it available for later use. It was too much typing
8// to just throw it away.
9
10#include <ThreadPool.hpp>
11
12// ###############################
13// ThreadPool Interface #
14// ###############################
15
16// clang-format off
17class IThreadPool {
18 public:
19 virtual int ThreadPoolInit(ThreadPool* tp, ThreadPoolAttr* attr) = 0;
20 virtual int ThreadPoolAddPersistent(ThreadPool* tp, ThreadPoolJob* job, int* jobId) = 0;
21 virtual int ThreadPoolAdd(ThreadPool* tp, ThreadPoolJob* job, int* jobId) = 0;
22 virtual int ThreadPoolRemove(ThreadPool* tp, int jobId, ThreadPoolJob* out) = 0;
23 virtual int ThreadPoolGetAttr(ThreadPool* tp, ThreadPoolAttr* out) = 0;
24 virtual int ThreadPoolSetAttr(ThreadPool* tp, ThreadPoolAttr* attr) = 0;
25 virtual int ThreadPoolShutdown(ThreadPool* tp) = 0;
26 virtual int TPAttrInit(ThreadPoolAttr* attr) = 0;
27 virtual int TPJobInit(ThreadPoolJob* job, start_routine func, void* arg) = 0;
28 virtual int TPJobSetPriority(ThreadPoolJob* job, ThreadPriority priority) = 0;
29 virtual int TPJobSetFreeFunction(ThreadPoolJob* job, free_routine func) = 0;
30 virtual int TPAttrSetMaxThreads(ThreadPoolAttr* attr, int maxThreads) = 0;
31 virtual int TPAttrSetMinThreads(ThreadPoolAttr* attr, int minThreads) = 0;
32 virtual int TPAttrSetStackSize(ThreadPoolAttr* attr, size_t stackSize) = 0;
33 virtual int TPAttrSetIdleTime(ThreadPoolAttr* attr, int idleTime) = 0;
34 virtual int TPAttrSetJobsPerThread(ThreadPoolAttr* attr, int jobsPerThread) = 0;
35 virtual int TPAttrSetStarvationTime(ThreadPoolAttr* attr, int starvationTime) = 0;
36 virtual int TPAttrSetSchedPolicy(ThreadPoolAttr* attr, PolicyType schedPolicy) = 0;
37 virtual int TPAttrSetMaxJobsTotal(ThreadPoolAttr* attr, int maxJobsTotal) = 0;
38 virtual void ThreadPoolPrintStats(ThreadPoolStats* stats) = 0;
39 virtual int ThreadPoolGetStats(ThreadPool* tp, ThreadPoolStats* stats) = 0;
40 virtual int gettimeofday(struct timeval* tv, struct timezone* tz) = 0;
41};
42// clang-format on
43
44
45// ###############################
46// ThreadPool from Interface #
47// ###############################
48
49// clang-format off
50class CThreadPool : public IThreadPool {
51 public:
52 int ThreadPoolInit(ThreadPool* tp, ThreadPoolAttr* attr) override {
53 return ::ThreadPoolInit(tp, attr);
54 }
55 int ThreadPoolAddPersistent(ThreadPool* tp, ThreadPoolJob* job, int* jobId) override {
56 return ::ThreadPoolAddPersistent(tp, job, jobId);
57 }
58 int ThreadPoolAdd(ThreadPool* tp, ThreadPoolJob* job, int* jobId) override {
59 return ::ThreadPoolAdd(tp, job, jobId);
60 }
61 int ThreadPoolRemove(ThreadPool* tp, int jobId, ThreadPoolJob* out) override {
62 return ::ThreadPoolRemove(tp, jobId, out);
63 }
64 int ThreadPoolGetAttr(ThreadPool* tp, ThreadPoolAttr* out) override {
65 return ::ThreadPoolGetAttr(tp, out);
66 }
67 int ThreadPoolSetAttr(ThreadPool* tp, ThreadPoolAttr* attr) override {
68 return ::ThreadPoolSetAttr(tp, attr);
69 }
70 int ThreadPoolShutdown(ThreadPool* tp) override {
71 return ::ThreadPoolShutdown(tp);
72 }
73 int TPAttrInit(ThreadPoolAttr* attr) override {
74 return ::TPAttrInit(attr);
75 }
76 int TPJobInit(ThreadPoolJob* job, start_routine func, void* arg) override {
77 return ::TPJobInit(job, func, arg);
78 }
79 int TPJobSetPriority(ThreadPoolJob* job, ThreadPriority priority) override {
80 return ::TPJobSetPriority(job, priority);
81 }
82 int TPJobSetFreeFunction(ThreadPoolJob* job, free_routine func) override {
83 return ::TPJobSetFreeFunction(job, func);
84 }
85 int TPAttrSetMaxThreads(ThreadPoolAttr* attr, int maxThreads) override {
86 return ::TPAttrSetMaxThreads(attr, maxThreads);
87 }
88 int TPAttrSetMinThreads(ThreadPoolAttr* attr, int minThreads) override {
89 return ::TPAttrSetMinThreads(attr, minThreads);
90 }
91 int TPAttrSetStackSize(ThreadPoolAttr* attr, size_t stackSize) override {
92 return ::TPAttrSetStackSize(attr, stackSize);
93 }
94 int TPAttrSetIdleTime(ThreadPoolAttr* attr, int idleTime) override {
95 return ::TPAttrSetIdleTime(attr, idleTime);
96 }
97 int TPAttrSetJobsPerThread(ThreadPoolAttr* attr, int jobsPerThread) override {
98 return ::TPAttrSetJobsPerThread(attr, jobsPerThread);
99 }
100 int TPAttrSetStarvationTime(ThreadPoolAttr* attr, int starvationTime) override {
101 return ::TPAttrSetStarvationTime(attr, starvationTime);
102 }
103 int TPAttrSetSchedPolicy(ThreadPoolAttr* attr, PolicyType schedPolicy) override {
104 return ::TPAttrSetSchedPolicy(attr, schedPolicy);
105 }
106 int TPAttrSetMaxJobsTotal(ThreadPoolAttr* attr, int totalMaxJobs) override {
107 return ::TPAttrSetMaxJobsTotal(attr, totalMaxJobs);
108 }
109 void ThreadPoolPrintStats(ThreadPoolStats* stats) override {
110 return ::ThreadPoolPrintStats(stats);
111 }
112 int ThreadPoolGetStats(ThreadPool* tp, ThreadPoolStats* stats) override {
113 return ::ThreadPoolGetStats(tp, stats);
114 }
115 int gettimeofday(struct timeval* tv, struct timezone* tz) override {
116 return ::gettimeofday(tv, tz);
117 }
118};
119// clang-format on
120
121#endif // INTERFACE_THREADPOOL_HPP
122
int ThreadPoolInit(ThreadPool *tp, ThreadPoolAttr *attr)
Initializes and starts ThreadPool.
int ThreadPoolAdd(ThreadPool *tp, ThreadPoolJob *job, int *jobId)
Adds a job to the thread pool.
int TPJobSetFreeFunction(ThreadPoolJob *job, free_routine func)
Sets the jobs free function.
int ThreadPoolShutdown(ThreadPool *tp)
Shuts the thread pool down.
int ThreadPoolGetAttr(ThreadPool *tp, ThreadPoolAttr *out)
Gets the current set of attributes associated with the thread pool.
void ThreadPoolPrintStats(ThreadPoolStats *stats)
Prints various statistics about the thread pool to stderr.
int TPAttrSetMaxJobsTotal(ThreadPoolAttr *attr, int totalMaxJobs)
Sets the maximum number jobs that can be qeued totally.
int TPAttrSetStarvationTime(ThreadPoolAttr *attr, int starvationTime)
Sets the starvation time for the thread pool attributes.
int TPAttrSetMaxThreads(ThreadPoolAttr *attr, int maxThreads)
Sets the max threads for the thread pool attributes.
int TPJobSetPriority(ThreadPoolJob *job, ThreadPriority priority)
Sets the priority of the threadpool job.
int ThreadPoolSetAttr(ThreadPool *tp, ThreadPoolAttr *attr)
Sets the attributes for the thread pool.
int ThreadPoolRemove(ThreadPool *tp, int jobId, ThreadPoolJob *out)
Removes a job from the thread pool.
int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats)
Returns various statistics about the thread pool.
int TPAttrSetJobsPerThread(ThreadPoolAttr *attr, int jobsPerThread)
Sets the jobs per thread ratio.
int gettimeofday(struct timeval *tv, struct timezone *tz)
Get time of day.
int TPJobInit(ThreadPoolJob *job, UPnPsdk::start_routine func, void *arg)
Initializes thread pool job.
int TPAttrInit(ThreadPoolAttr *attr)
Initializes thread pool attributes.
int TPAttrSetIdleTime(ThreadPoolAttr *attr, int idleTime)
Sets the idle time for the thread pool attributes.
int TPAttrSetMinThreads(ThreadPoolAttr *attr, int minThreads)
Sets the min threads for the thread pool attributes.
int TPAttrSetSchedPolicy(ThreadPoolAttr *attr, PolicyType schedPolicy)
Sets the scheduling policy for the thread pool attributes.
int maxJobsTotal
int TPAttrSetStackSize(ThreadPoolAttr *attr, size_t stackSize)
Sets the stack size for the thread pool attributes.
int ThreadPoolAddPersistent(ThreadPool *tp, ThreadPoolJob *job, int *jobId)
Adds a persistent job to the thread pool.
Manage a threadpool (for internal use only).
int PolicyType
Type of the thread policy.
ThreadPriority
Thread priority.
void(* free_routine)(void *arg)
A thread pool.
Internal ThreadPool Job.
Structure to hold statistics.
Attributes for thread pool.
Timezone.