[libc-commits] [libc] b7afa92 - [libc] Call mtx_init in mtx_test.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Wed May 13 10:05:55 PDT 2020


Author: Siva Chandra Reddy
Date: 2020-05-13T09:48:31-07:00
New Revision: b7afa92e75ddea744c9bafbb2119b63ea564e122

URL: https://github.com/llvm/llvm-project/commit/b7afa92e75ddea744c9bafbb2119b63ea564e122
DIFF: https://github.com/llvm/llvm-project/commit/b7afa92e75ddea744c9bafbb2119b63ea564e122.diff

LOG: [libc] Call mtx_init in mtx_test.

A typo which was caught has also been fixed.

Reviewers: abrachet

Differential Revision: https://reviews.llvm.org/D79826

Added: 
    

Modified: 
    libc/src/threads/mtx_init.h
    libc/test/src/threads/mtx_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/threads/mtx_init.h b/libc/src/threads/mtx_init.h
index 0286ab15b236..d85089ff8c2e 100644
--- a/libc/src/threads/mtx_init.h
+++ b/libc/src/threads/mtx_init.h
@@ -13,7 +13,7 @@
 
 namespace __llvm_libc {
 
-int mtx_int(mtx_t *mutex, int type);
+int mtx_init(mtx_t *mutex, int type);
 
 } // namespace __llvm_libc
 

diff  --git a/libc/test/src/threads/mtx_test.cpp b/libc/test/src/threads/mtx_test.cpp
index 2015d4b06f85..fc03d8a8957d 100644
--- a/libc/test/src/threads/mtx_test.cpp
+++ b/libc/test/src/threads/mtx_test.cpp
@@ -36,6 +36,9 @@ int counter(void *arg) {
 }
 
 TEST(MutexTest, RelayCounter) {
+  ASSERT_EQ(__llvm_libc::mtx_init(&mutex, mtx_plain),
+            static_cast<int>(thrd_success));
+
   // The idea of this test is that two competing threads will update
   // a counter only if the other thread has updated it.
   thrd_t thread;
@@ -43,7 +46,7 @@ TEST(MutexTest, RelayCounter) {
 
   int last_count = START;
   while (true) {
-    ASSERT_EQ(__llvm_libc::mtx_lock(&mutex), (int)thrd_success);
+    ASSERT_EQ(__llvm_libc::mtx_lock(&mutex), static_cast<int>(thrd_success));
     if (shared_int == START) {
       ++shared_int;
       last_count = shared_int;
@@ -52,7 +55,7 @@ TEST(MutexTest, RelayCounter) {
       ++shared_int;
       last_count = shared_int;
     }
-    ASSERT_EQ(__llvm_libc::mtx_unlock(&mutex), (int)thrd_success);
+    ASSERT_EQ(__llvm_libc::mtx_unlock(&mutex), static_cast<int>(thrd_success));
     if (last_count > MAX)
       break;
   }
@@ -77,21 +80,28 @@ int stepper(void *arg) {
 }
 
 TEST(MutexTest, WaitAndStep) {
+  ASSERT_EQ(__llvm_libc::mtx_init(&start_lock, mtx_plain),
+            static_cast<int>(thrd_success));
+  ASSERT_EQ(__llvm_libc::mtx_init(&step_lock, mtx_plain),
+            static_cast<int>(thrd_success));
+
   // In this test, we start a new thread but block it before it can make a
   // step. Once we ensure that the thread is blocked, we unblock it.
   // After unblocking, we then verify that the thread was indeed unblocked.
   step = false;
   start = false;
-  ASSERT_EQ(__llvm_libc::mtx_lock(&step_lock), (int)thrd_success);
+  ASSERT_EQ(__llvm_libc::mtx_lock(&step_lock), static_cast<int>(thrd_success));
 
   thrd_t thread;
   __llvm_libc::thrd_create(&thread, stepper, nullptr);
 
   while (true) {
     // Make sure the thread actually started.
-    ASSERT_EQ(__llvm_libc::mtx_lock(&start_lock), (int)thrd_success);
+    ASSERT_EQ(__llvm_libc::mtx_lock(&start_lock),
+              static_cast<int>(thrd_success));
     bool s = start;
-    ASSERT_EQ(__llvm_libc::mtx_unlock(&start_lock), (int)thrd_success);
+    ASSERT_EQ(__llvm_libc::mtx_unlock(&start_lock),
+              static_cast<int>(thrd_success));
     if (s)
       break;
   }
@@ -100,12 +110,15 @@ TEST(MutexTest, WaitAndStep) {
   ASSERT_FALSE(step);
 
   // Unlock the step lock and wait until the step is made.
-  ASSERT_EQ(__llvm_libc::mtx_unlock(&step_lock), (int)thrd_success);
+  ASSERT_EQ(__llvm_libc::mtx_unlock(&step_lock),
+            static_cast<int>(thrd_success));
 
   while (true) {
-    ASSERT_EQ(__llvm_libc::mtx_lock(&step_lock), (int)thrd_success);
+    ASSERT_EQ(__llvm_libc::mtx_lock(&step_lock),
+              static_cast<int>(thrd_success));
     bool current_step_value = step;
-    ASSERT_EQ(__llvm_libc::mtx_unlock(&step_lock), (int)thrd_success);
+    ASSERT_EQ(__llvm_libc::mtx_unlock(&step_lock),
+              static_cast<int>(thrd_success));
     if (current_step_value)
       break;
   }


        


More information about the libc-commits mailing list