michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef prtpool_h___ michael@0: #define prtpool_h___ michael@0: michael@0: #include "prtypes.h" michael@0: #include "prthread.h" michael@0: #include "prio.h" michael@0: #include "prerror.h" michael@0: michael@0: /* michael@0: * NOTE: michael@0: * THIS API IS A PRELIMINARY VERSION IN NSPR 4.0 AND IS SUBJECT TO michael@0: * CHANGE michael@0: */ michael@0: michael@0: PR_BEGIN_EXTERN_C michael@0: michael@0: typedef struct PRJobIoDesc { michael@0: PRFileDesc *socket; michael@0: PRErrorCode error; michael@0: PRIntervalTime timeout; michael@0: } PRJobIoDesc; michael@0: michael@0: typedef struct PRThreadPool PRThreadPool; michael@0: typedef struct PRJob PRJob; michael@0: typedef void (PR_CALLBACK *PRJobFn) (void *arg); michael@0: michael@0: /* Create thread pool */ michael@0: NSPR_API(PRThreadPool *) michael@0: PR_CreateThreadPool(PRInt32 initial_threads, PRInt32 max_threads, michael@0: PRUint32 stacksize); michael@0: michael@0: /* queue a job */ michael@0: NSPR_API(PRJob *) michael@0: PR_QueueJob(PRThreadPool *tpool, PRJobFn fn, void *arg, PRBool joinable); michael@0: michael@0: /* queue a job, when a socket is readable */ michael@0: NSPR_API(PRJob *) michael@0: PR_QueueJob_Read(PRThreadPool *tpool, PRJobIoDesc *iod, michael@0: PRJobFn fn, void * arg, PRBool joinable); michael@0: michael@0: /* queue a job, when a socket is writeable */ michael@0: NSPR_API(PRJob *) michael@0: PR_QueueJob_Write(PRThreadPool *tpool, PRJobIoDesc *iod, michael@0: PRJobFn fn, void * arg, PRBool joinable); michael@0: michael@0: /* queue a job, when a socket has a pending connection */ michael@0: NSPR_API(PRJob *) michael@0: PR_QueueJob_Accept(PRThreadPool *tpool, PRJobIoDesc *iod, michael@0: PRJobFn fn, void * arg, PRBool joinable); michael@0: michael@0: /* queue a job, when the socket connection to addr succeeds or fails */ michael@0: NSPR_API(PRJob *) michael@0: PR_QueueJob_Connect(PRThreadPool *tpool, PRJobIoDesc *iod, michael@0: const PRNetAddr *addr, PRJobFn fn, void * arg, PRBool joinable); michael@0: michael@0: /* queue a job, when a timer exipres */ michael@0: NSPR_API(PRJob *) michael@0: PR_QueueJob_Timer(PRThreadPool *tpool, PRIntervalTime timeout, michael@0: PRJobFn fn, void * arg, PRBool joinable); michael@0: /* cancel a job */ michael@0: NSPR_API(PRStatus) michael@0: PR_CancelJob(PRJob *job); michael@0: michael@0: /* join a job */ michael@0: NSPR_API(PRStatus) michael@0: PR_JoinJob(PRJob *job); michael@0: michael@0: /* shutdown pool */ michael@0: NSPR_API(PRStatus) michael@0: PR_ShutdownThreadPool(PRThreadPool *tpool); michael@0: michael@0: /* join pool, wait for exit of all threads */ michael@0: NSPR_API(PRStatus) michael@0: PR_JoinThreadPool(PRThreadPool *tpool); michael@0: michael@0: PR_END_EXTERN_C michael@0: michael@0: #endif /* prtpool_h___ */