mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-07 21:23:32 +00:00
renderer: ++wasm build portability
removed the direct thread inclusion when those thread features are disabled
This commit is contained in:
parent
6847d951d8
commit
36be459c80
3 changed files with 32 additions and 16 deletions
|
@ -20,24 +20,17 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
|
||||
#include "tvgArray.h"
|
||||
#include "tvgInlist.h"
|
||||
#include "tvgTaskScheduler.h"
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
namespace tvg {
|
||||
|
||||
struct TaskSchedulerImpl;
|
||||
static TaskSchedulerImpl* _inst = nullptr;
|
||||
static std::thread::id _tid; //dominant thread id
|
||||
|
||||
|
||||
#ifdef THORVG_THREAD_SUPPORT
|
||||
|
||||
static thread_local bool _async = true;
|
||||
|
@ -196,11 +189,14 @@ struct TaskSchedulerImpl
|
|||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
static TaskSchedulerImpl* _inst = nullptr;
|
||||
static ThreadID _tid; //dominant thread id
|
||||
|
||||
void TaskScheduler::init(uint32_t threads)
|
||||
{
|
||||
if (_inst) return;
|
||||
_inst = new TaskSchedulerImpl(threads);
|
||||
_tid = std::this_thread::get_id();
|
||||
_tid = tid();
|
||||
}
|
||||
|
||||
|
||||
|
@ -219,8 +215,7 @@ void TaskScheduler::request(Task* task)
|
|||
|
||||
uint32_t TaskScheduler::threads()
|
||||
{
|
||||
if (_inst) return _inst->threadCnt();
|
||||
return 0;
|
||||
return _inst ? _inst->threadCnt() : 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -230,7 +225,18 @@ void TaskScheduler::async(bool on)
|
|||
_async = on;
|
||||
}
|
||||
|
||||
|
||||
bool TaskScheduler::onthread()
|
||||
{
|
||||
return _tid != std::this_thread::get_id();
|
||||
return _tid != tid();
|
||||
}
|
||||
|
||||
|
||||
ThreadID TaskScheduler::tid()
|
||||
{
|
||||
#ifdef THORVG_THREAD_SUPPORT
|
||||
return std::this_thread::get_id();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
|
@ -23,16 +23,23 @@
|
|||
#ifndef _TVG_TASK_SCHEDULER_H_
|
||||
#define _TVG_TASK_SCHEDULER_H_
|
||||
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
#include "tvgCommon.h"
|
||||
#include "tvgInlist.h"
|
||||
|
||||
#ifdef THORVG_THREAD_SUPPORT
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#endif
|
||||
|
||||
namespace tvg {
|
||||
|
||||
|
||||
#ifdef THORVG_THREAD_SUPPORT
|
||||
|
||||
using ThreadID = std::thread::id;
|
||||
|
||||
struct Task
|
||||
{
|
||||
private:
|
||||
|
@ -79,6 +86,8 @@ private:
|
|||
|
||||
#else //THORVG_THREAD_SUPPORT
|
||||
|
||||
using ThreadID = uint8_t;
|
||||
|
||||
struct Task
|
||||
{
|
||||
public:
|
||||
|
@ -105,6 +114,7 @@ struct TaskScheduler
|
|||
static void request(Task* task);
|
||||
static void async(bool on);
|
||||
static bool onthread(); //figure out whether on worker thread or not
|
||||
static ThreadID tid();
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*/
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <memory>
|
||||
#include "tvgStr.h"
|
||||
#include "tvgGifEncoder.h"
|
||||
#include "tvgGifSaver.h"
|
||||
|
|
Loading…
Add table
Reference in a new issue