[libc-commits] [libc] 57afb48 - [libc][Obvious] Fix thrd_join's first arg.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Thu Aug 11 12:23:29 PDT 2022


Author: Siva Chandra Reddy
Date: 2022-08-11T19:18:11Z
New Revision: 57afb48057433cdd9f420efe208329a64adea352

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

LOG: [libc][Obvious] Fix thrd_join's first arg.

First argument to thrd_join was incorrectly listed as a pointer
to a thrd_t value. It should instead be a thrd_t value argument.

Added: 
    

Modified: 
    libc/spec/stdc.td
    libc/src/threads/thrd_join.cpp
    libc/src/threads/thrd_join.h
    libc/test/integration/src/threads/call_once_test.cpp
    libc/test/integration/src/threads/cnd_test.cpp
    libc/test/integration/src/threads/mtx_test.cpp
    libc/test/integration/src/threads/thrd_equal_test.cpp
    libc/test/integration/src/threads/thrd_exit_test.cpp
    libc/test/integration/src/threads/thrd_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index beabc1bc72184..4e7da2b67d9af 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -806,7 +806,7 @@ def StdC : StandardSpec<"stdc"> {
               "thrd_join",
               RetValSpec<IntType>,
               [
-                  ArgSpec<ThrdTTypePtr>,
+                  ArgSpec<ThrdTType>,
                   ArgSpec<IntPtr>,
               ]
           >,

diff  --git a/libc/src/threads/thrd_join.cpp b/libc/src/threads/thrd_join.cpp
index 4c3ecac34a4e9..e4cf5522db92f 100644
--- a/libc/src/threads/thrd_join.cpp
+++ b/libc/src/threads/thrd_join.cpp
@@ -17,8 +17,8 @@ namespace __llvm_libc {
 static_assert(sizeof(thrd_t) == sizeof(__llvm_libc::Thread),
               "Mismatch between thrd_t and internal Thread.");
 
-LLVM_LIBC_FUNCTION(int, thrd_join, (thrd_t * th, int *retval)) {
-  auto *thread = reinterpret_cast<Thread *>(th);
+LLVM_LIBC_FUNCTION(int, thrd_join, (thrd_t th, int *retval)) {
+  auto *thread = reinterpret_cast<Thread *>(&th);
   int result = thread->join(retval);
   return result == 0 ? thrd_success : thrd_error;
 }

diff  --git a/libc/src/threads/thrd_join.h b/libc/src/threads/thrd_join.h
index fc36503dc521c..248bced10263a 100644
--- a/libc/src/threads/thrd_join.h
+++ b/libc/src/threads/thrd_join.h
@@ -13,7 +13,7 @@
 
 namespace __llvm_libc {
 
-int thrd_join(thrd_t *thread, int *retval);
+int thrd_join(thrd_t thread, int *retval);
 
 } // namespace __llvm_libc
 

diff  --git a/libc/test/integration/src/threads/call_once_test.cpp b/libc/test/integration/src/threads/call_once_test.cpp
index 1de8a621779a2..dcb3f2507ca16 100644
--- a/libc/test/integration/src/threads/call_once_test.cpp
+++ b/libc/test/integration/src/threads/call_once_test.cpp
@@ -47,7 +47,7 @@ void call_from_5_threads() {
 
   for (unsigned int i = 0; i < NUM_THREADS; ++i) {
     int retval;
-    ASSERT_EQ(__llvm_libc::thrd_join(threads + i, &retval),
+    ASSERT_EQ(__llvm_libc::thrd_join(threads[i], &retval),
               static_cast<int>(thrd_success));
     ASSERT_EQ(retval, 0);
   }
@@ -102,10 +102,10 @@ void test_synchronization() {
             static_cast<int>(thrd_success));
 
   int retval;
-  ASSERT_EQ(__llvm_libc::thrd_join(&t1, &retval),
+  ASSERT_EQ(__llvm_libc::thrd_join(t1, &retval),
             static_cast<int>(thrd_success));
   ASSERT_EQ(retval, 0);
-  ASSERT_EQ(__llvm_libc::thrd_join(&t2, &retval),
+  ASSERT_EQ(__llvm_libc::thrd_join(t2, &retval),
             static_cast<int>(thrd_success));
   ASSERT_EQ(retval, 0);
 

diff  --git a/libc/test/integration/src/threads/cnd_test.cpp b/libc/test/integration/src/threads/cnd_test.cpp
index 3690a979fe759..c833fcb1775c1 100644
--- a/libc/test/integration/src/threads/cnd_test.cpp
+++ b/libc/test/integration/src/threads/cnd_test.cpp
@@ -77,7 +77,7 @@ void wait_notify_broadcast_test() {
 
   for (unsigned int i = 0; i < THRD_COUNT; ++i) {
     int retval = 0xBAD;
-    __llvm_libc::thrd_join(&threads[i], &retval);
+    __llvm_libc::thrd_join(threads[i], &retval);
     ASSERT_EQ(retval, 0);
   }
 
@@ -134,7 +134,7 @@ void single_waiter_test() {
   ASSERT_EQ(__llvm_libc::mtx_unlock(&waiter_mtx), int(thrd_success));
 
   int retval;
-  __llvm_libc::thrd_join(&waiter_thread, &retval);
+  __llvm_libc::thrd_join(waiter_thread, &retval);
   ASSERT_EQ(retval, 0x600D);
 
   __llvm_libc::mtx_destroy(&waiter_mtx);

diff  --git a/libc/test/integration/src/threads/mtx_test.cpp b/libc/test/integration/src/threads/mtx_test.cpp
index 34e060a4a0d55..cb955c97008e7 100644
--- a/libc/test/integration/src/threads/mtx_test.cpp
+++ b/libc/test/integration/src/threads/mtx_test.cpp
@@ -64,7 +64,7 @@ void relay_counter() {
   }
 
   int retval = 123;
-  __llvm_libc::thrd_join(&thread, &retval);
+  __llvm_libc::thrd_join(thread, &retval);
   ASSERT_EQ(retval, 0);
 
   __llvm_libc::mtx_destroy(&mutex);
@@ -129,7 +129,7 @@ void wait_and_step() {
   }
 
   int retval = 123;
-  __llvm_libc::thrd_join(&thread, &retval);
+  __llvm_libc::thrd_join(thread, &retval);
   ASSERT_EQ(retval, 0);
 
   __llvm_libc::mtx_destroy(&start_lock);
@@ -183,7 +183,7 @@ void multiple_waiters() {
 
   int retval;
   for (int i = 0; i < THREAD_COUNT; ++i) {
-    __llvm_libc::thrd_join(waiters + i, &retval);
+    __llvm_libc::thrd_join(waiters[i], &retval);
   }
 
   ASSERT_EQ(wait_count, 0);

diff  --git a/libc/test/integration/src/threads/thrd_equal_test.cpp b/libc/test/integration/src/threads/thrd_equal_test.cpp
index e743836fd7877..24c5240718be9 100644
--- a/libc/test/integration/src/threads/thrd_equal_test.cpp
+++ b/libc/test/integration/src/threads/thrd_equal_test.cpp
@@ -57,7 +57,7 @@ TEST_MAIN() {
   ASSERT_EQ(__llvm_libc::mtx_unlock(&mutex), int(thrd_success));
 
   int retval;
-  ASSERT_EQ(__llvm_libc::thrd_join(&th, &retval), int(thrd_success));
+  ASSERT_EQ(__llvm_libc::thrd_join(th, &retval), int(thrd_success));
   ASSERT_EQ(retval, 0);
   // The child thread should see that thrd_current return value is the same as
   // |child_thread|.

diff  --git a/libc/test/integration/src/threads/thrd_exit_test.cpp b/libc/test/integration/src/threads/thrd_exit_test.cpp
index d5f7259b2e17a..b331717849693 100644
--- a/libc/test/integration/src/threads/thrd_exit_test.cpp
+++ b/libc/test/integration/src/threads/thrd_exit_test.cpp
@@ -42,7 +42,7 @@ TEST_MAIN() {
   int retval;
 
   ASSERT_EQ(__llvm_libc::thrd_create(&th, func, nullptr), thrd_success);
-  ASSERT_EQ(__llvm_libc::thrd_join(&th, &retval), thrd_success);
+  ASSERT_EQ(__llvm_libc::thrd_join(th, &retval), thrd_success);
 
   ASSERT_TRUE(dtor_called);
   __llvm_libc::thrd_exit(0);

diff  --git a/libc/test/integration/src/threads/thrd_test.cpp b/libc/test/integration/src/threads/thrd_test.cpp
index 63ddb1798a6a5..d71d61ce44cec 100644
--- a/libc/test/integration/src/threads/thrd_test.cpp
+++ b/libc/test/integration/src/threads/thrd_test.cpp
@@ -27,7 +27,7 @@ void create_and_join() {
     ASSERT_EQ(__llvm_libc::thrd_create(&thread, thread_func, nullptr),
               (int)thrd_success);
     int retval = thread_count + 1; // Start with a retval we dont expect.
-    ASSERT_EQ(__llvm_libc::thrd_join(&thread, &retval), (int)thrd_success);
+    ASSERT_EQ(__llvm_libc::thrd_join(thread, &retval), (int)thrd_success);
     ASSERT_EQ(retval, 0);
     ASSERT_EQ(counter, old_counter_val + 1);
   }
@@ -47,7 +47,7 @@ void spawn_and_join() {
 
   for (int i = 0; i < thread_count; ++i) {
     int retval = thread_count + 1; // Start with a retval we dont expect.
-    ASSERT_EQ(__llvm_libc::thrd_join(&thread_list[i], &retval),
+    ASSERT_EQ(__llvm_libc::thrd_join(thread_list[i], &retval),
               (int)thrd_success);
     ASSERT_EQ(retval, i);
   }


        


More information about the libc-commits mailing list