~n-muench/ubuntu/precise/open-vm-tools/open-vm-tools-precise.sid-merge1

« back to all changes in this revision

Viewing changes to lib/include/syncWaitQ.h

  • Committer: Evan Broder
  • Date: 2010-03-21 23:26:53 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: broder@mit.edu-20100321232653-5a57r7v7ch4o6byv
Merging shared upstream rev into target branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*********************************************************
2
 
 * Copyright (C) 1998 VMware, Inc. All rights reserved.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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.
16
 
 *
17
 
 *********************************************************/
18
 
 
19
 
/*
20
 
 * syncWaitQ.h --
21
 
 *
22
 
 *      Implements a platform independent wait queue
23
 
 */
24
 
 
25
 
#ifndef _SYNC_WAITQ_H_
26
 
#define _SYNC_WAITQ_H_
27
 
 
28
 
#define INCLUDE_ALLOW_USERLEVEL
29
 
#define INCLUDE_ALLOW_VMCORE
30
 
#include "includeCheck.h"
31
 
 
32
 
#if __APPLE__
33
 
#include <pthread.h>
34
 
#endif
35
 
 
36
 
#include "vm_atomic.h"
37
 
 
38
 
/*
39
 
 * syncWaitQ.h --
40
 
 *
41
 
 *      The semantics of this wait queue primitive are as follows:
42
 
 *
43
 
 *      o Client threads can add themselves to a waitqueue object and
44
 
 *      receive a pollable handle via a call to SyncWaitQ_Add
45
 
 *
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.
51
 
 *
52
 
 *      For more information please refer to comments in the
53
 
 *      respective syncWaitQ{host}.c files
54
 
 *
55
 
 *      -- Ticho.
56
 
 * 
57
 
 */
58
 
 
59
 
/*
60
 
 * SyncWaitQ --
61
 
 *
62
 
 *      Memory buffer that stores information about an wait queue
63
 
 *      object. 
64
 
 *
65
 
 *      In the case of named queues, this structure can be allocated
66
 
 *      on shared memory and shared between multiple processes.  
67
 
 *
68
 
 *      This structure, however, cannot be memcpy()-ed
69
 
 */
70
 
 
71
 
 
72
 
typedef struct SyncWaitQ {
73
 
   /*
74
 
    * Common members used for both named and unnamed objects
75
 
    */
76
 
 
77
 
   // Whether the waitqueue has been initialized;
78
 
   Bool            initialized;
79
 
#ifndef _WIN32
80
 
   // Whether queue uses eventfd or pipe
81
 
   Bool            usesEventFd;
82
 
#endif
83
 
   // Whether there are any waiters on this queue
84
 
   Atomic_uint32   waiters;
85
 
   // A unique sequence number of the queue
86
 
   Atomic_uint64   seq;
87
 
 
88
 
   /*
89
 
    * Members used in case of named objects
90
 
    */
91
 
 
92
 
   // Name of the waitqueue object (FIFO path on Linux or Event name on Win32)
93
 
   char *pathName;
94
 
 
95
 
   /*
96
 
    * The following handles are only used only in the case of
97
 
    * anonymous pipes.
98
 
    *
99
 
    * On Win32 the readHandle is a handle to an event object
100
 
    *
101
 
    * On Posix the rwHandles are the read and write ends of an anonymous pipe,
102
 
    *          or eventfd handle.
103
 
    *
104
 
    *    -- Ticho 
105
 
    */
106
 
   
107
 
#ifdef _WIN32
108
 
   Atomic_uint64 readHandle;
109
 
#else
110
 
   union {
111
 
      Atomic_uint64 pipeHandles64;
112
 
      Atomic_uint32 pipeHandles[2];
113
 
      Atomic_uint32 eventHandle;
114
 
                  } u;
115
 
#   if __APPLE__
116
 
   pthread_mutex_t mutex;
117
 
#   endif
118
 
#endif // #ifdef _WIN32
119
 
} SyncWaitQ;
120
 
 
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);
126
 
 
127
 
#endif // #infdef _SYNC_WAITQ_H_