forked from artyom-beilis/cppcms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread_pool.h
More file actions
66 lines (51 loc) · 1.91 KB
/
Copy paththread_pool.h
File metadata and controls
66 lines (51 loc) · 1.91 KB
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
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <[email protected]>
//
// See accompanying file COPYING.TXT file for licensing details.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPCMS_THREAD_POOL_H
#define CPPCMS_THREAD_POOL_H
#include <cppcms/defs.h>
#include <booster/noncopyable.h>
#include <booster/function.h>
#include <booster/hold_ptr.h>
namespace cppcms {
namespace impl {
class thread_pool;
}
///
/// \brief This class provides an access to the thread pool where all CppCMS synchronous
/// applications are executed.
///
/// Users of asynchronous applications or tasks my send their jobs for the execution in the
/// thread_pool
///
class CPPCMS_API thread_pool : public booster::noncopyable {
public:
///
/// Post a request for execution of \a job in the pool. Received integer is special job identification
/// number that can be used to remove the job from the queue.
///
int post(booster::function<void()> const &job);
///
/// Cancel the job using id received from post() function
///
/// Returns true if the job was removed from the queue and false if the operation failed: the job execution is in the process
/// or completed
///
/// Note: the id is just a rolling number and job ids may be repeated once in a while, so it is good idea to check if the job
/// was completed before cancelling the job (even it is unlikely the 4 billion jobs would be executed in small period of time.
///
bool cancel(int id);
/// \cond INTERNAL
thread_pool(int threads);
void stop();
~thread_pool();
//// \endcond
private:
booster::hold_ptr<impl::thread_pool> impl_;
};
} // cppcms
#endif