Commit 829e6694 authored by Zebediah Figura's avatar Zebediah Figura Committed by Vitaly Lipatov

ntdll: Implement NtReleaseMutant().

parent 2051acb1
......@@ -424,6 +424,40 @@ NTSTATUS esync_create_mutex( HANDLE *handle, ACCESS_MASK access,
return create_esync( ESYNC_MUTEX, handle, access, attr, initial ? 0 : 1, 0 );
}
NTSTATUS esync_release_mutex( HANDLE *handle, LONG *prev )
{
struct esync *obj;
struct mutex *mutex;
static const uint64_t value = 1;
NTSTATUS ret;
TRACE("%p, %p.\n", handle, prev);
if ((ret = get_object( handle, &obj ))) return ret;
mutex = obj->shm;
/* This is thread-safe, because the only thread that can change the tid to
* or from our tid is ours. */
if (mutex->tid != GetCurrentThreadId()) return STATUS_MUTANT_NOT_OWNED;
if (prev) *prev = mutex->count;
mutex->count--;
if (!mutex->count)
{
/* This is also thread-safe, as long as signaling the file is the last
* thing we do. Other threads don't care about the tid if it isn't
* theirs. */
mutex->tid = 0;
if (write( obj->fd, &value, sizeof(value) ) == -1)
return errno_to_status( errno );
}
return STATUS_SUCCESS;
}
#define TICKSPERSEC 10000000
#define TICKSPERMSEC 10000
......
......@@ -33,6 +33,7 @@ extern NTSTATUS esync_set_event( HANDLE handle ) DECLSPEC_HIDDEN;
extern NTSTATUS esync_create_mutex( HANDLE *handle, ACCESS_MASK access,
const OBJECT_ATTRIBUTES *attr, BOOLEAN initial ) DECLSPEC_HIDDEN;
extern NTSTATUS esync_release_mutex( HANDLE *handle, LONG *prev ) DECLSPEC_HIDDEN;
extern NTSTATUS esync_wait_objects( DWORD count, const HANDLE *handles, BOOLEAN wait_any,
BOOLEAN alertable, const LARGE_INTEGER *timeout ) DECLSPEC_HIDDEN;
......
......@@ -609,6 +609,9 @@ NTSTATUS WINAPI NtReleaseMutant( HANDLE handle, LONG *prev_count )
{
NTSTATUS ret;
if (do_esync())
return esync_release_mutex( handle, prev_count );
SERVER_START_REQ( release_mutex )
{
req->handle = wine_server_obj_handle( handle );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment