vkd3d: Move the vkd3d_mutex implementation to vkd3d-common.

This commit is contained in:
Henri Verbeet 2024-03-18 16:09:43 +01:00 committed by Alexandre Julliard
parent 2431357fd6
commit 166dc24b2f
Notes: Alexandre Julliard 2024-03-19 23:18:24 +01:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/732
2 changed files with 60 additions and 67 deletions

View File

@ -30,6 +30,9 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#ifndef _WIN32
#include <pthread.h>
#endif
#ifdef _MSC_VER
#include <intrin.h>
@ -424,6 +427,63 @@ static inline uint32_t vkd3d_atomic_increment_u32(uint32_t volatile *x)
return vkd3d_atomic_add_fetch_u32(x, 1);
}
struct vkd3d_mutex
{
#ifdef _WIN32
CRITICAL_SECTION lock;
#else
pthread_mutex_t lock;
#endif
};
static inline void vkd3d_mutex_init(struct vkd3d_mutex *lock)
{
#ifdef _WIN32
InitializeCriticalSection(&lock->lock);
#else
int ret;
if ((ret = pthread_mutex_init(&lock->lock, NULL)))
ERR("Failed to initialise the mutex, ret %d.\n", ret);
#endif
}
static inline void vkd3d_mutex_lock(struct vkd3d_mutex *lock)
{
#ifdef _WIN32
EnterCriticalSection(&lock->lock);
#else
int ret;
if ((ret = pthread_mutex_lock(&lock->lock)))
ERR("Failed to lock the mutex, ret %d.\n", ret);
#endif
}
static inline void vkd3d_mutex_unlock(struct vkd3d_mutex *lock)
{
#ifdef _WIN32
LeaveCriticalSection(&lock->lock);
#else
int ret;
if ((ret = pthread_mutex_unlock(&lock->lock)))
ERR("Failed to unlock the mutex, ret %d.\n", ret);
#endif
}
static inline void vkd3d_mutex_destroy(struct vkd3d_mutex *lock)
{
#ifdef _WIN32
DeleteCriticalSection(&lock->lock);
#else
int ret;
if ((ret = pthread_mutex_destroy(&lock->lock)))
ERR("Failed to destroy the mutex, ret %d.\n", ret);
#endif
}
static inline void vkd3d_parse_version(const char *version, int *major, int *minor)
{
*major = atoi(version);

View File

@ -203,36 +203,11 @@ union vkd3d_thread_handle
void *handle;
};
struct vkd3d_mutex
{
CRITICAL_SECTION lock;
};
struct vkd3d_cond
{
CONDITION_VARIABLE cond;
};
static inline void vkd3d_mutex_init(struct vkd3d_mutex *lock)
{
InitializeCriticalSection(&lock->lock);
}
static inline void vkd3d_mutex_lock(struct vkd3d_mutex *lock)
{
EnterCriticalSection(&lock->lock);
}
static inline void vkd3d_mutex_unlock(struct vkd3d_mutex *lock)
{
LeaveCriticalSection(&lock->lock);
}
static inline void vkd3d_mutex_destroy(struct vkd3d_mutex *lock)
{
DeleteCriticalSection(&lock->lock);
}
static inline void vkd3d_cond_init(struct vkd3d_cond *cond)
{
InitializeConditionVariable(&cond->cond);
@ -288,53 +263,11 @@ union vkd3d_thread_handle
void *handle;
};
struct vkd3d_mutex
{
pthread_mutex_t lock;
};
struct vkd3d_cond
{
pthread_cond_t cond;
};
static inline void vkd3d_mutex_init(struct vkd3d_mutex *lock)
{
int ret;
ret = pthread_mutex_init(&lock->lock, NULL);
if (ret)
ERR("Could not initialize the mutex, error %d.\n", ret);
}
static inline void vkd3d_mutex_lock(struct vkd3d_mutex *lock)
{
int ret;
ret = pthread_mutex_lock(&lock->lock);
if (ret)
ERR("Could not lock the mutex, error %d.\n", ret);
}
static inline void vkd3d_mutex_unlock(struct vkd3d_mutex *lock)
{
int ret;
ret = pthread_mutex_unlock(&lock->lock);
if (ret)
ERR("Could not unlock the mutex, error %d.\n", ret);
}
static inline void vkd3d_mutex_destroy(struct vkd3d_mutex *lock)
{
int ret;
ret = pthread_mutex_destroy(&lock->lock);
if (ret)
ERR("Could not destroy the mutex, error %d.\n", ret);
}
static inline void vkd3d_cond_init(struct vkd3d_cond *cond)
{
int ret;