mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
libs/vkd3d: Move event objects implementation to libvkd3d-utils.
The libvkd3d is not the best place for event objects implementation.
This commit is contained in:
parent
0c1432e671
commit
c7d123b122
@ -45,3 +45,111 @@ HRESULT WINAPI D3D12CreateDevice(IUnknown *adapter,
|
||||
|
||||
return vkd3d_create_device(&create_info, riid, device);
|
||||
}
|
||||
|
||||
/* Events */
|
||||
HANDLE WINAPI VKD3DCreateEvent(void)
|
||||
{
|
||||
struct vkd3d_event *event;
|
||||
int rc;
|
||||
|
||||
TRACE(".\n");
|
||||
|
||||
if (!(event = vkd3d_malloc(sizeof(*event))))
|
||||
return NULL;
|
||||
|
||||
if ((rc = pthread_mutex_init(&event->mutex, NULL)))
|
||||
{
|
||||
ERR("Failed to initialize mutex, error %d.\n", rc);
|
||||
vkd3d_free(event);
|
||||
return NULL;
|
||||
}
|
||||
if ((rc = pthread_cond_init(&event->cond, NULL)))
|
||||
{
|
||||
ERR("Failed to initialize condition variable, error %d.\n", rc);
|
||||
pthread_mutex_destroy(&event->mutex);
|
||||
vkd3d_free(event);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
event->is_signaled = FALSE;
|
||||
|
||||
TRACE("Created event %p.\n", event);
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
unsigned int WINAPI VKD3DWaitEvent(HANDLE event, unsigned int milliseconds)
|
||||
{
|
||||
struct vkd3d_event *impl = event;
|
||||
int rc;
|
||||
|
||||
TRACE("event %p, milliseconds %u.\n", event, milliseconds);
|
||||
|
||||
if ((rc = pthread_mutex_lock(&impl->mutex)))
|
||||
{
|
||||
ERR("Failed to lock mutex, error %d.\n", rc);
|
||||
return WAIT_FAILED;
|
||||
}
|
||||
|
||||
if (impl->is_signaled || !milliseconds)
|
||||
{
|
||||
BOOL is_signaled = impl->is_signaled;
|
||||
impl->is_signaled = FALSE;
|
||||
pthread_mutex_unlock(&impl->mutex);
|
||||
return is_signaled ? WAIT_OBJECT_0 : WAIT_TIMEOUT;
|
||||
}
|
||||
|
||||
if (milliseconds == INFINITE)
|
||||
{
|
||||
do
|
||||
{
|
||||
if ((rc = pthread_cond_wait(&impl->cond, &impl->mutex)))
|
||||
{
|
||||
ERR("Failed to wait on condition variable, error %d.\n", rc);
|
||||
pthread_mutex_unlock(&impl->mutex);
|
||||
return WAIT_FAILED;
|
||||
}
|
||||
} while (!impl->is_signaled);
|
||||
|
||||
impl->is_signaled = FALSE;
|
||||
pthread_mutex_unlock(&impl->mutex);
|
||||
return WAIT_OBJECT_0;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&impl->mutex);
|
||||
FIXME("Timed wait not implemented yet.\n");
|
||||
return WAIT_FAILED;
|
||||
}
|
||||
|
||||
BOOL WINAPI VKD3DSignalEvent(HANDLE event)
|
||||
{
|
||||
struct vkd3d_event *impl = event;
|
||||
int rc;
|
||||
|
||||
TRACE("event %p.\n", event);
|
||||
|
||||
if ((rc = pthread_mutex_lock(&impl->mutex)))
|
||||
{
|
||||
ERR("Failed to lock mutex, error %d.\n", rc);
|
||||
return FALSE;
|
||||
}
|
||||
impl->is_signaled = TRUE;
|
||||
pthread_cond_signal(&impl->cond);
|
||||
pthread_mutex_unlock(&impl->mutex);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void WINAPI VKD3DDestroyEvent(HANDLE event)
|
||||
{
|
||||
struct vkd3d_event *impl = event;
|
||||
int rc;
|
||||
|
||||
TRACE("event %p.\n", event);
|
||||
|
||||
if ((rc = pthread_mutex_destroy(&impl->mutex)))
|
||||
ERR("Failed to destroy mutex, error %d.\n", rc);
|
||||
if ((rc = pthread_cond_destroy(&impl->cond)))
|
||||
ERR("Failed to destroy condition variable, error %d.\n", rc);
|
||||
vkd3d_free(impl);
|
||||
}
|
||||
|
@ -23,10 +23,18 @@
|
||||
#ifndef __VKD3D_UTILS_PRIVATE_H
|
||||
#define __VKD3D_UTILS_PRIVATE_H
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#define COBJMACROS
|
||||
#define NONAMELESSUNION
|
||||
#include "vkd3d_debug.h"
|
||||
|
||||
#include "vkd3d_memory.h"
|
||||
#include "vkd3d.h"
|
||||
|
||||
struct vkd3d_event
|
||||
{
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
BOOL is_signaled;
|
||||
};
|
||||
|
||||
#endif /* __VKD3D_UTILS_PRIVATE_H */
|
||||
|
@ -51,110 +51,3 @@ HRESULT WINAPI vkd3d_create_device(const struct vkd3d_device_create_info *create
|
||||
riid, device);
|
||||
}
|
||||
|
||||
/* Events */
|
||||
HANDLE WINAPI VKD3DCreateEvent(void)
|
||||
{
|
||||
struct vkd3d_event *event;
|
||||
int rc;
|
||||
|
||||
TRACE(".\n");
|
||||
|
||||
if (!(event = vkd3d_malloc(sizeof(*event))))
|
||||
return NULL;
|
||||
|
||||
if ((rc = pthread_mutex_init(&event->mutex, NULL)))
|
||||
{
|
||||
ERR("Failed to initialize mutex, error %d.\n", rc);
|
||||
vkd3d_free(event);
|
||||
return NULL;
|
||||
}
|
||||
if ((rc = pthread_cond_init(&event->cond, NULL)))
|
||||
{
|
||||
ERR("Failed to initialize condition variable, error %d.\n", rc);
|
||||
pthread_mutex_destroy(&event->mutex);
|
||||
vkd3d_free(event);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
event->is_signaled = FALSE;
|
||||
|
||||
TRACE("Created event %p.\n", event);
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
unsigned int WINAPI VKD3DWaitEvent(HANDLE event, unsigned int milliseconds)
|
||||
{
|
||||
struct vkd3d_event *impl = event;
|
||||
int rc;
|
||||
|
||||
TRACE("event %p, milliseconds %u.\n", event, milliseconds);
|
||||
|
||||
if ((rc = pthread_mutex_lock(&impl->mutex)))
|
||||
{
|
||||
ERR("Failed to lock mutex, error %d.\n", rc);
|
||||
return WAIT_FAILED;
|
||||
}
|
||||
|
||||
if (impl->is_signaled || !milliseconds)
|
||||
{
|
||||
BOOL is_signaled = impl->is_signaled;
|
||||
impl->is_signaled = FALSE;
|
||||
pthread_mutex_unlock(&impl->mutex);
|
||||
return is_signaled ? WAIT_OBJECT_0 : WAIT_TIMEOUT;
|
||||
}
|
||||
|
||||
if (milliseconds == INFINITE)
|
||||
{
|
||||
do
|
||||
{
|
||||
if ((rc = pthread_cond_wait(&impl->cond, &impl->mutex)))
|
||||
{
|
||||
ERR("Failed to wait on condition variable, error %d.\n", rc);
|
||||
pthread_mutex_unlock(&impl->mutex);
|
||||
return WAIT_FAILED;
|
||||
}
|
||||
} while (!impl->is_signaled);
|
||||
|
||||
impl->is_signaled = FALSE;
|
||||
pthread_mutex_unlock(&impl->mutex);
|
||||
return WAIT_OBJECT_0;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&impl->mutex);
|
||||
FIXME("Timed wait not implemented yet.\n");
|
||||
return WAIT_FAILED;
|
||||
}
|
||||
|
||||
BOOL WINAPI VKD3DSignalEvent(HANDLE event)
|
||||
{
|
||||
struct vkd3d_event *impl = event;
|
||||
int rc;
|
||||
|
||||
TRACE("event %p.\n", event);
|
||||
|
||||
if ((rc = pthread_mutex_lock(&impl->mutex)))
|
||||
{
|
||||
ERR("Failed to lock mutex, error %d.\n", rc);
|
||||
return FALSE;
|
||||
}
|
||||
impl->is_signaled = TRUE;
|
||||
pthread_cond_signal(&impl->cond);
|
||||
pthread_mutex_unlock(&impl->mutex);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void WINAPI VKD3DDestroyEvent(HANDLE event)
|
||||
{
|
||||
struct vkd3d_event *impl = event;
|
||||
int rc;
|
||||
|
||||
TRACE("event %p.\n", event);
|
||||
|
||||
if ((rc = pthread_mutex_destroy(&impl->mutex)))
|
||||
ERR("Failed to destroy mutex, error %d.\n", rc);
|
||||
if ((rc = pthread_cond_destroy(&impl->cond)))
|
||||
ERR("Failed to destroy condition variable, error %d.\n", rc);
|
||||
vkd3d_free(impl);
|
||||
}
|
||||
|
@ -45,13 +45,6 @@ struct vkd3d_instance
|
||||
struct vkd3d_vk_instance_procs vk_procs;
|
||||
};
|
||||
|
||||
struct vkd3d_event
|
||||
{
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
BOOL is_signaled;
|
||||
};
|
||||
|
||||
struct vkd3d_waiting_event
|
||||
{
|
||||
UINT64 value;
|
||||
|
Loading…
Reference in New Issue
Block a user