1 /* NT semaphore functions for regutil
3 * The contents of this file are subject to the Mozilla Public License
4 * Version 1.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 * http://www.mozilla.org/MPL/
8 * Software distributed under the License is distributed on an "AS IS"
9 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
10 * License for the specific language governing rights and limitations
13 * The Original Code is regutil.
15 * The Initial Developer of the Original Code is Patrick TJ McPhee.
16 * Portions created by Patrick McPhee are Copyright © 1998, 2001
17 * Patrick TJ McPhee. All Rights Reserved.
21 * $Header: /opt/cvs/Regina/regutil/regsem.c,v 1.1 2009/10/07 07:51:59 mark Exp $
26 /* ******************************************************************** */
27 /* **************************** Semaphores **************************** */
28 /* ******************************************************************** */
29 static const char notimp
[] = "not implemented";
30 #define what() memcpy(result->strptr, notimp, sizeof(notimp)-1), result->strlength = sizeof(notimp)-1
32 /* syscloseeventsem(handle) */
33 rxfunc(syscloseeventsem
)
39 if (argv
[0].strlength
!= sizeof(semid
))
42 memcpy(&semid
, argv
[0].strptr
, sizeof(semid
));
45 result
->strlength
= sprintf(result
->strptr
, "%d", GetLastError());
50 /* sysclosemutexsem(handle) */
51 rxfunc(sysclosemutexsem
)
53 return syscloseeventsem(fname
, argc
, argv
, pSomething
, result
);
56 /* syscreateeventsem([name],[manual_reset]) */
57 rxfunc(syscreateeventsem
)
65 if (argc
> 0 && argv
[0].strlength
) {
66 rxstrdup(name
, argv
[0]);
71 if (argc
> 1 && argv
[1].strlength
)
72 rxstrdup(manual
, argv
[1]);
76 /* docs suggest the fact that this argument exists means the semaphore
77 * should be manual-reset */
78 if (manual
&& !stricmp(manual
, "yes"))
83 event
= CreateEvent(NULL
, bManual
, FALSE
, name
);
86 result
->strlength
= sizeof(event
);
87 memcpy(result
->strptr
, &event
, sizeof(event
));
91 result
->strlength
= 0;
97 /* syscreatemutexsem([name]) */
98 rxfunc(syscreatemutexsem
)
103 if (argc
> 0 && argv
[0].strlength
) {
104 rxstrdup(name
, argv
[0]);
109 mutex
= CreateMutex(NULL
, FALSE
, name
);
112 result
->strlength
= sizeof(mutex
);
113 memcpy(result
->strptr
, &mutex
, sizeof(mutex
));
116 result
->strlength
= 0;
123 /* sysopeneventsem(name) */
124 rxfunc(sysopeneventsem
)
131 rxstrdup(name
, argv
[0]);
133 event
= OpenEvent(EVENT_ALL_ACCESS
, FALSE
, name
);
136 result
->strlength
= sizeof(event
);
137 memcpy(result
->strptr
, &event
, sizeof(event
));
147 /* sysopenmutexsem(name) */
148 rxfunc(sysopenmutexsem
)
155 rxstrdup(name
, argv
[0]);
157 mutex
= OpenMutex(MUTEX_ALL_ACCESS
, FALSE
, name
);
160 result
->strlength
= sizeof(mutex
);
161 memcpy(result
->strptr
, &mutex
, sizeof(mutex
));
170 /* sysposteventsem(handle) */
171 rxfunc(sysposteventsem
)
177 memcpy(&event
, argv
[0].strptr
, sizeof(event
));
181 result
->strlength
= sprintf(result
->strptr
, "%d", GetLastError());
186 /* syspulseeventsem(handle) */
187 rxfunc(syspulseeventsem
)
193 memcpy(&event
, argv
[0].strptr
, sizeof(event
));
197 result
->strlength
= sprintf(result
->strptr
, "%d", GetLastError());
203 /* sysreleasemutexsem(handle) */
204 rxfunc(sysreleasemutexsem
)
210 memcpy(&mutex
, argv
[0].strptr
, sizeof(mutex
));
214 result
->strlength
= sprintf(result
->strptr
, "%d", GetLastError());
219 /* sysrequestmutexsem(handle, [timeout]) */
220 rxfunc(sysrequestmutexsem
)
229 memcpy(&mutex
, argv
[0].strptr
, sizeof(mutex
));
232 rxstrdup(timeout
, argv
[1]);
233 mtimeout
= atoi(timeout
);
239 rc
= WaitForSingleObject(mutex
, mtimeout
);
241 result
->strlength
= sprintf(result
->strptr
, "%d", rc
);
246 /* sysreseteventsem(handle) */
247 rxfunc(sysreseteventsem
)
253 memcpy(&event
, argv
[0].strptr
, sizeof(event
));
257 result
->strlength
= sprintf(result
->strptr
, "%d", GetLastError());
262 /* syswaiteventsem(handle, [timeout]) */
263 rxfunc(syswaiteventsem
)
271 memcpy(&event
, argv
[0].strptr
, sizeof(event
));
274 rxstrdup(timeout
, argv
[1]);
275 mtimeout
= atoi(timeout
);
281 rc
= WaitForSingleObject(event
, mtimeout
);
283 result
->strlength
= sprintf(result
->strptr
, "%d", rc
);