prtpool.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #ifndef prtpool_h___
  6. #define prtpool_h___
  7. #include "prtypes.h"
  8. #include "prthread.h"
  9. #include "prio.h"
  10. #include "prerror.h"
  11. /*
  12. * NOTE:
  13. * THIS API IS A PRELIMINARY VERSION IN NSPR 4.0 AND IS SUBJECT TO
  14. * CHANGE
  15. */
  16. PR_BEGIN_EXTERN_C
  17. typedef struct PRJobIoDesc {
  18. PRFileDesc *socket;
  19. PRErrorCode error;
  20. PRIntervalTime timeout;
  21. } PRJobIoDesc;
  22. typedef struct PRThreadPool PRThreadPool;
  23. typedef struct PRJob PRJob;
  24. typedef void (PR_CALLBACK *PRJobFn) (void *arg);
  25. /* Create thread pool */
  26. NSPR_API(PRThreadPool *)
  27. PR_CreateThreadPool(PRInt32 initial_threads, PRInt32 max_threads,
  28. PRUint32 stacksize);
  29. /* queue a job */
  30. NSPR_API(PRJob *)
  31. PR_QueueJob(PRThreadPool *tpool, PRJobFn fn, void *arg, PRBool joinable);
  32. /* queue a job, when a socket is readable */
  33. NSPR_API(PRJob *)
  34. PR_QueueJob_Read(PRThreadPool *tpool, PRJobIoDesc *iod,
  35. PRJobFn fn, void * arg, PRBool joinable);
  36. /* queue a job, when a socket is writeable */
  37. NSPR_API(PRJob *)
  38. PR_QueueJob_Write(PRThreadPool *tpool, PRJobIoDesc *iod,
  39. PRJobFn fn, void * arg, PRBool joinable);
  40. /* queue a job, when a socket has a pending connection */
  41. NSPR_API(PRJob *)
  42. PR_QueueJob_Accept(PRThreadPool *tpool, PRJobIoDesc *iod,
  43. PRJobFn fn, void * arg, PRBool joinable);
  44. /* queue a job, when the socket connection to addr succeeds or fails */
  45. NSPR_API(PRJob *)
  46. PR_QueueJob_Connect(PRThreadPool *tpool, PRJobIoDesc *iod,
  47. const PRNetAddr *addr, PRJobFn fn, void * arg, PRBool joinable);
  48. /* queue a job, when a timer exipres */
  49. NSPR_API(PRJob *)
  50. PR_QueueJob_Timer(PRThreadPool *tpool, PRIntervalTime timeout,
  51. PRJobFn fn, void * arg, PRBool joinable);
  52. /* cancel a job */
  53. NSPR_API(PRStatus)
  54. PR_CancelJob(PRJob *job);
  55. /* join a job */
  56. NSPR_API(PRStatus)
  57. PR_JoinJob(PRJob *job);
  58. /* shutdown pool */
  59. NSPR_API(PRStatus)
  60. PR_ShutdownThreadPool(PRThreadPool *tpool);
  61. /* join pool, wait for exit of all threads */
  62. NSPR_API(PRStatus)
  63. PR_JoinThreadPool(PRThreadPool *tpool);
  64. PR_END_EXTERN_C
  65. #endif /* prtpool_h___ */