Browse Source

Get rid of utils/thread.{h,cpp}

pull/2443/head
Vladimir Olteanu 5 years ago committed by Anders Jenbo
parent
commit
1889f2badd
  1. 1
      CMakeLists.txt
  2. 84
      Source/utils/thread.cpp
  3. 23
      Source/utils/thread.h

1
CMakeLists.txt

@ -417,7 +417,6 @@ set(libdevilutionx_SRCS
Source/utils/file_util.cpp
Source/utils/language.cpp
Source/utils/paths.cpp
Source/utils/thread.cpp
Source/utils/sdl_thread.cpp
Source/DiabloUI/art.cpp
Source/DiabloUI/art_draw.cpp

84
Source/utils/thread.cpp

@ -1,84 +0,0 @@
#include "utils/thread.h"
#include <SDL.h>
#include <set>
#include "appfat.h"
#include "utils/log.hpp"
#include "utils/stubs.h"
namespace devilution {
static int SDLCALL ThreadTranslate(void *ptr)
{
auto handler = (void (*)())ptr;
handler();
return 0;
}
SDL_Thread *CreateThread(void (*handler)(), SDL_threadID *threadId)
{
#ifdef USE_SDL1
SDL_Thread *ret = SDL_CreateThread(ThreadTranslate, (void *)handler);
#else
SDL_Thread *ret = SDL_CreateThread(ThreadTranslate, nullptr, (void *)handler);
#endif
if (ret == nullptr) {
ErrSdl();
}
*threadId = SDL_GetThreadID(ret);
return ret;
}
event_emul *StartEvent()
{
event_emul *ret;
ret = new event_emul();
ret->mutex = SDL_CreateMutex();
if (ret->mutex == nullptr) {
ErrSdl();
}
ret->cond = SDL_CreateCond();
if (ret->cond == nullptr) {
ErrSdl();
}
return ret;
}
void EndEvent(event_emul *event)
{
SDL_DestroyCond(event->cond);
SDL_DestroyMutex(event->mutex);
delete event;
}
void SetEvent(event_emul *e)
{
if (SDL_LockMutex(e->mutex) <= -1 || SDL_CondSignal(e->cond) <= -1 || SDL_UnlockMutex(e->mutex) <= -1) {
ErrSdl();
}
}
void ResetEvent(event_emul *e)
{
if (SDL_LockMutex(e->mutex) <= -1 || SDL_CondWaitTimeout(e->cond, e->mutex, 0) <= -1 || SDL_UnlockMutex(e->mutex) <= -1) {
ErrSdl();
}
}
int WaitForEvent(event_emul *e)
{
if (SDL_LockMutex(e->mutex) <= -1) {
ErrSdl();
}
int ret = SDL_CondWait(e->cond, e->mutex);
if (ret <= -1 || SDL_CondSignal(e->cond) <= -1 || SDL_UnlockMutex(e->mutex) <= -1) {
Log("{}", SDL_GetError());
return -1;
}
return ret;
}
} // namespace devilution

23
Source/utils/thread.h

@ -1,23 +0,0 @@
#pragma once
#include <SDL.h>
#ifdef USE_SDL1
#include "utils/sdl2_to_1_2_backports.h"
#endif
namespace devilution {
typedef struct event_emul {
SDL_mutex *mutex;
SDL_cond *cond;
} event_emul;
event_emul *StartEvent();
void EndEvent(event_emul *event);
void SetEvent(event_emul *e);
void ResetEvent(event_emul *e);
int WaitForEvent(event_emul *e);
SDL_Thread *CreateThread(void (*handler)(), SDL_threadID *ThreadID);
} // namespace devilution
Loading…
Cancel
Save