renderer: ++optimization

skip locking if the thread number is 0.
This commit is contained in:
Hermet Park 2024-07-09 16:08:38 +09:00
parent 04dbc5f509
commit 19815de7d7
3 changed files with 24 additions and 14 deletions

View file

@ -28,6 +28,7 @@
#define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR
#include <mutex>
#include "tvgTaskScheduler.h"
namespace tvg {
@ -42,13 +43,17 @@ namespace tvg {
ScopedLock(Key& k)
{
k.mtx.lock();
key = &k;
if (TaskScheduler::threads() > 0) {
k.mtx.lock();
key = &k;
}
}
~ScopedLock()
{
key->mtx.unlock();
if (TaskScheduler::threads() > 0) {
key->mtx.unlock();
}
}
};

View file

@ -32,6 +32,20 @@
/* External Class Implementation */
/************************************************************************/
uint32_t RenderMethod::ref()
{
ScopedLock lock(key);
return (++refCnt);
}
uint32_t RenderMethod::unref()
{
ScopedLock lock(key);
return (--refCnt);
}
void RenderTransform::override(const Matrix& m)
{
this->m = m;

View file

@ -248,17 +248,8 @@ private:
Key key;
public:
uint32_t ref()
{
ScopedLock lock(key);
return (++refCnt);
}
uint32_t unref()
{
ScopedLock lock(key);
return (--refCnt);
}
uint32_t ref();
uint32_t unref();
virtual ~RenderMethod() {}
virtual RenderData prepare(const RenderShape& rshape, RenderData data, const RenderTransform* transform, Array<RenderData>& clips, uint8_t opacity, RenderUpdateFlag flags, bool clipper) = 0;