2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "threads/Thread.h"
16 #include <gtest/gtest.h>
19 inline static bool waitForWaiters(E
& event
, int numWaiters
, std::chrono::milliseconds duration
)
21 for (auto i
= std::chrono::milliseconds::zero(); i
< duration
; i
++)
23 if (event
.getNumWaits() == numWaiters
)
26 std::this_thread::sleep_for(std::chrono::milliseconds(1));
32 inline static bool waitForThread(std::atomic
<long>& mutex
,
34 std::chrono::milliseconds duration
)
37 for (auto i
= std::chrono::milliseconds::zero(); i
< duration
; i
++)
39 if (mutex
== (long)numWaiters
)
43 std::unique_lock
<CCriticalSection
> tmplock(sec
); // kick any memory syncs
46 std::this_thread::sleep_for(std::chrono::milliseconds(1));
54 std::atomic
<long>* val
;
56 inline AtomicGuard(std::atomic
<long>* val_
) : val(val_
) { if (val
) ++(*val
); }
57 inline ~AtomicGuard() { if (val
) --(*val
); }
62 std::unique_ptr
<CThread
> cthread
;
65 inline explicit thread(IRunnable
& runnable
)
66 : cthread(std::make_unique
<CThread
>(&runnable
, "DumbThread"))
71 void join() { cthread
->Join(std::chrono::milliseconds::max()); }
73 bool timed_join(std::chrono::milliseconds duration
) { return cthread
->Join(duration
); }