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
20PR_BEGIN_EXTERN_C
21
22typedef struct PRJobIoDesc {
23 PRFileDesc *socket;
24 PRErrorCode error;
25 PRIntervalTime timeout;
26} PRJobIoDesc;
27
28typedef struct PRThreadPool PRThreadPool;
29typedef struct PRJob PRJob;
30typedef void (PR_CALLBACK *PRJobFn) (void *arg);
31
32/* Create thread pool */
33NSPR_API(PRThreadPool *)
34PR_CreateThreadPool(PRInt32 initial_threads, PRInt32 max_threads,
35 PRUint32 stacksize);
36
37/* queue a job */
38NSPR_API(PRJob *)
39PR_QueueJob(PRThreadPool *tpool, PRJobFn fn, void *arg, PRBool joinable);
40
41/* queue a job, when a socket is readable */
42NSPR_API(PRJob *)
43PR_QueueJob_Read(PRThreadPool *tpool, PRJobIoDesc *iod,
44 PRJobFn fn, void * arg, PRBool joinable);
45
46/* queue a job, when a socket is writeable */
47NSPR_API(PRJob *)
48PR_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 */
52NSPR_API(PRJob *)
53PR_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 */
57NSPR_API(PRJob *)
58PR_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 */
62NSPR_API(PRJob *)
63PR_QueueJob_Timer(PRThreadPool *tpool, PRIntervalTime timeout,
64 PRJobFn fn, void * arg, PRBool joinable);
65/* cancel a job */
66NSPR_API(PRStatus)
67PR_CancelJob(PRJob *job);
68
69/* join a job */
70NSPR_API(PRStatus)
71PR_JoinJob(PRJob *job);
72
73/* shutdown pool */
74NSPR_API(PRStatus)
75PR_ShutdownThreadPool(PRThreadPool *tpool);
76
77/* join pool, wait for exit of all threads */
78NSPR_API(PRStatus)
79PR_JoinThreadPool(PRThreadPool *tpool);
80
81PR_END_EXTERN_C
82
83#endif /* prtpool_h___ */
84

source code of include/nspr/prtpool.h