sw_engine: fix invalid data sharing at multi-threading.
authorHermet Park <chuneon.park@samsung.com>
Fri, 7 May 2021 10:45:07 +0000 (19:45 +0900)
committerJunsuChoi <jsuya.choi@samsung.com>
Thu, 13 May 2021 08:22:11 +0000 (17:22 +0900)
commit7c8d026dd226f00151ee1062be6bf57efbaf08b5
tree9effc952ed00cea2780d1cb3ee4b2b491437b2e6
parentc81325301735347250891b9d2d61c89747e43620
sw_engine: fix invalid data sharing at multi-threading.

We have encountered that multi-threading usage that user creates,
multiple canvases owned by multiple user threads.

Current sw_engine memory pool has been considered only for multi-threads,
spawned by tvg task scheduler.

In this case it's safe but when user threads introduced, it can occur race-condition.

Thus, Here is a renewal policy that non-threading tvg(initialized threads with zero),
takes care of multiple user threads bu changing its policy,
each of canvases should have individual memory pool to guarantee mutual-exclusion.

@API additions

enum MempoolPolicy
{
    Default = 0, ///< Default behavior that ThorVG is designed to.
    Shareable,   ///< Memory Pool is shared among the SwCanvases.
    Individual   ///< Allocate designated memory pool that is only used by current instance.
};

Result SwCanvas::mempool(MempoolPolicy policy) noexcept;

All in all, if user calls multiple threads, set memory pool policy to Individual.
inc/thorvg.h
src/lib/sw_engine/tvgSwCommon.h
src/lib/sw_engine/tvgSwImage.cpp
src/lib/sw_engine/tvgSwMemPool.cpp
src/lib/sw_engine/tvgSwRenderer.cpp
src/lib/sw_engine/tvgSwRenderer.h
src/lib/sw_engine/tvgSwShape.cpp
src/lib/sw_engine/tvgSwStroke.cpp
src/lib/tvgSwCanvas.cpp