Skip to content

Commit

Permalink
liblegacy: Removal of Qt dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 8a82388 commit e71e509
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 59 deletions.
2 changes: 1 addition & 1 deletion doomsday/libs/legacy/CMakeLists.txt
Expand Up @@ -5,7 +5,7 @@ project (DE_LIBLEGACY)
include (../../cmake/Config.cmake)

# Dependencies.
find_package (DengCore)
find_package (DengCore REQUIRED)

# Options.
option (DE_LIBLEGACY_WRITER_TYPE_CHECK
Expand Down
35 changes: 18 additions & 17 deletions doomsday/libs/legacy/include/de/concurrency.h
Expand Up @@ -2,7 +2,7 @@
* @file concurrency.h
* Concurrency: threads, mutexes, semaphores.
*
* @authors Copyright © 2003-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2003-2018 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2006 Jamie Jones <jamie_jones_au@yahoo.com.au>
*
Expand Down Expand Up @@ -45,31 +45,30 @@ typedef enum systhreadexitstatus_e {
typedef std::function<int (void *)> systhreadfunc_t;

#ifdef __DE__ // libdeng internal
#include <QThread>
#include <de/Thread>
/**
* Thread that runs a user-specified callback function. Exceptions from the callback
* function are caught.
*/
class CallbackThread : public QThread
class CallbackThread
: public de::Thread
, DE_OBSERVES(de::Thread, Finished)
{
Q_OBJECT

public:
CallbackThread(systhreadfunc_t func, void *parm = 0);
~CallbackThread();

void run();
int exitValue() const;
void run() override;
int exitValue() const;
systhreadexitstatus_t exitStatus() const;
void setTerminationFunc(void (*func)(systhreadexitstatus_t));
void setTerminationFunc(void (*func)(systhreadexitstatus_t));

protected slots:
void deleteNow();
void threadFinished(Thread &) override;

private:
systhreadfunc_t _callback;
void *_parm;
int _returnValue;
systhreadfunc_t _callback;
void * _parm;
int _returnValue;
systhreadexitstatus_t _exitStatus;
void (*_terminationFunc)(systhreadexitstatus_t);
};
Expand All @@ -87,8 +86,9 @@ protected slots:
* of the thread as a parameter.
* @return Thread handle.
*/
DE_PUBLIC thread_t Sys_StartThread(systhreadfunc_t startpos, void *parm,
void (*terminationFunc)(systhreadexitstatus_t));
DE_PUBLIC thread_t Sys_StartThread(systhreadfunc_t startpos,
void * parm,
void (*terminationFunc)(systhreadexitstatus_t));

extern "C" {
#endif // __cplusplus
Expand All @@ -104,8 +104,9 @@ extern "C" {
* of the thread as a parameter.
* @return Thread handle.
*/
DE_PUBLIC thread_t Sys_StartThread(int (*startpos)(void *), void *parm,
void (*terminationFunc)(systhreadexitstatus_t));
DE_PUBLIC thread_t Sys_StartThread(int (*startpos)(void *),
void *parm,
void (*terminationFunc)(systhreadexitstatus_t));

DE_PUBLIC void Thread_Sleep(int milliseconds);

Expand Down
4 changes: 0 additions & 4 deletions doomsday/libs/legacy/include/de/liblegacy.h
Expand Up @@ -52,10 +52,6 @@
# endif
#endif

#ifdef DE_USE_QT
# include <QtCore/qglobal.h>
#endif

#include <assert.h>
#include <stddef.h>

Expand Down
10 changes: 5 additions & 5 deletions doomsday/libs/legacy/include/de/str.hh
Expand Up @@ -25,7 +25,7 @@
#include "liblegacy.h"
#include "str.h"

#include <QString>
#include <de/String>

namespace de {

Expand All @@ -34,21 +34,21 @@ namespace de {
*/
class Str {
public:
Str(char const *text = 0) {
Str(const char *text = 0) {
Str_InitStd(&str);
if (text) {
Str_Set(&str, text);
}
}
Str(QString const &text) {
Str(const String &text) {
Str_InitStd(&str);
Str_Set(&str, text.toUtf8());
Str_Set(&str, text);
}
~Str() {
// This should never be called directly.
Str_Free(&str);
}
operator char const *(void) const {
operator const char *(void) const {
return str.str;
}
operator ddstring_t *(void) {
Expand Down
61 changes: 31 additions & 30 deletions doomsday/libs/legacy/src/concurrency.cpp
Expand Up @@ -2,7 +2,7 @@
* @file concurrency.cpp
* Concurrency: threads, mutexes, semaphores.
*
* @authors Copyright © 2003-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2003-2018 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2006 Jamie Jones <jamie_jones_au@yahoo.com.au>
*
Expand All @@ -22,46 +22,46 @@
*/

#include "de/concurrency.h"
#include <QMutex>
#include <QCoreApplication>
#include <QDebug>
#include <de/App>
#include <de/Time>
#include <de/Log>
#include <de/Garbage>
#include <assert.h>

CallbackThread::CallbackThread(systhreadfunc_t func, void *param)
: _callback(func), _parm(param), _returnValue(0),
_exitStatus(DE_THREAD_STOPPED_NORMALLY),
_terminationFunc(0)
: _callback(std::move(func))
, _parm(param)
, _returnValue(0)
, _exitStatus(DE_THREAD_STOPPED_NORMALLY)
, _terminationFunc(nullptr)
{
//qDebug() << "CallbackThread:" << this << "created.";

// Only used if the thread needs to be shut down forcibly.
setTerminationEnabled(true);

// Cleanup at app exit time for threads whose exit value hasn't been checked.
connect(qApp, SIGNAL(destroyed()), this, SLOT(deleteNow()));
audienceForFinished() += this;
}

CallbackThread::~CallbackThread()
{
if (isRunning())
{
//qDebug() << "CallbackThread:" << this << "forcibly stopping, deleting.";
de::debug("CallbackThread %p being forcibly stopped before deletion", this);
terminate();
wait(1000);
// wait(1000);
}
else
{
//qDebug() << "CallbackThread:" << this << "deleted.";
}
}

void CallbackThread::deleteNow()
//void CallbackThread::deleteNow()
void CallbackThread::threadFinished(Thread &)
{
delete this;
de::trash(this); //delete this;
}

void CallbackThread::run()
Expand All @@ -76,10 +76,10 @@ void CallbackThread::run()
}
_exitStatus = DE_THREAD_STOPPED_NORMALLY;
}
catch (std::exception const &error)
catch (const std::exception &error)
{
LOG_AS("CallbackThread");
LOG_ERROR(QString("Uncaught exception: ") + error.what());
LOG_ERROR("Uncaught exception: ") << error.what();
_returnValue = -1;
_exitStatus = DE_THREAD_STOPPED_WITH_EXCEPTION;
}
Expand All @@ -92,7 +92,7 @@ void CallbackThread::run()
Garbage_ClearForThread();

// No more log output from this thread.
de::Log::disposeThreadLog();
//de::Log::disposeThreadLog();
}

int CallbackThread::exitValue() const
Expand Down Expand Up @@ -128,7 +128,7 @@ void Thread_Sleep(int milliseconds)

thread_t Sys_StartThread(systhreadfunc_t startpos, void *parm, void (*terminationFunc)(systhreadexitstatus_t))
{
CallbackThread *t = new CallbackThread(startpos, parm);
CallbackThread *t = new CallbackThread(std::move(startpos), parm);
t->setTerminationFunc(terminationFunc);
t->start();
return t;
Expand All @@ -141,12 +141,12 @@ thread_t Sys_StartThread(int (*startpos)(void *), void *parm, void (*termination

void Thread_KillAbnormally(thread_t handle)
{
QThread *t = reinterpret_cast<QThread *>(handle);
de::Thread *t = reinterpret_cast<de::Thread *>(handle);
if (!handle)
{
t = QThread::currentThread();
t = de::Thread::currentThread();
}
assert(t);
DE_ASSERT(t);
t->terminate();
}

Expand All @@ -168,7 +168,7 @@ int Sys_WaitThread(thread_t handle, int timeoutMs, systhreadexitstatus_t *exitSt
}

CallbackThread *t = reinterpret_cast<CallbackThread *>(handle);
assert(static_cast<QThread *>(t) != QThread::currentThread());
DE_ASSERT(static_cast<de::Thread *>(t) != de::Thread::currentThread());
t->wait(timeoutMs);
if (!t->isFinished())
{
Expand All @@ -179,40 +179,41 @@ int Sys_WaitThread(thread_t handle, int timeoutMs, systhreadexitstatus_t *exitSt
{
if (exitStatus) *exitStatus = t->exitStatus();
}
t->deleteLater(); // get rid of it
//t->deleteLater(); // get rid of it
de::trash(t);
return t->exitValue();
}

uint32_t Sys_ThreadId(thread_t handle)
{
QThread *t = reinterpret_cast<QThread *>(handle);
if (!t) t = QThread::currentThread();
auto *t = reinterpret_cast<de::Thread *>(handle);
if (!t) t = de::Thread::currentThread();
return uint32_t(PTR2INT(t));
}

uint32_t Sys_CurrentThreadId(void)
{
return Sys_ThreadId(NULL /*this thread*/);
return Sys_ThreadId(nullptr /*this thread*/);
}

/// @todo remove the name parameter
mutex_t Sys_CreateMutex(const char *)
{
return new QMutex(QMutex::Recursive);
return new std::recursive_mutex;
}

void Sys_DestroyMutex(mutex_t handle)
{
if (handle)
{
delete reinterpret_cast<QMutex *>(handle);
delete reinterpret_cast<std::recursive_mutex *>(handle);
}
}

void Sys_Lock(mutex_t handle)
{
QMutex *m = reinterpret_cast<QMutex *>(handle);
assert(m != 0);
auto *m = reinterpret_cast<std::recursive_mutex *>(handle);
DE_ASSERT(m != nullptr);
if (m)
{
m->lock();
Expand All @@ -221,8 +222,8 @@ void Sys_Lock(mutex_t handle)

void Sys_Unlock(mutex_t handle)
{
QMutex *m = reinterpret_cast<QMutex *>(handle);
assert(m != 0);
auto *m = reinterpret_cast<std::recursive_mutex *>(handle);
DE_ASSERT(m != nullptr);
if (m)
{
m->unlock();
Expand Down
2 changes: 0 additions & 2 deletions doomsday/libs/legacy/src/timer.cpp
Expand Up @@ -23,8 +23,6 @@
* 02110-1301 USA</small>
*/

#include <QTime>

#ifdef WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
Expand Down

0 comments on commit e71e509

Please sign in to comment.