1
/*********************************************************
2
* Copyright (C) 1998 VMware, Inc. All rights reserved.
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License as published
6
* by the Free Software Foundation version 2.1 and no later version.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
11
* License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program; if not, write to the Free Software Foundation, Inc.,
15
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17
*********************************************************/
22
* Implements a platform independent wait queue
25
#ifndef _SYNC_WAITQ_H_
26
#define _SYNC_WAITQ_H_
28
#define INCLUDE_ALLOW_USERLEVEL
29
#define INCLUDE_ALLOW_VMCORE
30
#include "includeCheck.h"
36
#include "vm_atomic.h"
41
* The semantics of this wait queue primitive are as follows:
43
* o Client threads can add themselves to a waitqueue object and
44
* receive a pollable handle via a call to SyncWaitQ_Add
46
* o When the waitqueue is woken up, each handle that was
47
* previously obtained via a call to SyncWaitQ_Add becomes
48
* signaled and remains so until it is removed via a call to
49
* SyncWaitQ_Remove. Any calls to SyncWaitQ_Add, after the queue
50
* has been woken up, will return fresh, unsignaled handles.
52
* For more information please refer to comments in the
53
* respective syncWaitQ{host}.c files
62
* Memory buffer that stores information about an wait queue
65
* In the case of named queues, this structure can be allocated
66
* on shared memory and shared between multiple processes.
68
* This structure, however, cannot be memcpy()-ed
72
typedef struct SyncWaitQ {
74
* Common members used for both named and unnamed objects
77
// Whether the waitqueue has been initialized;
80
// Whether queue uses eventfd or pipe
83
// Whether there are any waiters on this queue
84
Atomic_uint32 waiters;
85
// A unique sequence number of the queue
89
* Members used in case of named objects
92
// Name of the waitqueue object (FIFO path on Linux or Event name on Win32)
96
* The following handles are only used only in the case of
99
* On Win32 the readHandle is a handle to an event object
101
* On Posix the rwHandles are the read and write ends of an anonymous pipe,
108
Atomic_uint64 readHandle;
111
Atomic_uint64 pipeHandles64;
112
Atomic_uint32 pipeHandles[2];
113
Atomic_uint32 eventHandle;
116
pthread_mutex_t mutex;
118
#endif // #ifdef _WIN32
121
Bool SyncWaitQ_Init(SyncWaitQ *that, char const *path);
122
void SyncWaitQ_Destroy(SyncWaitQ *that);
123
PollDevHandle SyncWaitQ_Add(SyncWaitQ *that);
124
Bool SyncWaitQ_Remove(SyncWaitQ *that, PollDevHandle fd);
125
Bool SyncWaitQ_WakeUp(SyncWaitQ *that);
127
#endif // #infdef _SYNC_WAITQ_H_