home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / src / io / pprmwait.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.0 KB  |  78 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #if defined(_PPRMWAIT_H)
  20. #else
  21. #define _PPRMWAIT_H
  22.  
  23. #include "prlock.h"
  24. #include "prcvar.h"
  25. #include "prclist.h"
  26. #include "prthread.h"
  27.  
  28. #define _PR_HASH_OFFSET 75013
  29. #define MAX_POLLING_INTERVAL 100
  30. #define _PR_POLL_COUNT_FUDGE 64
  31. #define MAX_POLLING_INTERVAL 100
  32. #define _PR_DEFAULT_HASH_LENGTH 59
  33.  
  34. #define _MW_REHASH(a, i, m) _MW_HASH((PRUint32)(a) + (i) + _PR_HASH_OFFSET, m)
  35. #define _MW_HASH(a, m) ((((PRUint32)(a) >> 4) ^ ((PRUint32)(a) >> 10)) % (m))
  36. #define _MW_ABORTED(_rv) \
  37.     ((PR_FAILURE == (_rv)) && (PR_PENDING_INTERRUPT_ERROR == PR_GetError()))
  38.  
  39. typedef enum {_prmw_success, _prmw_rehash, _prmw_error} _PR_HashStory;
  40.  
  41. typedef struct _PRWaiterHash
  42. {
  43.     PRUint16 count;             /* current number in hash table */
  44.     PRUint16 length;            /* current size of the hash table */
  45.     PRRecvWait *recv_wait;      /* hash table of receive wait objects */
  46. } _PRWaiterHash;
  47.  
  48. typedef enum {_prmw_running, _prmw_stopping, _prmw_stopped} PRMWGroupState;
  49.  
  50. struct PRWaitGroup
  51. {
  52.     PRCList group_link;         /* all groups are linked to each other */
  53.     PRCList io_ready;           /* list of I/O requests that are ready */
  54.     PRMWGroupState state;       /* state of this group (so we can shut down) */
  55.  
  56.     PRLock *ml;                 /* lock for synchronizing this wait group */
  57.     PRCondVar *io_taken;        /* calling threads notify when they take I/O */
  58.     PRCondVar *io_complete;     /* calling threads wait here for completions */
  59.     PRCondVar *new_business;    /* polling thread waits here more work */
  60.     PRCondVar *mw_manage;       /* used to manage group lists */
  61.     PRThread* poller;           /* thread that's actually doing the poll() */
  62.     PRUint16 waiting_threads;   /* number of threads waiting for recv */
  63.     PRUint16 polling_count;     /* number of elements in the polling list */
  64.     PRPollDesc *polling_list;   /* list poller builds for polling */
  65.     PRIntervalTime last_poll;   /* last time we polled */
  66.     _PRWaiterHash *waiter;      /* pointer to hash table of wait receive objects */
  67. };
  68.  
  69. typedef struct _PRGlobalState
  70. {
  71.     PRCList group_list;         /* master of the group list */
  72.     PRWaitGroup *group;         /* the default (NULL) group */
  73. } _PRGlobalState;
  74.  
  75. #endif /* defined(_PPRMWAIT_H) */
  76.  
  77. /* pprmwait.h */
  78.