Serge Ivanov
[wine/multimedia.git] / dlls / ntdll / sync.c
blobddd306742b5023ee85482fc99a80432c04305153
1 /*
2 * Process synchronisation
3 */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <time.h>
9 #include "debugtools.h"
11 #include "winerror.h"
12 #include "server.h"
13 #include "ntddk.h"
14 #include "ntdll_misc.h"
16 DEFAULT_DEBUG_CHANNEL(ntdll);
18 /* copy a key name into the request buffer */
19 static inline NTSTATUS copy_nameU( LPWSTR Dest, const OBJECT_ATTRIBUTES *attr )
21 if (attr && attr->ObjectName && attr->ObjectName->Buffer)
23 if ((attr->ObjectName->Length) > MAX_PATH) return STATUS_BUFFER_OVERFLOW;
24 lstrcpyW( Dest, attr->ObjectName->Buffer );
26 else Dest[0] = 0;
27 return STATUS_SUCCESS;
31 * Semaphores
34 /******************************************************************************
35 * NtCreateSemaphore
37 NTSTATUS WINAPI NtCreateSemaphore(
38 OUT PHANDLE SemaphoreHandle,
39 IN ACCESS_MASK DesiredAccess,
40 IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
41 IN ULONG InitialCount,
42 IN ULONG MaximumCount)
44 struct create_semaphore_request *req = get_req_buffer();
45 NTSTATUS ret;
47 if ((MaximumCount <= 0) || (InitialCount < 0) || (InitialCount > MaximumCount))
48 return STATUS_INVALID_PARAMETER;
50 *SemaphoreHandle = 0;
51 req->initial = InitialCount;
52 req->max = MaximumCount;
53 req->inherit = ObjectAttributes && (ObjectAttributes->Attributes & OBJ_INHERIT);
54 if (!(ret = copy_nameU( req->name, ObjectAttributes )) &&
55 !(ret = server_call_noerr( REQ_CREATE_SEMAPHORE ))) *SemaphoreHandle = req->handle;
56 return ret;
59 /******************************************************************************
60 * NtOpenSemaphore
62 NTSTATUS WINAPI NtOpenSemaphore(
63 OUT PHANDLE SemaphoreHandle,
64 IN ACCESS_MASK DesiredAcces,
65 IN POBJECT_ATTRIBUTES ObjectAttributes)
67 struct open_semaphore_request *req = get_req_buffer();
68 NTSTATUS ret;
70 *SemaphoreHandle = 0;
71 req->access = DesiredAcces;
72 req->inherit = ObjectAttributes && (ObjectAttributes->Attributes & OBJ_INHERIT);
73 if (!(ret = copy_nameU( req->name, ObjectAttributes )) &&
74 !(ret = server_call_noerr( REQ_OPEN_SEMAPHORE ))) *SemaphoreHandle = req->handle;
75 return ret;
78 /******************************************************************************
79 * NtQuerySemaphore
81 NTSTATUS WINAPI NtQuerySemaphore(
82 HANDLE SemaphoreHandle,
83 PVOID SemaphoreInformationClass,
84 OUT PVOID SemaphoreInformation,
85 ULONG Length,
86 PULONG ReturnLength)
88 FIXME("(0x%08x,%p,%p,0x%08lx,%p) stub!\n",
89 SemaphoreHandle, SemaphoreInformationClass, SemaphoreInformation, Length, ReturnLength);
90 return STATUS_SUCCESS;
92 /******************************************************************************
93 * NtReleaseSemaphore
95 NTSTATUS WINAPI NtReleaseSemaphore(
96 IN HANDLE SemaphoreHandle,
97 IN ULONG ReleaseCount,
98 IN PULONG PreviousCount)
100 struct release_semaphore_request *req = get_req_buffer();
101 NTSTATUS ret;
103 if (ReleaseCount < 0) return STATUS_INVALID_PARAMETER;
105 req->handle = SemaphoreHandle;
106 req->count = ReleaseCount;
107 if (!(ret = server_call_noerr( REQ_RELEASE_SEMAPHORE )))
109 if (PreviousCount) *PreviousCount = req->prev_count;
111 return ret;
115 * Events
118 /**************************************************************************
119 * NtCreateEvent
121 NTSTATUS WINAPI NtCreateEvent(
122 OUT PHANDLE EventHandle,
123 IN ACCESS_MASK DesiredAccess,
124 IN POBJECT_ATTRIBUTES ObjectAttributes,
125 IN BOOLEAN ManualReset,
126 IN BOOLEAN InitialState)
128 struct create_event_request *req = get_req_buffer();
129 NTSTATUS ret;
131 *EventHandle = 0;
132 req->manual_reset = ManualReset;
133 req->initial_state = InitialState;
134 req->inherit = ObjectAttributes && (ObjectAttributes->Attributes & OBJ_INHERIT);
135 if (!(ret = copy_nameU( req->name, ObjectAttributes )) &&
136 !(ret = server_call_noerr( REQ_CREATE_EVENT ))) *EventHandle = req->handle;
137 return ret;
140 /******************************************************************************
141 * NtOpenEvent
143 NTSTATUS WINAPI NtOpenEvent(
144 OUT PHANDLE EventHandle,
145 IN ACCESS_MASK DesiredAccess,
146 IN POBJECT_ATTRIBUTES ObjectAttributes)
148 struct open_event_request *req = get_req_buffer();
149 NTSTATUS ret;
151 *EventHandle = 0;
152 req->access = DesiredAccess;
153 req->inherit = ObjectAttributes && (ObjectAttributes->Attributes & OBJ_INHERIT);
154 if (!(ret = copy_nameU( req->name, ObjectAttributes )) &&
155 !(ret = server_call_noerr( REQ_OPEN_EVENT ))) *EventHandle = req->handle;
156 return ret;
160 /******************************************************************************
161 * NtSetEvent
163 NTSTATUS WINAPI NtSetEvent(
164 IN HANDLE EventHandle,
165 PULONG NumberOfThreadsReleased)
167 struct event_op_request *req = get_req_buffer();
168 FIXME("(0x%08x,%p)\n", EventHandle, NumberOfThreadsReleased);
169 req->handle = EventHandle;
170 req->op = SET_EVENT;
171 return server_call_noerr( REQ_EVENT_OP );
174 /******************************************************************************
175 * NtResetEvent
177 NTSTATUS WINAPI NtResetEvent(
178 IN HANDLE EventHandle,
179 PULONG NumberOfThreadsReleased)
181 struct event_op_request *req = get_req_buffer();
182 FIXME("(0x%08x,%p)\n", EventHandle, NumberOfThreadsReleased);
183 req->handle = EventHandle;
184 req->op = RESET_EVENT;
185 return server_call_noerr( REQ_EVENT_OP );
188 /******************************************************************************
189 * NtClearEvent
191 * FIXME
192 * same as NtResetEvent ???
194 NTSTATUS WINAPI NtClearEvent (
195 IN HANDLE EventHandle)
197 return NtResetEvent( EventHandle, NULL );
200 /******************************************************************************
201 * NtPulseEvent
203 * FIXME
204 * PulseCount
206 NTSTATUS WINAPI NtPulseEvent(
207 IN HANDLE EventHandle,
208 IN PULONG PulseCount)
210 struct event_op_request *req = get_req_buffer();
211 FIXME("(0x%08x,%p)\n", EventHandle, PulseCount);
212 req->handle = EventHandle;
213 req->op = PULSE_EVENT;
214 return server_call_noerr( REQ_EVENT_OP );
217 /******************************************************************************
218 * NtQueryEvent
220 NTSTATUS WINAPI NtQueryEvent (
221 IN HANDLE EventHandle,
222 IN UINT EventInformationClass,
223 OUT PVOID EventInformation,
224 IN ULONG EventInformationLength,
225 OUT PULONG ReturnLength)
227 FIXME("(0x%08x)\n", EventHandle);
228 return STATUS_SUCCESS;