4 * Copyright 1998 Alexandre Julliard
11 #include "server/request.h"
15 /***********************************************************************
16 * CreateMutex32A (KERNEL32.166)
18 HANDLE WINAPI
CreateMutexA( SECURITY_ATTRIBUTES
*sa
, BOOL owner
, LPCSTR name
)
20 struct create_mutex_request req
;
21 struct create_mutex_reply reply
;
22 int len
= name
? strlen(name
) + 1 : 0;
25 req
.inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
26 CLIENT_SendRequest( REQ_CREATE_MUTEX
, -1, 2, &req
, sizeof(req
), name
, len
);
28 CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
);
29 if (reply
.handle
== -1) return 0;
34 /***********************************************************************
35 * CreateMutex32W (KERNEL32.167)
37 HANDLE WINAPI
CreateMutexW( SECURITY_ATTRIBUTES
*sa
, BOOL owner
,
40 LPSTR nameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, name
);
41 HANDLE ret
= CreateMutexA( sa
, owner
, nameA
);
42 if (nameA
) HeapFree( GetProcessHeap(), 0, nameA
);
47 /***********************************************************************
48 * OpenMutex32A (KERNEL32.541)
50 HANDLE WINAPI
OpenMutexA( DWORD access
, BOOL inherit
, LPCSTR name
)
52 struct open_named_obj_request req
;
53 struct open_named_obj_reply reply
;
54 int len
= name
? strlen(name
) + 1 : 0;
56 req
.type
= OPEN_MUTEX
;
58 req
.inherit
= inherit
;
59 CLIENT_SendRequest( REQ_OPEN_NAMED_OBJ
, -1, 2, &req
, sizeof(req
), name
, len
);
60 CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
);
61 if (reply
.handle
== -1) return 0; /* must return 0 on failure, not -1 */
66 /***********************************************************************
67 * OpenMutex32W (KERNEL32.542)
69 HANDLE WINAPI
OpenMutexW( DWORD access
, BOOL inherit
, LPCWSTR name
)
71 LPSTR nameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, name
);
72 HANDLE ret
= OpenMutexA( access
, inherit
, nameA
);
73 if (nameA
) HeapFree( GetProcessHeap(), 0, nameA
);
78 /***********************************************************************
79 * ReleaseMutex (KERNEL32.582)
81 BOOL WINAPI
ReleaseMutex( HANDLE handle
)
83 struct release_mutex_request req
;
86 CLIENT_SendRequest( REQ_RELEASE_MUTEX
, -1, 1, &req
, sizeof(req
) );
87 return !CLIENT_WaitReply( NULL
, NULL
, 0 );