1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/include/prtpool.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef prtpool_h___ 1.10 +#define prtpool_h___ 1.11 + 1.12 +#include "prtypes.h" 1.13 +#include "prthread.h" 1.14 +#include "prio.h" 1.15 +#include "prerror.h" 1.16 + 1.17 +/* 1.18 + * NOTE: 1.19 + * THIS API IS A PRELIMINARY VERSION IN NSPR 4.0 AND IS SUBJECT TO 1.20 + * CHANGE 1.21 + */ 1.22 + 1.23 +PR_BEGIN_EXTERN_C 1.24 + 1.25 +typedef struct PRJobIoDesc { 1.26 + PRFileDesc *socket; 1.27 + PRErrorCode error; 1.28 + PRIntervalTime timeout; 1.29 +} PRJobIoDesc; 1.30 + 1.31 +typedef struct PRThreadPool PRThreadPool; 1.32 +typedef struct PRJob PRJob; 1.33 +typedef void (PR_CALLBACK *PRJobFn) (void *arg); 1.34 + 1.35 +/* Create thread pool */ 1.36 +NSPR_API(PRThreadPool *) 1.37 +PR_CreateThreadPool(PRInt32 initial_threads, PRInt32 max_threads, 1.38 + PRUint32 stacksize); 1.39 + 1.40 +/* queue a job */ 1.41 +NSPR_API(PRJob *) 1.42 +PR_QueueJob(PRThreadPool *tpool, PRJobFn fn, void *arg, PRBool joinable); 1.43 + 1.44 +/* queue a job, when a socket is readable */ 1.45 +NSPR_API(PRJob *) 1.46 +PR_QueueJob_Read(PRThreadPool *tpool, PRJobIoDesc *iod, 1.47 + PRJobFn fn, void * arg, PRBool joinable); 1.48 + 1.49 +/* queue a job, when a socket is writeable */ 1.50 +NSPR_API(PRJob *) 1.51 +PR_QueueJob_Write(PRThreadPool *tpool, PRJobIoDesc *iod, 1.52 + PRJobFn fn, void * arg, PRBool joinable); 1.53 + 1.54 +/* queue a job, when a socket has a pending connection */ 1.55 +NSPR_API(PRJob *) 1.56 +PR_QueueJob_Accept(PRThreadPool *tpool, PRJobIoDesc *iod, 1.57 + PRJobFn fn, void * arg, PRBool joinable); 1.58 + 1.59 +/* queue a job, when the socket connection to addr succeeds or fails */ 1.60 +NSPR_API(PRJob *) 1.61 +PR_QueueJob_Connect(PRThreadPool *tpool, PRJobIoDesc *iod, 1.62 + const PRNetAddr *addr, PRJobFn fn, void * arg, PRBool joinable); 1.63 + 1.64 +/* queue a job, when a timer exipres */ 1.65 +NSPR_API(PRJob *) 1.66 +PR_QueueJob_Timer(PRThreadPool *tpool, PRIntervalTime timeout, 1.67 + PRJobFn fn, void * arg, PRBool joinable); 1.68 +/* cancel a job */ 1.69 +NSPR_API(PRStatus) 1.70 +PR_CancelJob(PRJob *job); 1.71 + 1.72 +/* join a job */ 1.73 +NSPR_API(PRStatus) 1.74 +PR_JoinJob(PRJob *job); 1.75 + 1.76 +/* shutdown pool */ 1.77 +NSPR_API(PRStatus) 1.78 +PR_ShutdownThreadPool(PRThreadPool *tpool); 1.79 + 1.80 +/* join pool, wait for exit of all threads */ 1.81 +NSPR_API(PRStatus) 1.82 +PR_JoinThreadPool(PRThreadPool *tpool); 1.83 + 1.84 +PR_END_EXTERN_C 1.85 + 1.86 +#endif /* prtpool_h___ */