[libc-commits] [libc] 7a2a765 - [libc] Add mtx_destroy which does nothing.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Mon Aug 30 13:48:26 PDT 2021


Author: Siva Chandra Reddy
Date: 2021-08-30T20:43:46Z
New Revision: 7a2a765745973ebeb041276d2d9489a000ba9371

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

LOG: [libc] Add mtx_destroy which does nothing.

There is not cleanup to be done for the mutex type so mtx_destroy does
nothing.

Added: 
    libc/src/threads/linux/mtx_destroy.cpp
    libc/src/threads/mtx_destroy.h

Modified: 
    libc/config/linux/x86_64/entrypoints.txt
    libc/spec/stdc.td
    libc/src/threads/CMakeLists.txt
    libc/src/threads/linux/CMakeLists.txt
    libc/test/src/threads/CMakeLists.txt
    libc/test/src/threads/call_once_test.cpp
    libc/test/src/threads/mtx_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 3a15068682aa7..a4b8383b8eb35 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -189,6 +189,7 @@ if(LLVM_LIBC_FULL_BUILD)
 
     # threads.h entrypoints
     libc.src.threads.call_once
+    libc.src.threads.mtx_destroy
     libc.src.threads.mtx_init
     libc.src.threads.mtx_lock
     libc.src.threads.mtx_unlock

diff  --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index da169a53c2773..08ceea7e952a0 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -580,6 +580,13 @@ def StdC : StandardSpec<"stdc"> {
                   ArgSpec<IntType>,
               ]
           >,
+          FunctionSpec<
+              "mtx_destroy",
+              RetValSpec<IntType>,
+              [
+                  ArgSpec<VoidType>,
+              ]
+          >,
           FunctionSpec<
               "mtx_lock",
               RetValSpec<IntType>,

diff  --git a/libc/src/threads/CMakeLists.txt b/libc/src/threads/CMakeLists.txt
index 276aa51cfbd51..a5d9589e44f33 100644
--- a/libc/src/threads/CMakeLists.txt
+++ b/libc/src/threads/CMakeLists.txt
@@ -30,6 +30,13 @@ add_entrypoint_object(
     .${LIBC_TARGET_OS}.mtx_init
 )
 
+add_entrypoint_object(
+  mtx_destroy
+  ALIAS
+  DEPENDS
+    .${LIBC_TARGET_OS}.mtx_destroy
+)
+
 add_entrypoint_object(
   mtx_lock
   ALIAS

diff  --git a/libc/src/threads/linux/CMakeLists.txt b/libc/src/threads/linux/CMakeLists.txt
index 730314cefe521..b28850b94d8f2 100644
--- a/libc/src/threads/linux/CMakeLists.txt
+++ b/libc/src/threads/linux/CMakeLists.txt
@@ -81,6 +81,17 @@ add_entrypoint_object(
     libc.include.threads
 )
 
+add_entrypoint_object(
+  mtx_destroy
+  SRCS
+    mtx_destroy.cpp
+  HDRS
+    ../mtx_destroy.h
+  DEPENDS
+    .threads_utils
+    libc.include.threads
+)
+
 add_entrypoint_object(
   mtx_lock
   SRCS

diff  --git a/libc/src/threads/linux/mtx_destroy.cpp b/libc/src/threads/linux/mtx_destroy.cpp
new file mode 100644
index 0000000000000..a64cfde4835bc
--- /dev/null
+++ b/libc/src/threads/linux/mtx_destroy.cpp
@@ -0,0 +1,18 @@
+//===-- Linux implementation of the mtx_destroy function ------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/threads/mtx_destroy.h"
+#include "include/threads.h" // For mtx_t definition.
+#include "src/__support/common.h"
+#include "src/threads/linux/Mutex.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(void, mtx_destroy, (mtx_t * mutex)) {}
+
+} // namespace __llvm_libc

diff  --git a/libc/src/threads/mtx_destroy.h b/libc/src/threads/mtx_destroy.h
new file mode 100644
index 0000000000000..c123b814789fb
--- /dev/null
+++ b/libc/src/threads/mtx_destroy.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for mtx_destroy function ----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_THREADS_MTX_DESTROY_H
+#define LLVM_LIBC_SRC_THREADS_MTX_DESTROY_H
+
+#include "include/threads.h"
+
+namespace __llvm_libc {
+
+void mtx_destroy(mtx_t *mutex);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_THREADS_MTX_DESTROY_H

diff  --git a/libc/test/src/threads/CMakeLists.txt b/libc/test/src/threads/CMakeLists.txt
index 246401d1ce7f8..52d0e0d08a1a1 100644
--- a/libc/test/src/threads/CMakeLists.txt
+++ b/libc/test/src/threads/CMakeLists.txt
@@ -9,6 +9,7 @@ add_libc_unittest(
   DEPENDS
     libc.include.threads
     libc.src.threads.call_once
+    libc.src.threads.mtx_destroy
     libc.src.threads.mtx_init
     libc.src.threads.mtx_lock
     libc.src.threads.mtx_unlock
@@ -39,6 +40,7 @@ add_libc_unittest(
   DEPENDS
     libc.include.threads
     libc.src.errno.__errno_location
+    libc.src.threads.mtx_destroy
     libc.src.threads.mtx_init
     libc.src.threads.mtx_lock
     libc.src.threads.mtx_unlock

diff  --git a/libc/test/src/threads/call_once_test.cpp b/libc/test/src/threads/call_once_test.cpp
index 569c912378f29..18ed710157634 100644
--- a/libc/test/src/threads/call_once_test.cpp
+++ b/libc/test/src/threads/call_once_test.cpp
@@ -8,6 +8,7 @@
 
 #include "include/threads.h"
 #include "src/threads/call_once.h"
+#include "src/threads/mtx_destroy.h"
 #include "src/threads/mtx_init.h"
 #include "src/threads/mtx_lock.h"
 #include "src/threads/mtx_unlock.h"
@@ -108,4 +109,6 @@ TEST(LlvmLibcCallOnceTest, TestSynchronization) {
   ASSERT_EQ(retval, 0);
 
   ASSERT_EQ(static_cast<unsigned int>(done_count), 2U);
+
+  __llvm_libc::mtx_destroy(&once_func_blocker);
 }

diff  --git a/libc/test/src/threads/mtx_test.cpp b/libc/test/src/threads/mtx_test.cpp
index 536ff520c6018..8ee8cf5bb0dd7 100644
--- a/libc/test/src/threads/mtx_test.cpp
+++ b/libc/test/src/threads/mtx_test.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "include/threads.h"
+#include "src/threads/mtx_destroy.h"
 #include "src/threads/mtx_init.h"
 #include "src/threads/mtx_lock.h"
 #include "src/threads/mtx_unlock.h"
@@ -63,6 +64,8 @@ TEST(LlvmLibcMutexTest, RelayCounter) {
   int retval = 123;
   __llvm_libc::thrd_join(&thread, &retval);
   ASSERT_EQ(retval, 0);
+
+  __llvm_libc::mtx_destroy(&mutex);
 }
 
 mtx_t start_lock, step_lock;
@@ -126,6 +129,9 @@ TEST(LlvmLibcMutexTest, WaitAndStep) {
   int retval = 123;
   __llvm_libc::thrd_join(&thread, &retval);
   ASSERT_EQ(retval, 0);
+
+  __llvm_libc::mtx_destroy(&start_lock);
+  __llvm_libc::mtx_destroy(&step_lock);
 }
 
 static constexpr int THREAD_COUNT = 10;
@@ -179,4 +185,7 @@ TEST(LlvmLibcMutexTest, MultipleWaiters) {
   }
 
   ASSERT_EQ(wait_count, 0);
+
+  __llvm_libc::mtx_destroy(&multiple_waiter_lock);
+  __llvm_libc::mtx_destroy(&counter_lock);
 }


        


More information about the libc-commits mailing list