1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/include/private/pprmwait.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 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 +#if defined(_PPRMWAIT_H) 1.10 +#else 1.11 +#define _PPRMWAIT_H 1.12 + 1.13 +#include "prlock.h" 1.14 +#include "prcvar.h" 1.15 +#include "prclist.h" 1.16 +#include "prthread.h" 1.17 + 1.18 +#define MAX_POLLING_INTERVAL 100 1.19 +#define _PR_POLL_COUNT_FUDGE 64 1.20 +#define _PR_DEFAULT_HASH_LENGTH 59 1.21 + 1.22 +/* 1.23 + * Our hash table resolves collisions by open addressing with 1.24 + * double hashing. See Cormen, Leiserson, and Rivest, 1.25 + * Introduction to Algorithms, p. 232, The MIT Press, 1990. 1.26 + */ 1.27 + 1.28 +#define _MW_HASH(a, m) ((((PRUptrdiff)(a) >> 4) ^ ((PRUptrdiff)(a) >> 10)) % (m)) 1.29 +#define _MW_HASH2(a, m) (1 + ((((PRUptrdiff)(a) >> 4) ^ ((PRUptrdiff)(a) >> 10)) % (m - 2))) 1.30 +#define _MW_ABORTED(_rv) \ 1.31 + ((PR_FAILURE == (_rv)) && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) 1.32 + 1.33 +typedef enum {_prmw_success, _prmw_rehash, _prmw_error} _PR_HashStory; 1.34 + 1.35 +typedef struct _PRWaiterHash 1.36 +{ 1.37 + PRUint16 count; /* current number in hash table */ 1.38 + PRUint16 length; /* current size of the hash table */ 1.39 + PRRecvWait *recv_wait; /* hash table of receive wait objects */ 1.40 +} _PRWaiterHash; 1.41 + 1.42 +typedef enum {_prmw_running, _prmw_stopping, _prmw_stopped} PRMWGroupState; 1.43 + 1.44 +struct PRWaitGroup 1.45 +{ 1.46 + PRCList group_link; /* all groups are linked to each other */ 1.47 + PRCList io_ready; /* list of I/O requests that are ready */ 1.48 + PRMWGroupState state; /* state of this group (so we can shut down) */ 1.49 + 1.50 + PRLock *ml; /* lock for synchronizing this wait group */ 1.51 + PRCondVar *io_taken; /* calling threads notify when they take I/O */ 1.52 + PRCondVar *io_complete; /* calling threads wait here for completions */ 1.53 + PRCondVar *new_business; /* polling thread waits here more work */ 1.54 + PRCondVar *mw_manage; /* used to manage group lists */ 1.55 + PRThread* poller; /* thread that's actually doing the poll() */ 1.56 + PRUint16 waiting_threads; /* number of threads waiting for recv */ 1.57 + PRUint16 polling_count; /* number of elements in the polling list */ 1.58 + PRUint32 p_timestamp; /* pseudo-time group had element removed */ 1.59 + PRPollDesc *polling_list; /* list poller builds for polling */ 1.60 + PRIntervalTime last_poll; /* last time we polled */ 1.61 + _PRWaiterHash *waiter; /* pointer to hash table of wait receive objects */ 1.62 + 1.63 +#ifdef WINNT 1.64 + /* 1.65 + * On NT, idle threads are responsible for getting completed i/o. 1.66 + * They need to add completed i/o to the io_ready list. Since 1.67 + * idle threads cannot use nspr locks, we have to use an md lock 1.68 + * to protect the io_ready list. 1.69 + */ 1.70 + _MDLock mdlock; /* protect io_ready, waiter, and wait_list */ 1.71 + PRCList wait_list; /* used in place of io_complete. reuse 1.72 + * waitQLinks in the PRThread structure. */ 1.73 +#endif /* WINNT */ 1.74 +}; 1.75 + 1.76 +/********************************************************************** 1.77 +*********************************************************************** 1.78 +******************** Wait group enumerations ************************** 1.79 +*********************************************************************** 1.80 +**********************************************************************/ 1.81 +typedef struct _PRGlobalState 1.82 +{ 1.83 + PRCList group_list; /* master of the group list */ 1.84 + PRWaitGroup *group; /* the default (NULL) group */ 1.85 +} _PRGlobalState; 1.86 + 1.87 +#ifdef WINNT 1.88 +extern PRStatus NT_HashRemoveInternal(PRWaitGroup *group, PRFileDesc *fd); 1.89 +#endif 1.90 + 1.91 +typedef enum {_PR_ENUM_UNSEALED=0, _PR_ENUM_SEALED=0x0eadface} _PREnumSeal; 1.92 + 1.93 +struct PRMWaitEnumerator 1.94 +{ 1.95 + PRWaitGroup *group; /* group this enumerator is bound to */ 1.96 + PRThread *thread; /* thread in midst of an enumeration */ 1.97 + _PREnumSeal seal; /* trying to detect deleted objects */ 1.98 + PRUint32 p_timestamp; /* when enumeration was (re)started */ 1.99 + PRRecvWait **waiter; /* pointer into hash table */ 1.100 + PRUintn index; /* position in hash table */ 1.101 + void *pad[4]; /* some room to grow */ 1.102 +}; 1.103 + 1.104 +#endif /* defined(_PPRMWAIT_H) */ 1.105 + 1.106 +/* pprmwait.h */