4 * Copyright 1998 Alexandre Julliard
13 #include "server/request.h"
22 /***********************************************************************
23 * CreateMutex32A (KERNEL32.166)
25 HANDLE WINAPI
CreateMutexA( SECURITY_ATTRIBUTES
*sa
, BOOL owner
,
28 struct create_mutex_request req
;
29 struct create_mutex_reply reply
;
30 int len
= name
? strlen(name
) + 1 : 0;
35 req
.inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
37 CLIENT_SendRequest( REQ_CREATE_MUTEX
, -1, 2, &req
, sizeof(req
), name
, len
);
38 CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
);
39 if (reply
.handle
== -1) return 0;
42 mutex
= (MUTEX
*)K32OBJ_Create( K32OBJ_MUTEX
, sizeof(*mutex
),
43 name
, reply
.handle
, MUTEX_ALL_ACCESS
,
45 if (mutex
) K32OBJ_DecCount( &mutex
->header
);
46 if (handle
== INVALID_HANDLE_VALUE
) handle
= 0;
52 /***********************************************************************
53 * CreateMutex32W (KERNEL32.167)
55 HANDLE WINAPI
CreateMutexW( SECURITY_ATTRIBUTES
*sa
, BOOL owner
,
58 LPSTR nameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, name
);
59 HANDLE ret
= CreateMutexA( sa
, owner
, nameA
);
60 if (nameA
) HeapFree( GetProcessHeap(), 0, nameA
);
65 /***********************************************************************
66 * OpenMutex32A (KERNEL32.541)
68 HANDLE WINAPI
OpenMutexA( DWORD access
, BOOL inherit
, LPCSTR name
)
72 struct open_named_obj_request req
;
73 struct open_named_obj_reply reply
;
74 int len
= name
? strlen(name
) + 1 : 0;
76 req
.type
= OPEN_MUTEX
;
78 req
.inherit
= inherit
;
79 CLIENT_SendRequest( REQ_OPEN_NAMED_OBJ
, -1, 2, &req
, sizeof(req
), name
, len
);
80 CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
);
81 if (reply
.handle
!= -1)
84 if ((obj
= K32OBJ_FindNameType( name
, K32OBJ_MUTEX
)) != NULL
)
86 handle
= HANDLE_Alloc( PROCESS_Current(), obj
, access
, inherit
, reply
.handle
);
87 K32OBJ_DecCount( obj
);
88 if (handle
== INVALID_HANDLE_VALUE
)
89 handle
= 0; /* must return 0 on failure, not -1 */
91 else CLIENT_CloseHandle( reply
.handle
);
98 /***********************************************************************
99 * OpenMutex32W (KERNEL32.542)
101 HANDLE WINAPI
OpenMutexW( DWORD access
, BOOL inherit
, LPCWSTR name
)
103 LPSTR nameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, name
);
104 HANDLE ret
= OpenMutexA( access
, inherit
, nameA
);
105 if (nameA
) HeapFree( GetProcessHeap(), 0, nameA
);
110 /***********************************************************************
111 * ReleaseMutex (KERNEL32.582)
113 BOOL WINAPI
ReleaseMutex( HANDLE handle
)
115 struct release_mutex_request req
;
117 req
.handle
= HANDLE_GetServerHandle( PROCESS_Current(), handle
,
118 K32OBJ_MUTEX
, MUTEX_MODIFY_STATE
);
119 if (req
.handle
== -1) return FALSE
;
120 CLIENT_SendRequest( REQ_RELEASE_MUTEX
, -1, 1, &req
, sizeof(req
) );
121 return !CLIENT_WaitReply( NULL
, NULL
, 0 );