VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/include/private/pprmwait.h@ 11551

Last change on this file since 11551 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#if defined(_PPRMWAIT_H)
39#else
40#define _PPRMWAIT_H
41
42#include "prlock.h"
43#include "prcvar.h"
44#include "prclist.h"
45#include "prthread.h"
46
47#define MAX_POLLING_INTERVAL 100
48#define _PR_POLL_COUNT_FUDGE 64
49#define MAX_POLLING_INTERVAL 100
50#define _PR_DEFAULT_HASH_LENGTH 59
51
52/*
53 * Our hash table resolves collisions by open addressing with
54 * double hashing. See Cormen, Leiserson, and Rivest,
55 * Introduction to Algorithms, p. 232, The MIT Press, 1990.
56 */
57
58#define _MW_HASH(a, m) ((((PRUptrdiff)(a) >> 4) ^ ((PRUptrdiff)(a) >> 10)) % (m))
59#define _MW_HASH2(a, m) (1 + ((((PRUptrdiff)(a) >> 4) ^ ((PRUptrdiff)(a) >> 10)) % (m - 2)))
60#define _MW_ABORTED(_rv) \
61 ((PR_FAILURE == (_rv)) && (PR_PENDING_INTERRUPT_ERROR == PR_GetError()))
62
63typedef enum {_prmw_success, _prmw_rehash, _prmw_error} _PR_HashStory;
64
65typedef struct _PRWaiterHash
66{
67 PRUint16 count; /* current number in hash table */
68 PRUint16 length; /* current size of the hash table */
69 PRRecvWait *recv_wait; /* hash table of receive wait objects */
70} _PRWaiterHash;
71
72typedef enum {_prmw_running, _prmw_stopping, _prmw_stopped} PRMWGroupState;
73
74struct PRWaitGroup
75{
76 PRCList group_link; /* all groups are linked to each other */
77 PRCList io_ready; /* list of I/O requests that are ready */
78 PRMWGroupState state; /* state of this group (so we can shut down) */
79
80 PRLock *ml; /* lock for synchronizing this wait group */
81 PRCondVar *io_taken; /* calling threads notify when they take I/O */
82 PRCondVar *io_complete; /* calling threads wait here for completions */
83 PRCondVar *new_business; /* polling thread waits here more work */
84 PRCondVar *mw_manage; /* used to manage group lists */
85 PRThread* poller; /* thread that's actually doing the poll() */
86 PRUint16 waiting_threads; /* number of threads waiting for recv */
87 PRUint16 polling_count; /* number of elements in the polling list */
88 PRUint32 p_timestamp; /* pseudo-time group had element removed */
89 PRPollDesc *polling_list; /* list poller builds for polling */
90 PRIntervalTime last_poll; /* last time we polled */
91 _PRWaiterHash *waiter; /* pointer to hash table of wait receive objects */
92
93#ifdef WINNT
94 /*
95 * On NT, idle threads are responsible for getting completed i/o.
96 * They need to add completed i/o to the io_ready list. Since
97 * idle threads cannot use nspr locks, we have to use an md lock
98 * to protect the io_ready list.
99 */
100 _MDLock mdlock; /* protect io_ready, waiter, and wait_list */
101 PRCList wait_list; /* used in place of io_complete. reuse
102 * waitQLinks in the PRThread structure. */
103#endif /* WINNT */
104};
105
106/**********************************************************************
107***********************************************************************
108******************** Wait group enumerations **************************
109***********************************************************************
110**********************************************************************/
111typedef struct _PRGlobalState
112{
113 PRCList group_list; /* master of the group list */
114 PRWaitGroup *group; /* the default (NULL) group */
115} _PRGlobalState;
116
117#ifdef WINNT
118extern PRStatus NT_HashRemoveInternal(PRWaitGroup *group, PRFileDesc *fd);
119#endif
120
121typedef enum {_PR_ENUM_UNSEALED=0, _PR_ENUM_SEALED=0x0eadface} _PREnumSeal;
122
123struct PRMWaitEnumerator
124{
125 PRWaitGroup *group; /* group this enumerator is bound to */
126 PRThread *thread; /* thread in midst of an enumeration */
127 _PREnumSeal seal; /* trying to detect deleted objects */
128 PRUint32 p_timestamp; /* when enumeration was (re)started */
129 PRRecvWait **waiter; /* pointer into hash table */
130 PRUintn index; /* position in hash table */
131 void *pad[4]; /* some room to grow */
132};
133
134#endif /* defined(_PPRMWAIT_H) */
135
136/* pprmwait.h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette