Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1192)

Unified Diff: tests/unittests/shared/platform/atomic_ops_test.c

Issue 7602019: atomic_ops_test: Simplify by using joinable threads (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/unittests/shared/platform/atomic_ops_test.c
diff --git a/tests/unittests/shared/platform/atomic_ops_test.c b/tests/unittests/shared/platform/atomic_ops_test.c
index 4519576921ff21630ff94e4058aaa3fce9ccbeda..da4c3cc0d93d2d7b2734aaef1900125effbf7ca6 100644
--- a/tests/unittests/shared/platform/atomic_ops_test.c
+++ b/tests/unittests/shared/platform/atomic_ops_test.c
@@ -15,8 +15,6 @@ int32_t gIncrementsPerThread = 1000;
int32_t gNumThreads;
struct NaClMutex gMutex;
-struct NaClCondVar gFinishedCv;
-int32_t gFinishedCount = 0;
/* For atomic counter test */
@@ -90,14 +88,6 @@ void WINAPI ThreadMain(void *state) {
ExchangeTest(tid);
CompareAndSwapTest(tid);
-
- /* Signal that we're finished */
- NaClXMutexLock(&gMutex);
- gFinishedCount++;
- NaClXCondVarSignal(&gFinishedCv);
- NaClXMutexUnlock(&gMutex);
-
- NaClThreadExit(0);
}
int main(int argc, const char *argv[]) {
@@ -124,31 +114,27 @@ int main(int argc, const char *argv[]) {
exit(EXIT_FAILURE);
}
- if (!NaClCondVarCtor(&gFinishedCv)) {
- fprintf(stderr, "NaClCondVarCtor failed\n");
- exit(EXIT_FAILURE);
- }
NaClXMutexLock(&gMutex);
for (tid = 1; tid <= gNumThreads; ++tid) {
fprintf(stderr, "Creating thread %d\n", (int)tid);
- rv = NaClThreadCtor(&threads[tid-1],
- ThreadMain,
- (void*) (intptr_t) tid,
- THREAD_STACK_SIZE);
+ rv = NaClThreadCreateJoinable(&threads[tid-1],
+ ThreadMain,
+ (void*) (intptr_t) tid,
+ THREAD_STACK_SIZE);
if (!rv) {
fprintf(stderr, "NaClThreadCtor failed\n");
exit(EXIT_FAILURE);
}
}
- while (gFinishedCount != gNumThreads) {
- /* This releases the mutex, so the tests begin */
- NaClXCondVarWait(&gFinishedCv, &gMutex);
- }
NaClXMutexUnlock(&gMutex);
+ for (tid = 1; tid <= gNumThreads; ++tid) {
+ NaClThreadJoin(&threads[tid-1]);
+ }
+
/* Check the results */
tmp = gIncrementsPerThread * gNumThreads;
if (gCounter != tmp) {
@@ -172,7 +158,6 @@ int main(int argc, const char *argv[]) {
}
fprintf(stderr, "PASSED\n");
- NaClCondVarDtor(&gFinishedCv);
NaClMutexDtor(&gMutex);
free(threads);
return 0;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698