[libc-commits] [libc] 2f4f452 - [libc] Add a skeleton for C standard condition variable functions.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Wed Sep 1 12:42:09 PDT 2021


Author: Siva Chandra Reddy
Date: 2021-09-01T19:41:52Z
New Revision: 2f4f452f166bbbf0d39193f0e68d680d235e64ba

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

LOG: [libc] Add a skeleton for C standard condition variable functions.

This patch adds a skeleton as a preparatory step for the next patch which
adds the actual implementations of the condition variable functions.

Reviewed By: michaelrj

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

Added: 
    libc/src/threads/cnd_broadcast.h
    libc/src/threads/cnd_destroy.h
    libc/src/threads/cnd_init.h
    libc/src/threads/cnd_signal.h
    libc/src/threads/cnd_wait.h
    libc/src/threads/linux/cnd_broadcast.cpp
    libc/src/threads/linux/cnd_destroy.cpp
    libc/src/threads/linux/cnd_init.cpp
    libc/src/threads/linux/cnd_signal.cpp
    libc/src/threads/linux/cnd_wait.cpp

Modified: 
    libc/config/linux/api.td
    libc/config/linux/x86_64/entrypoints.txt
    libc/spec/spec.td
    libc/spec/stdc.td
    libc/src/threads/CMakeLists.txt
    libc/src/threads/linux/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/api.td b/libc/config/linux/api.td
index c68888ab3c700..ddcf9018f66db 100644
--- a/libc/config/linux/api.td
+++ b/libc/config/linux/api.td
@@ -344,6 +344,19 @@ def MtxT : TypeDecl<"mtx_t"> {
   }];
 }
 
+def CndT : TypeDecl<"cnd_t"> {
+  let Decl = [{
+    typedef struct {
+      void *__qfront;
+      void *__qback;
+      struct {
+        unsigned char __w[4];
+        int __t;
+      } __qmtx;
+    } cnd_t;
+  }];
+}
+
 def ThreadStartT : TypeDecl<"thrd_start_t"> {
   let Decl = "typedef int (*thrd_start_t)(void *);";
 }
@@ -363,6 +376,7 @@ def ThreadsAPI : PublicAPI<"threads.h"> {
     OnceFlag,
     CallOnceFuncT,
     MtxT,
+    CndT,
     ThreadStartT,
   ];
 

diff  --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index a4b8383b8eb35..59c5f5100f691 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -189,6 +189,11 @@ if(LLVM_LIBC_FULL_BUILD)
 
     # threads.h entrypoints
     libc.src.threads.call_once
+    libc.src.threads.cnd_broadcast
+    libc.src.threads.cnd_destroy
+    libc.src.threads.cnd_init
+    libc.src.threads.cnd_signal
+    libc.src.threads.cnd_wait
     libc.src.threads.mtx_destroy
     libc.src.threads.mtx_init
     libc.src.threads.mtx_lock

diff  --git a/libc/spec/spec.td b/libc/spec/spec.td
index 55f75f28df3ac..9bb2925e84651 100644
--- a/libc/spec/spec.td
+++ b/libc/spec/spec.td
@@ -77,6 +77,8 @@ def OnceFlagTypePtr : PtrType<OnceFlagType>;
 def CallOnceFuncType : NamedType<"__call_once_func_t">;
 def MtxTType : NamedType<"mtx_t">;
 def MtxTTypePtr : PtrType<MtxTType>;
+def CndTType : NamedType<"cnd_t">;
+def CndTTypePtr : PtrType<CndTType>;
 def ThrdStartTType : NamedType<"thrd_start_t">;
 def ThrdTType : NamedType<"thrd_t">;
 def ThrdTTypePtr : PtrType<ThrdTType>;

diff  --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 08ceea7e952a0..c50f9175fb697 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -549,6 +549,7 @@ def StdC : StandardSpec<"stdc"> {
       [
           OnceFlagType,
           CallOnceFuncType,
+          CndTType,
           MtxTType,
           ThrdStartTType,
           ThrdTType,
@@ -572,6 +573,42 @@ def StdC : StandardSpec<"stdc"> {
                   ArgSpec<CallOnceFuncType>,
               ]
           >,
+          FunctionSpec<
+              "cnd_broadcast",
+              RetValSpec<IntType>,
+              [
+                  ArgSpec<CndTTypePtr>,
+              ]
+          >,
+          FunctionSpec<
+              "cnd_destroy",
+              RetValSpec<VoidType>,
+              [
+                  ArgSpec<CndTTypePtr>,
+              ]
+          >,
+          FunctionSpec<
+              "cnd_init",
+              RetValSpec<IntType>,
+              [
+                  ArgSpec<CndTTypePtr>,
+              ]
+          >,
+          FunctionSpec<
+              "cnd_signal",
+              RetValSpec<IntType>,
+              [
+                  ArgSpec<CndTTypePtr>,
+              ]
+          >,
+          FunctionSpec<
+              "cnd_wait",
+              RetValSpec<IntType>,
+              [
+                  ArgSpec<CndTTypePtr>,
+                  ArgSpec<MtxTTypePtr>,
+              ]
+          >,
           FunctionSpec<
               "mtx_init",
               RetValSpec<IntType>,

diff  --git a/libc/src/threads/CMakeLists.txt b/libc/src/threads/CMakeLists.txt
index a5d9589e44f33..de72701bef759 100644
--- a/libc/src/threads/CMakeLists.txt
+++ b/libc/src/threads/CMakeLists.txt
@@ -50,3 +50,38 @@ add_entrypoint_object(
   DEPENDS
     .${LIBC_TARGET_OS}.mtx_unlock
 )
+
+add_entrypoint_object(
+  cnd_init
+  ALIAS
+  DEPENDS
+    .${LIBC_TARGET_OS}.cnd_init
+)
+
+add_entrypoint_object(
+  cnd_destroy
+  ALIAS
+  DEPENDS
+    .${LIBC_TARGET_OS}.cnd_destroy
+)
+
+add_entrypoint_object(
+  cnd_wait
+  ALIAS
+  DEPENDS
+    .${LIBC_TARGET_OS}.cnd_wait
+)
+
+add_entrypoint_object(
+  cnd_signal
+  ALIAS
+  DEPENDS
+    .${LIBC_TARGET_OS}.cnd_signal
+)
+
+add_entrypoint_object(
+  cnd_broadcast
+  ALIAS
+  DEPENDS
+    .${LIBC_TARGET_OS}.cnd_broadcast
+)

diff  --git a/libc/src/threads/cnd_broadcast.h b/libc/src/threads/cnd_broadcast.h
new file mode 100644
index 0000000000000..219341bc44981
--- /dev/null
+++ b/libc/src/threads/cnd_broadcast.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for cnd_broadcast 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_CND_BROADCAST_H
+#define LLVM_LIBC_SRC_THREADS_CND_BROADCAST_H
+
+#include "include/threads.h"
+
+namespace __llvm_libc {
+
+int cnd_broadcast(cnd_t *cond);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_THREADS_CND_BROADCAST_H

diff  --git a/libc/src/threads/cnd_destroy.h b/libc/src/threads/cnd_destroy.h
new file mode 100644
index 0000000000000..4fa1ea18b5e29
--- /dev/null
+++ b/libc/src/threads/cnd_destroy.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for cnd_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_CND_DESTROY_H
+#define LLVM_LIBC_SRC_THREADS_CND_DESTROY_H
+
+#include "include/threads.h"
+
+namespace __llvm_libc {
+
+void cnd_destroy(cnd_t *cond);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_THREADS_CND_DESTROY_H

diff  --git a/libc/src/threads/cnd_init.h b/libc/src/threads/cnd_init.h
new file mode 100644
index 0000000000000..8c14c88342e37
--- /dev/null
+++ b/libc/src/threads/cnd_init.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for cnd_init 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_CND_INIT_H
+#define LLVM_LIBC_SRC_THREADS_CND_INIT_H
+
+#include "include/threads.h"
+
+namespace __llvm_libc {
+
+int cnd_init(cnd_t *cond);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_THREADS_CND_INIT_H

diff  --git a/libc/src/threads/cnd_signal.h b/libc/src/threads/cnd_signal.h
new file mode 100644
index 0000000000000..d85802dda4845
--- /dev/null
+++ b/libc/src/threads/cnd_signal.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for cnd_signal 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_CND_SIGNAL_H
+#define LLVM_LIBC_SRC_THREADS_CND_SIGNAL_H
+
+#include "include/threads.h"
+
+namespace __llvm_libc {
+
+int cnd_signal(cnd_t *cond);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_THREADS_CND_SIGNAL_H

diff  --git a/libc/src/threads/cnd_wait.h b/libc/src/threads/cnd_wait.h
new file mode 100644
index 0000000000000..5f9ac08846767
--- /dev/null
+++ b/libc/src/threads/cnd_wait.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for cnd_wait 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_CND_WAIT_H
+#define LLVM_LIBC_SRC_THREADS_CND_WAIT_H
+
+#include "include/threads.h"
+
+namespace __llvm_libc {
+
+int cnd_wait(cnd_t *cond, mtx_t *mutex);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_THREADS_CND_WAIT_H

diff  --git a/libc/src/threads/linux/CMakeLists.txt b/libc/src/threads/linux/CMakeLists.txt
index b28850b94d8f2..abf38fabb8aeb 100644
--- a/libc/src/threads/linux/CMakeLists.txt
+++ b/libc/src/threads/linux/CMakeLists.txt
@@ -113,3 +113,58 @@ add_entrypoint_object(
     .threads_utils
     libc.include.threads
 )
+
+add_entrypoint_object(
+  cnd_init
+  SRCS
+    cnd_init.cpp
+  HDRS
+    ../cnd_init.h
+  DEPENDS
+    .threads_utils
+    libc.include.threads
+)
+
+add_entrypoint_object(
+  cnd_destroy
+  SRCS
+    cnd_destroy.cpp
+  HDRS
+    ../cnd_destroy.h
+  DEPENDS
+    .threads_utils
+    libc.include.threads
+)
+
+add_entrypoint_object(
+  cnd_wait
+  SRCS
+    cnd_wait.cpp
+  HDRS
+    ../cnd_wait.h
+  DEPENDS
+    .threads_utils
+    libc.include.threads
+)
+
+add_entrypoint_object(
+  cnd_signal
+  SRCS
+    cnd_signal.cpp
+  HDRS
+    ../cnd_signal.h
+  DEPENDS
+    .threads_utils
+    libc.include.threads
+)
+
+add_entrypoint_object(
+  cnd_broadcast
+  SRCS
+    cnd_broadcast.cpp
+  HDRS
+    ../cnd_broadcast.h
+  DEPENDS
+    .threads_utils
+    libc.include.threads
+)

diff  --git a/libc/src/threads/linux/cnd_broadcast.cpp b/libc/src/threads/linux/cnd_broadcast.cpp
new file mode 100644
index 0000000000000..e10f9fa6c228c
--- /dev/null
+++ b/libc/src/threads/linux/cnd_broadcast.cpp
@@ -0,0 +1,16 @@
+//===-- Linux implementation of the cnd_broadcast 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/cnd_broadcast.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(int, cnd_broadcast, (cnd_t * cond)) { return thrd_success; }
+
+} // namespace __llvm_libc

diff  --git a/libc/src/threads/linux/cnd_destroy.cpp b/libc/src/threads/linux/cnd_destroy.cpp
new file mode 100644
index 0000000000000..ac8a852a97394
--- /dev/null
+++ b/libc/src/threads/linux/cnd_destroy.cpp
@@ -0,0 +1,16 @@
+//===-- Linux implementation of the cnd_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/cnd_destroy.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(void, cnd_destroy, (cnd_t * cond)) { }
+
+} // namespace __llvm_libc

diff  --git a/libc/src/threads/linux/cnd_init.cpp b/libc/src/threads/linux/cnd_init.cpp
new file mode 100644
index 0000000000000..f034695227b7e
--- /dev/null
+++ b/libc/src/threads/linux/cnd_init.cpp
@@ -0,0 +1,16 @@
+//===-- Linux implementation of the cnd_init 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/cnd_init.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(int, cnd_init, (cnd_t * cond)) { return thrd_success; }
+
+} // namespace __llvm_libc

diff  --git a/libc/src/threads/linux/cnd_signal.cpp b/libc/src/threads/linux/cnd_signal.cpp
new file mode 100644
index 0000000000000..8ef16a355e7b0
--- /dev/null
+++ b/libc/src/threads/linux/cnd_signal.cpp
@@ -0,0 +1,16 @@
+//===-- Linux implementation of the cnd_signal 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/cnd_signal.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(int, cnd_signal, (cnd_t * cond)) { return thrd_success; }
+
+} // namespace __llvm_libc

diff  --git a/libc/src/threads/linux/cnd_wait.cpp b/libc/src/threads/linux/cnd_wait.cpp
new file mode 100644
index 0000000000000..e2dda46d2dc9c
--- /dev/null
+++ b/libc/src/threads/linux/cnd_wait.cpp
@@ -0,0 +1,18 @@
+//===-- Linux implementation of the cnd_wait 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/cnd_wait.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(int, cnd_wait, (cnd_t * cond, mtx_t *mutex)) {
+  return thrd_success;
+}
+
+} // namespace __llvm_libc


        


More information about the libc-commits mailing list