From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- gfx/angle/checkout/src/libANGLE/WorkerThread.h | 94 ++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 gfx/angle/checkout/src/libANGLE/WorkerThread.h (limited to 'gfx/angle/checkout/src/libANGLE/WorkerThread.h') diff --git a/gfx/angle/checkout/src/libANGLE/WorkerThread.h b/gfx/angle/checkout/src/libANGLE/WorkerThread.h new file mode 100644 index 0000000000..6ef94fcc5b --- /dev/null +++ b/gfx/angle/checkout/src/libANGLE/WorkerThread.h @@ -0,0 +1,94 @@ +// +// Copyright 2016 The ANGLE Project Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// WorkerThread: +// Asychronous tasks/threads for ANGLE, similar to a TaskRunner in Chromium. +// Can be implemented as different targets, depending on platform. +// + +#ifndef LIBANGLE_WORKER_THREAD_H_ +#define LIBANGLE_WORKER_THREAD_H_ + +#include +#include +#include + +#include "common/debug.h" +#include "libANGLE/features.h" + +namespace angle +{ + +class WorkerThreadPool; + +// A callback function with no return value and no arguments. +class Closure +{ + public: + virtual ~Closure() = default; + virtual void operator()() = 0; +}; + +// An event that we can wait on, useful for joining worker threads. +class WaitableEvent : angle::NonCopyable +{ + public: + WaitableEvent(); + virtual ~WaitableEvent(); + + // Waits indefinitely for the event to be signaled. + virtual void wait() = 0; + + // Peeks whether the event is ready. If ready, wait() will not block. + virtual bool isReady() = 0; + void setWorkerThreadPool(std::shared_ptr pool) { mPool = pool; } + + template + static void WaitMany(std::array, Count> *waitables) + { + ASSERT(Count > 0); + for (size_t index = 0; index < Count; ++index) + { + (*waitables)[index]->wait(); + } + } + + private: + std::shared_ptr mPool; +}; + +// A mock waitable event. +class WaitableEventDone final : public WaitableEvent +{ + public: + void wait() override; + bool isReady() override; +}; + +// Request WorkerThreads from the WorkerThreadPool. Each pool can keep worker threads around so +// we avoid the costly spin up and spin down time. +class WorkerThreadPool : angle::NonCopyable +{ + public: + WorkerThreadPool(); + virtual ~WorkerThreadPool(); + + static std::shared_ptr Create(bool multithreaded); + static std::shared_ptr PostWorkerTask(std::shared_ptr pool, + std::shared_ptr task); + + virtual void setMaxThreads(size_t maxThreads) = 0; + + virtual bool isAsync() = 0; + + private: + // Returns an event to wait on for the task to finish. + // If the pool fails to create the task, returns null. + virtual std::shared_ptr postWorkerTask(std::shared_ptr task) = 0; +}; + +} // namespace angle + +#endif // LIBANGLE_WORKER_THREAD_H_ -- cgit v1.2.3