-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
128 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "TestGlobal.h" | ||
|
||
#include <mutex> | ||
#include <condition_variable> | ||
|
||
#include <dispatch/dispatch.h> | ||
|
||
|
||
static int g_AsyncCount = 0; | ||
static std::mutex g_AsyncCountMutex; | ||
static std::condition_variable g_AsyncCountCond; | ||
dispatch_queue_t g_TestQueue; | ||
int g_IsMainKey; | ||
|
||
void startAsync() { | ||
std::lock_guard lk(g_AsyncCountMutex); | ||
++g_AsyncCount; | ||
} | ||
|
||
void endAsync() { | ||
std::lock_guard lk(g_AsyncCountMutex); | ||
if (--g_AsyncCount == 0) | ||
g_AsyncCountCond.notify_one(); | ||
|
||
} | ||
|
||
void waitForNoAsync() { | ||
std::unique_lock lk(g_AsyncCountMutex); | ||
g_AsyncCountCond.wait(lk, []{ return g_AsyncCount == 0; }); | ||
} | ||
|
||
bool isMainQueue() { | ||
return (intptr_t)dispatch_get_specific(&g_IsMainKey) == 1; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef HEADER_TEST_GLOBAL_H_INCLUDED | ||
#define HEADER_TEST_GLOBAL_H_INCLUDED | ||
|
||
void startAsync(); | ||
void endAsync(); | ||
void waitForNoAsync(); | ||
bool isMainQueue(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters