-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc] Add pthread_detach and thrd_detach.
Tests for pthread_detach and thrd_detach have not been added. Instead, a test for the underlying implementation has been added as it makes use of an internal wait method to synchronize with detached threads. Reviewed By: lntue, michaelrj Differential Revision: https://reviews.llvm.org/D127479
- Loading branch information
Siva Chandra Reddy
committed
Jun 11, 2022
1 parent
e06faed
commit 5db4177
Showing
15 changed files
with
293 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//===-- Implementation of the pthread_detach 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 "pthread_detach.h" | ||
|
||
#include "src/__support/common.h" | ||
#include "src/__support/threads/thread.h" | ||
|
||
#include <pthread.h> // For pthread_* type definitions. | ||
|
||
namespace __llvm_libc { | ||
|
||
static_assert(sizeof(pthread_t) == sizeof(__llvm_libc::Thread<void *>), | ||
"Mismatch between pthread_t and internal Thread<void *>."); | ||
|
||
LLVM_LIBC_FUNCTION(int, pthread_detach, (pthread_t th)) { | ||
auto *thread = reinterpret_cast<Thread<void *> *>(&th); | ||
thread->detach(); | ||
return 0; | ||
} | ||
|
||
} // namespace __llvm_libc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//===-- Implementation header for pthread_detach 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_PTHREAD_DETACH_H | ||
#define LLVM_LIBC_SRC_THREADS_PTHREAD_DETACH_H | ||
|
||
#include <pthread.h> | ||
|
||
namespace __llvm_libc { | ||
|
||
int pthread_detach(pthread_t thread); | ||
|
||
} // namespace __llvm_libc | ||
|
||
#endif // LLVM_LIBC_SRC_THREADS_PTHREAD_DETACH_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//===-- Linux implementation of the thrd_detach 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/thrd_detach.h" | ||
#include "src/__support/common.h" | ||
#include "src/__support/threads/thread.h" | ||
|
||
#include <threads.h> // For thrd_* type definitions. | ||
|
||
namespace __llvm_libc { | ||
|
||
static_assert(sizeof(thrd_t) == sizeof(__llvm_libc::Thread<int>), | ||
"Mismatch between thrd_t and internal Thread<int>."); | ||
|
||
LLVM_LIBC_FUNCTION(int, thrd_detach, (thrd_t th)) { | ||
auto *thread = reinterpret_cast<Thread<int> *>(&th); | ||
thread->detach(); | ||
return 0; | ||
} | ||
|
||
} // namespace __llvm_libc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//===-- Implementation header for thrd_detach 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_THRD_DETACH_H | ||
#define LLVM_LIBC_SRC_THREADS_THRD_DETACH_H | ||
|
||
#include "include/threads.h" | ||
|
||
namespace __llvm_libc { | ||
|
||
int thrd_detach(thrd_t thread); | ||
|
||
} // namespace __llvm_libc | ||
|
||
#endif // LLVM_LIBC_SRC_THREADS_THRD_DETACH_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
if(NOT (TARGET libc.src.__support.threads.thread AND | ||
TARGET libc.src.__support.threads.mutex)) | ||
return() | ||
endif() | ||
|
||
add_libc_unittest( | ||
thread_detach_test | ||
SUITE | ||
SRCS | ||
thread_detach_test.cpp | ||
DEPENDS | ||
libc.src.__support.threads.mutex | ||
libc.src.__support.threads.thread | ||
libc.src.__support.threads.thread_attrib | ||
COMPILE_OPTIONS | ||
-O3 | ||
-fno-omit-frame-pointer | ||
) |
Oops, something went wrong.