Fixed/implemented various interrupt functions.
[wine.git] / scheduler / mutex.c
blob7bbe6a8f82e662601f9a33e1649314fafc67333a
1 /*
2 * Win32 mutexes
4 * Copyright 1998 Alexandre Julliard
5 */
7 #include <assert.h>
8 #include <string.h>
9 #include "winerror.h"
10 #include "heap.h"
11 #include "server/request.h"
12 #include "server.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;
24 req.owned = owner;
25 req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
26 CLIENT_SendRequest( REQ_CREATE_MUTEX, -1, 2, &req, sizeof(req), name, len );
27 SetLastError(0);
28 CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
29 if (reply.handle == -1) return 0;
30 return reply.handle;
34 /***********************************************************************
35 * CreateMutex32W (KERNEL32.167)
37 HANDLE WINAPI CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner,
38 LPCWSTR name )
40 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
41 HANDLE ret = CreateMutexA( sa, owner, nameA );
42 if (nameA) HeapFree( GetProcessHeap(), 0, nameA );
43 return ret;
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;
57 req.access = access;
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 */
62 return reply.handle;
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 );
74 return ret;
78 /***********************************************************************
79 * ReleaseMutex (KERNEL32.582)
81 BOOL WINAPI ReleaseMutex( HANDLE handle )
83 struct release_mutex_request req;
85 req.handle = handle;
86 CLIENT_SendRequest( REQ_RELEASE_MUTEX, -1, 1, &req, sizeof(req) );
87 return !CLIENT_WaitReply( NULL, NULL, 0 );