1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | |
6 | #ifndef prtpool_h___ |
7 | #define prtpool_h___ |
8 | |
9 | #include "prtypes.h" |
10 | #include "prthread.h" |
11 | #include "prio.h" |
12 | #include "prerror.h" |
13 | |
14 | /* |
15 | * NOTE: |
16 | * THIS API IS A PRELIMINARY VERSION IN NSPR 4.0 AND IS SUBJECT TO |
17 | * CHANGE |
18 | */ |
19 | |
20 | PR_BEGIN_EXTERN_C |
21 | |
22 | typedef struct PRJobIoDesc { |
23 | PRFileDesc *socket; |
24 | PRErrorCode error; |
25 | PRIntervalTime timeout; |
26 | } PRJobIoDesc; |
27 | |
28 | typedef struct PRThreadPool PRThreadPool; |
29 | typedef struct PRJob PRJob; |
30 | typedef void (PR_CALLBACK *PRJobFn) (void *arg); |
31 | |
32 | /* Create thread pool */ |
33 | NSPR_API(PRThreadPool *) |
34 | PR_CreateThreadPool(PRInt32 initial_threads, PRInt32 max_threads, |
35 | PRUint32 stacksize); |
36 | |
37 | /* queue a job */ |
38 | NSPR_API(PRJob *) |
39 | PR_QueueJob(PRThreadPool *tpool, PRJobFn fn, void *arg, PRBool joinable); |
40 | |
41 | /* queue a job, when a socket is readable */ |
42 | NSPR_API(PRJob *) |
43 | PR_QueueJob_Read(PRThreadPool *tpool, PRJobIoDesc *iod, |
44 | PRJobFn fn, void * arg, PRBool joinable); |
45 | |
46 | /* queue a job, when a socket is writeable */ |
47 | NSPR_API(PRJob *) |
48 | PR_QueueJob_Write(PRThreadPool *tpool, PRJobIoDesc *iod, |
49 | PRJobFn fn, void * arg, PRBool joinable); |
50 | |
51 | /* queue a job, when a socket has a pending connection */ |
52 | NSPR_API(PRJob *) |
53 | PR_QueueJob_Accept(PRThreadPool *tpool, PRJobIoDesc *iod, |
54 | PRJobFn fn, void * arg, PRBool joinable); |
55 | |
56 | /* queue a job, when the socket connection to addr succeeds or fails */ |
57 | NSPR_API(PRJob *) |
58 | PR_QueueJob_Connect(PRThreadPool *tpool, PRJobIoDesc *iod, |
59 | const PRNetAddr *addr, PRJobFn fn, void * arg, PRBool joinable); |
60 | |
61 | /* queue a job, when a timer exipres */ |
62 | NSPR_API(PRJob *) |
63 | PR_QueueJob_Timer(PRThreadPool *tpool, PRIntervalTime timeout, |
64 | PRJobFn fn, void * arg, PRBool joinable); |
65 | /* cancel a job */ |
66 | NSPR_API(PRStatus) |
67 | PR_CancelJob(PRJob *job); |
68 | |
69 | /* join a job */ |
70 | NSPR_API(PRStatus) |
71 | PR_JoinJob(PRJob *job); |
72 | |
73 | /* shutdown pool */ |
74 | NSPR_API(PRStatus) |
75 | PR_ShutdownThreadPool(PRThreadPool *tpool); |
76 | |
77 | /* join pool, wait for exit of all threads */ |
78 | NSPR_API(PRStatus) |
79 | PR_JoinThreadPool(PRThreadPool *tpool); |
80 | |
81 | PR_END_EXTERN_C |
82 | |
83 | #endif /* prtpool_h___ */ |
84 | |