diff options
author | Pavel Labath <labath@google.com> | 2016-05-10 07:54:25 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2016-05-10 07:54:25 +0000 |
commit | ebc7135f8e529470c9745e8324d74f48f0fc3749 (patch) | |
tree | cf18e8340883179ea63f0dbd0361bd058cbab5b9 /lldb/packages/Python/lldbsuite/test/make/test_common.h | |
parent | bdb54eb4573f554854531cfebde54f102b618d68 (diff) | |
download | bcm5719-llvm-ebc7135f8e529470c9745e8324d74f48f0fc3749.tar.gz bcm5719-llvm-ebc7135f8e529470c9745e8324d74f48f0fc3749.zip |
Fix race in TestExitDuringStep and unify pseudo_barrier handling
Summary:
TestExitDuringStep was very rarely hanging on the buildbots. I can't be sure, but I believe this
was because of the fact that it declared its pseudo_barrier variable as "volatile int", which is
not sufficient to guarantee corectness (also, all other tests used atomic variables for this, and
they were passing reliably AFAIK). Besides switching to an atomic variable in this test as well,
I have also took this opportunity to unify all the copies of the pseudo_barrier code to a single
place to reduce the chance of this happening again.
Reviewers: clayborg
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D20065
llvm-svn: 269025
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/make/test_common.h')
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/make/test_common.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/make/test_common.h b/lldb/packages/Python/lldbsuite/test/make/test_common.h index a1ed364574e..a002f9fa9a4 100644 --- a/lldb/packages/Python/lldbsuite/test/make/test_common.h +++ b/lldb/packages/Python/lldbsuite/test/make/test_common.h @@ -42,3 +42,26 @@ #define lldb_enable_attach() #endif + +#ifdef __cplusplus +#include <atomic> + +// Note that although hogging the CPU while waiting for a variable to change +// would be terrible in production code, it's great for testing since it +// avoids a lot of messy context switching to get multiple threads synchronized. + +typedef std::atomic<int> pseudo_barrier_t; +#define pseudo_barrier_wait(barrier) \ + do \ + { \ + --(barrier); \ + while ((barrier).load() > 0) \ + ; \ + } while (0) + +#define pseudo_barrier_init(barrier, count) \ + do \ + { \ + (barrier) = (count); \ + } while (0) +#endif // __cplusplus |