Better implementation of inline functions SetLastError and
[wine.git] / scheduler / mutex.c
blob24bbe199a157f28698f383522a3e27dda6ba99b9
1 /*
2 * Win32 mutexes
4 * Copyright 1998 Alexandre Julliard
5 */
7 #include <assert.h>
8 #include <string.h>
9 #include "winerror.h"
10 #include "server.h"
13 /***********************************************************************
14 * CreateMutex32A (KERNEL32.166)
16 HANDLE WINAPI CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name )
18 struct create_mutex_request *req = get_req_buffer();
20 req->owned = owner;
21 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
22 server_strcpyAtoW( req->name, name );
23 SetLastError(0);
24 server_call( REQ_CREATE_MUTEX );
25 if (req->handle == -1) return 0;
26 return req->handle;
30 /***********************************************************************
31 * CreateMutex32W (KERNEL32.167)
33 HANDLE WINAPI CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name )
35 struct create_mutex_request *req = get_req_buffer();
37 req->owned = owner;
38 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
39 server_strcpyW( req->name, name );
40 SetLastError(0);
41 server_call( REQ_CREATE_MUTEX );
42 if (req->handle == -1) return 0;
43 return req->handle;
47 /***********************************************************************
48 * OpenMutex32A (KERNEL32.541)
50 HANDLE WINAPI OpenMutexA( DWORD access, BOOL inherit, LPCSTR name )
52 struct open_mutex_request *req = get_req_buffer();
54 req->access = access;
55 req->inherit = inherit;
56 server_strcpyAtoW( req->name, name );
57 server_call( REQ_OPEN_MUTEX );
58 if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */
59 return req->handle;
63 /***********************************************************************
64 * OpenMutex32W (KERNEL32.542)
66 HANDLE WINAPI OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name )
68 struct open_mutex_request *req = get_req_buffer();
70 req->access = access;
71 req->inherit = inherit;
72 server_strcpyW( req->name, name );
73 server_call( REQ_OPEN_MUTEX );
74 if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */
75 return req->handle;
79 /***********************************************************************
80 * ReleaseMutex (KERNEL32.582)
82 BOOL WINAPI ReleaseMutex( HANDLE handle )
84 struct release_mutex_request *req = get_req_buffer();
85 req->handle = handle;
86 return !server_call( REQ_RELEASE_MUTEX );