VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/include/prmwait.h@ 26515

Last change on this file since 26515 was 11551, checked in by vboxsync, 16 years ago

API/xpcom: prefix any C symbols in VBoxXPCOM.so, to avoid namespace pollution. Enabled only on Linux at the moment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.0 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(_PRMWAIT_H)
39#else
40#define _PRMWAIT_H
41
42#include "prio.h"
43#include "prtypes.h"
44#include "prclist.h"
45
46#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
47#define PR_AddWaitFileDesc VBoxNsprPR_AddWaitFileDesc
48#define PR_CancelWaitFileDesc VBoxNsprPR_CancelWaitFileDesc
49#define PR_CancelWaitGroup VBoxNsprPR_CancelWaitGroup
50#define PR_CreateWaitGroup VBoxNsprPR_CreateWaitGroup
51#define PR_CreateMWaitEnumerator VBoxNsprPR_CreateMWaitEnumerator
52#define PR_DestroyWaitGroup VBoxNsprPR_DestroyWaitGroup
53#define PR_DestroyMWaitEnumerator VBoxNsprPR_DestroyMWaitEnumerator
54#define PR_EnumerateWaitGroup VBoxNsprPR_EnumerateWaitGroup
55#define PR_WaitRecvReady VBoxNsprPR_WaitRecvReady
56#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
57
58PR_BEGIN_EXTERN_C
59
60/********************************************************************************/
61/********************************************************************************/
62/********************************************************************************/
63/****************************** WARNING ****************************/
64/********************************************************************************/
65/**************************** This is work in progress. *************************/
66/************************** Do not make any assumptions *************************/
67/************************** about the stability of this *************************/
68/************************** API or the underlying imple- ************************/
69/************************** mentation. ************************/
70/********************************************************************************/
71/********************************************************************************/
72
73/*
74** STRUCTURE: PRWaitGroup
75** DESCRIPTION:
76** The client may define several wait groups in order to semantically
77** tie a collection of file descriptors for a single purpose. This allows
78** easier dispatching of threads that returned with active file descriptors
79** from the wait function.
80*/
81typedef struct PRWaitGroup PRWaitGroup;
82
83/*
84** ENUMERATION: PRMWStatus
85** DESCRIPTION:
86** This enumeration is used to indicate the completion status of
87** a receive wait object. Generally stated, a positive value indicates
88** that the operation is not yet complete. A zero value indicates
89** success (similar to PR_SUCCESS) and any negative value is an
90** indication of failure. The reason for the failure can be retrieved
91** by calling PR_GetError().
92**
93** PR_MW_PENDING The operation is still pending. None of the other
94** fields of the object are currently valid.
95** PR_MW_SUCCESS The operation is complete and it was successful.
96** PR_MW_FAILURE The operation failed. The reason for the failure
97** can be retrieved by calling PR_GetError().
98** PR_MW_TIMEOUT The amount of time allowed for by the object's
99** 'timeout' field has expired w/o the operation
100** otherwise coming to closure.
101** PR_MW_INTERRUPT The operation was cancelled, either by the client
102** calling PR_CancelWaitFileDesc() or destroying the
103** entire wait group (PR_DestroyWaitGroup()).
104*/
105typedef enum PRMWStatus
106{
107 PR_MW_PENDING = 1,
108 PR_MW_SUCCESS = 0,
109 PR_MW_FAILURE = -1,
110 PR_MW_TIMEOUT = -2,
111 PR_MW_INTERRUPT = -3
112} PRMWStatus;
113
114/*
115** STRUCTURE: PRMemoryDescriptor
116** DESCRIPTION:
117** THis is a descriptor for an interval of memory. It contains a
118** pointer to the first byte of that memory and the length (in
119** bytes) of the interval.
120*/
121typedef struct PRMemoryDescriptor
122{
123 void *start; /* pointer to first byte of memory */
124 PRSize length; /* length (in bytes) of memory interval */
125} PRMemoryDescriptor;
126
127/*
128** STRUCTURE: PRMWaitClientData
129** DESCRIPTION:
130** An opague stucture for which a client MAY give provide a concrete
131** definition and associate with a receive descriptor. The NSPR runtime
132** does not manage this field. It is completely up to the client.
133*/
134typedef struct PRMWaitClientData PRMWaitClientData;
135
136/*
137** STRUCTURE: PRRecvWait
138** DESCRIPTION:
139** A receive wait object contains the file descriptor that is subject
140** to the wait and the amount of time (beginning epoch established
141** when the object is presented to the runtime) the the channel should
142** block before abandoning the process.
143**
144** The success of the wait operation will be noted in the object's
145** 'outcome' field. The fields are not valid when the NSPR runtime
146** is in possession of the object.
147**
148** The memory descriptor describes an interval of writable memory
149** in the caller's address space where data from an initial read
150** can be placed. The description may indicate a null interval.
151*/
152typedef struct PRRecvWait
153{
154 PRCList internal; /* internal runtime linkages */
155
156 PRFileDesc *fd; /* file descriptor associated w/ object */
157 PRMWStatus outcome; /* outcome of the current/last operation */
158 PRIntervalTime timeout; /* time allowed for entire operation */
159
160 PRInt32 bytesRecv; /* number of bytes transferred into buffer */
161 PRMemoryDescriptor buffer; /* where to store first segment of input data */
162 PRMWaitClientData *client; /* pointer to arbitrary client defined data */
163} PRRecvWait;
164
165/*
166** STRUCTURE: PRMWaitEnumerator
167** DESCRIPTION:
168** An enumeration object is used to store the state of an existing
169** enumeration over a wait group. The opaque object must be allocated
170** by the client and the reference presented on each call to the
171** pseudo-stateless enumerator. The enumeration objects are sharable
172** only in serial fashion.
173*/
174typedef struct PRMWaitEnumerator PRMWaitEnumerator;
175
176
177/*
178** FUNCTION: PR_AddWaitFileDesc
179** DESCRIPTION:
180** This function will effectively add a file descriptor to the
181** list of those waiting for network receive. The new descriptor
182** will be semantically tied to the wait group specified.
183**
184** The ownership for the storage pointed to by 'desc' is temporarily
185** passed over the the NSPR runtime. It will be handed back by the
186** function PR_WaitRecvReady().
187**
188** INPUTS
189** group A reference to a PRWaitGroup or NULL. Wait groups are
190** created by calling PR_CreateWaitGroup() and are used
191** to semantically group various file descriptors by the
192** client's application.
193** desc A reference to a valid PRRecvWait. The object of the
194** reference must be preserved and not be modified
195** until its ownership is returned to the client.
196** RETURN
197** PRStatus An indication of success. If equal to PR_FAILUE details
198** of the failure are avaiable via PR_GetError().
199**
200** ERRORS
201** PR_INVALID_ARGUMENT_ERROR
202** Invalid 'group' identifier or duplicate 'desc' object.
203** PR_OUT_OF_MEMORY_ERROR
204** Insuffient memory for internal data structures.
205** PR_INVALID_STATE_ERROR
206** The group is being destroyed.
207*/
208NSPR_API(PRStatus) PR_AddWaitFileDesc(PRWaitGroup *group, PRRecvWait *desc);
209
210/*
211** FUNCTION: PR_WaitRecvReady
212** DESCRIPTION:
213** PR_WaitRecvReady will block the calling thread until one of the
214** file descriptors that have been added via PR_AddWaitFileDesc is
215** available for input I/O.
216** INPUT
217** group A pointer to a valid PRWaitGroup or NULL (the null
218** group. The function will block the caller until a
219** channel from the wait group becomes ready for receive
220** or there is some sort of error.
221** RETURN
222** PRReciveWait
223** When the caller is resumed it is either returned a
224** valid pointer to a previously added receive wait or
225** a NULL. If the latter, the function has terminated
226** for a reason that can be determined by calling
227** PR_GetError().
228** If a valid pointer is returned, the reference is to the
229** file descriptor contained in the receive wait object.
230** The outcome of the wait operation may still fail, and
231** if it has, that fact will be noted in the object's
232** outcome field. Details can be retrieved from PR_GetError().
233**
234** ERRORS
235** PR_INVALID_ARGUMENT_ERROR
236** The 'group' is not known by the runtime.
237** PR_PENDING_INTERRUPT_ERROR
238 The thread was interrupted.
239** PR_INVALID_STATE_ERROR
240** The group is being destroyed.
241*/
242NSPR_API(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group);
243
244/*
245** FUNCTION: PR_CancelWaitFileDesc
246** DESCRIPTION:
247** PR_CancelWaitFileDesc is provided as a means for cancelling operations
248** on objects previously submitted by use of PR_AddWaitFileDesc(). If
249** the runtime knows of the object, it will be marked as having failed
250** because it was interrupted (similar to PR_Interrupt()). The first
251** available thread waiting on the group will be made to return the
252** PRRecvWait object with the outcome noted.
253**
254** INPUTS
255** group The wait group under which the wait receive object was
256** added.
257** desc A pointer to the wait receive object that is to be
258** cancelled.
259** RETURN
260** PRStatus If the wait receive object was located and associated
261** with the specified wait group, the status returned will
262** be PR_SUCCESS. There is still a race condition that would
263** permit the offected object to complete normally, but it
264** is assured that it will complete in the near future.
265** If the receive object or wait group are invalid, the
266** function will return with a status of PR_FAILURE.
267**
268** ERRORS
269** PR_INVALID_ARGUMENT_ERROR
270** The 'group' argument is not recognized as a valid group.
271** PR_COLLECTION_EMPTY_ERROR
272** There are no more receive wait objects in the group's
273** collection.
274** PR_INVALID_STATE_ERROR
275** The group is being destroyed.
276*/
277NSPR_API(PRStatus) PR_CancelWaitFileDesc(PRWaitGroup *group, PRRecvWait *desc);
278
279/*
280** FUNCTION: PR_CancelWaitGroup
281** DESCRIPTION:
282** PR_CancelWaitGroup is provided as a means for cancelling operations
283** on objects previously submitted by use of PR_AddWaitFileDesc(). Each
284** successive call will return a pointer to a PRRecvWait object that
285** was previously registered via PR_AddWaitFileDesc(). If no wait
286** objects are associated with the wait group, a NULL will be returned.
287** This function should be called in a loop until a NULL is returned
288** to reclaim all the wait objects prior to calling PR_DestroyWaitGroup().
289**
290** INPUTS
291** group The wait group under which the wait receive object was
292** added.
293** RETURN
294** PRRecvWait* If the wait group is valid and at least one receive wait
295** object is present in the group, that object will be
296** marked as PR_MW_INTERRUPT'd and removed from the group's
297** queues. Otherwise a NULL will be returned and the reason
298** for the NULL may be retrieved by calling PR_GetError().
299**
300** ERRORS
301** PR_INVALID_ARGUMENT_ERROR
302** PR_GROUP_EMPTY_ERROR
303*/
304NSPR_API(PRRecvWait*) PR_CancelWaitGroup(PRWaitGroup *group);
305
306/*
307** FUNCTION: PR_CreateWaitGroup
308** DESCRIPTION:
309** A wait group is an opaque object that a client may create in order
310** to semantically group various wait requests. Each wait group is
311** unique, including the default wait group (NULL). A wait request
312** that was added under a wait group will only be serviced by a caller
313** that specified the same wait group.
314**
315** INPUT
316** size The size of the hash table to be used to contain the
317** receive wait objects. This is just the initial size.
318** It will grow as it needs to, but to avoid that hassle
319** one can suggest a suitable size initially. It should
320** be ~30% larger than the maximum number of receive wait
321** objects expected.
322** RETURN
323** PRWaitGroup If successful, the function will return a pointer to an
324** object that was allocated by and owned by the runtime.
325** The reference remains valid until it is explicitly destroyed
326** by calling PR_DestroyWaitGroup().
327**
328** ERRORS
329** PR_OUT_OF_MEMORY_ERROR
330*/
331NSPR_API(PRWaitGroup*) PR_CreateWaitGroup(PRInt32 size);
332
333/*
334** FUNCTION: PR_DestroyWaitGroup
335** DESCRIPTION:
336** Undo the effects of PR_CreateWaitGroup(). Any receive wait operations
337** on the group will be treated as if the each had been the target of a
338** PR_CancelWaitFileDesc().
339**
340** INPUT
341** group Reference to a wait group previously allocated using
342** PR_CreateWaitGroup().
343** RETURN
344** PRStatus Will be PR_SUCCESS if the wait group was valid and there
345** are no receive wait objects in that group. Otherwise
346** will indicate PR_FAILURE.
347**
348** ERRORS
349** PR_INVALID_ARGUMENT_ERROR
350** The 'group' argument does not reference a known object.
351** PR_INVALID_STATE_ERROR
352** The group still contains receive wait objects.
353*/
354NSPR_API(PRStatus) PR_DestroyWaitGroup(PRWaitGroup *group);
355
356/*
357** FUNCTION: PR_CreateMWaitEnumerator
358** DESCRIPTION:
359** The PR_CreateMWaitEnumerator() function returns a reference to an
360** opaque PRMWaitEnumerator object. The enumerator object is required
361** as an argument for each successive call in the stateless enumeration
362** of the indicated wait group.
363**
364** group The wait group that the enumeration is intended to
365** process. It may be be the default wait group (NULL).
366** RETURN
367** PRMWaitEnumerator* group
368** A reference to an object that will be used to store
369** intermediate state of enumerations.
370** ERRORS
371** Errors are indicated by the function returning a NULL.
372** PR_INVALID_ARGUMENT_ERROR
373** The 'group' argument does not reference a known object.
374** PR_OUT_OF_MEMORY_ERROR
375*/
376NSPR_API(PRMWaitEnumerator*) PR_CreateMWaitEnumerator(PRWaitGroup *group);
377
378/*
379** FUNCTION: PR_DestroyMWaitEnumerator
380** DESCRIPTION:
381** Destroys the object created by PR_CreateMWaitEnumerator(). The reference
382** used as an argument becomes invalid.
383**
384** INPUT
385** PRMWaitEnumerator* enumerator
386** The PRMWaitEnumerator object to destroy.
387** RETURN
388** PRStatus
389** PR_SUCCESS if successful, PR_FAILURE otherwise.
390** ERRORS
391** PR_INVALID_ARGUMENT_ERROR
392** The enumerator is invalid.
393*/
394NSPR_API(PRStatus) PR_DestroyMWaitEnumerator(PRMWaitEnumerator* enumerator);
395
396/*
397** FUNCTION: PR_EnumerateWaitGroup
398** DESCRIPTION:
399** PR_EnumerateWaitGroup is a thread safe enumerator over a wait group.
400** Each call to the enumerator must present a valid PRMWaitEnumerator
401** rererence and a pointer to the "previous" element returned from the
402** enumeration process or a NULL.
403**
404** An enumeration is started by passing a NULL as the "previous" value.
405** Subsequent calls to the enumerator must pass in the result of the
406** previous call. The enumeration end is signaled by the runtime returning
407** a NULL as the result.
408**
409** Modifications to the content of the wait group are allowed during
410** an enumeration. The effect is that the enumeration may have to be
411** "reset" and that may result in duplicates being returned from the
412** enumeration.
413**
414** An enumeration may be abandoned at any time. The runtime is not
415** keeping any state, so there are no issues in that regard.
416*/
417NSPR_API(PRRecvWait*) PR_EnumerateWaitGroup(
418 PRMWaitEnumerator *enumerator, const PRRecvWait *previous);
419
420PR_END_EXTERN_C
421
422#endif /* defined(_PRMWAIT_H) */
423
424/* prmwait.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