[libc][POSIX][pthreads] implement pthread_condattr_t functions (#88987)
Implement: - pthread_condattr_destroy - pthread_condattr_getclock - pthread_condattr_getpshared - pthread_condattr_init - pthread_condattr_setclock - pthread_condattr_setpshared Fixes: #88581
This commit is contained in:
parent
19c6a7feca
commit
06947b9f8d
@ -175,6 +175,7 @@ def PThreadAPI : PublicAPI<"pthread.h"> {
|
||||
"__pthread_start_t",
|
||||
"__pthread_tss_dtor_t",
|
||||
"pthread_attr_t",
|
||||
"pthread_condattr_t",
|
||||
"pthread_mutex_t",
|
||||
"pthread_mutexattr_t",
|
||||
"pthread_t",
|
||||
@ -241,10 +242,30 @@ def SysSendfileAPI : PublicAPI<"sys/sendfile.h"> {
|
||||
}
|
||||
|
||||
def SysTypesAPI : PublicAPI<"sys/types.h"> {
|
||||
let Types = ["blkcnt_t", "blksize_t", "clockid_t", "dev_t", "gid_t", "ino_t",
|
||||
"mode_t", "nlink_t", "off_t", "pid_t", "pthread_attr_t", "pthread_key_t",
|
||||
"pthread_mutex_t", "pthread_mutexattr_t", "pthread_once_t", "pthread_t",
|
||||
"size_t", "ssize_t", "suseconds_t", "time_t", "uid_t"];
|
||||
let Types = [
|
||||
"blkcnt_t",
|
||||
"blksize_t",
|
||||
"clockid_t",
|
||||
"dev_t",
|
||||
"gid_t",
|
||||
"ino_t",
|
||||
"mode_t",
|
||||
"nlink_t",
|
||||
"off_t",
|
||||
"pid_t",
|
||||
"pthread_attr_t",
|
||||
"pthread_condattr_t",
|
||||
"pthread_key_t",
|
||||
"pthread_mutex_t",
|
||||
"pthread_mutexattr_t",
|
||||
"pthread_once_t",
|
||||
"pthread_t",
|
||||
"size_t",
|
||||
"ssize_t",
|
||||
"suseconds_t",
|
||||
"time_t",
|
||||
"uid_t"
|
||||
];
|
||||
}
|
||||
|
||||
def SysUtsNameAPI : PublicAPI<"sys/utsname.h"> {
|
||||
|
@ -639,6 +639,12 @@ if(LLVM_LIBC_FULL_BUILD)
|
||||
libc.src.pthread.pthread_attr_setguardsize
|
||||
libc.src.pthread.pthread_attr_setstack
|
||||
libc.src.pthread.pthread_attr_setstacksize
|
||||
libc.src.pthread.pthread_condattr_destroy
|
||||
libc.src.pthread.pthread_condattr_getclock
|
||||
libc.src.pthread.pthread_condattr_getpshared
|
||||
libc.src.pthread.pthread_condattr_init
|
||||
libc.src.pthread.pthread_condattr_setclock
|
||||
libc.src.pthread.pthread_condattr_setpshared
|
||||
libc.src.pthread.pthread_create
|
||||
libc.src.pthread.pthread_detach
|
||||
libc.src.pthread.pthread_equal
|
||||
|
@ -321,6 +321,7 @@ add_gen_header(
|
||||
.llvm-libc-types.__pthread_start_t
|
||||
.llvm-libc-types.__pthread_tss_dtor_t
|
||||
.llvm-libc-types.pthread_attr_t
|
||||
.llvm-libc-types.pthread_condattr_t
|
||||
.llvm-libc-types.pthread_mutex_t
|
||||
.llvm-libc-types.pthread_mutexattr_t
|
||||
.llvm-libc-types.pthread_t
|
||||
|
@ -49,11 +49,12 @@ add_header(pid_t HDR pid_t.h)
|
||||
add_header(posix_spawn_file_actions_t HDR posix_spawn_file_actions_t.h)
|
||||
add_header(posix_spawnattr_t HDR posix_spawnattr_t.h)
|
||||
add_header(pthread_attr_t HDR pthread_attr_t.h DEPENDS .size_t)
|
||||
add_header(pthread_condattr_t HDR pthread_condattr_t.h DEPENDS .clockid_t)
|
||||
add_header(pthread_key_t HDR pthread_key_t.h)
|
||||
add_header(pthread_mutex_t HDR pthread_mutex_t.h DEPENDS .__futex_word .__mutex_type)
|
||||
add_header(pthread_t HDR pthread_t.h DEPENDS .__thread_type)
|
||||
add_header(pthread_mutexattr_t HDR pthread_mutexattr_t.h)
|
||||
add_header(pthread_once_t HDR pthread_once_t.h DEPENDS .__futex_word)
|
||||
add_header(pthread_t HDR pthread_t.h DEPENDS .__thread_type)
|
||||
add_header(rlim_t HDR rlim_t.h)
|
||||
add_header(time_t HDR time_t.h)
|
||||
add_header(stack_t HDR stack_t.h)
|
||||
|
18
libc/include/llvm-libc-types/pthread_condattr_t.h
Normal file
18
libc/include/llvm-libc-types/pthread_condattr_t.h
Normal file
@ -0,0 +1,18 @@
|
||||
//===-- Definition of pthread_condattr_t type -----------------------------===//
|
||||
//
|
||||
// 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_TYPES_PTHREAD_CONDATTR_T_H
|
||||
#define LLVM_LIBC_TYPES_PTHREAD_CONDATTR_T_H
|
||||
|
||||
#include "clockid_t.h"
|
||||
|
||||
typedef struct {
|
||||
clockid_t clock;
|
||||
int pshared;
|
||||
} pthread_condattr_t;
|
||||
|
||||
#endif // LLVM_LIBC_TYPES_PTHREAD_CONDATTR_T_H
|
@ -11,6 +11,9 @@
|
||||
|
||||
#include "__llvm-libc-common.h"
|
||||
|
||||
// TODO: move to a pthreads-macros.h file:
|
||||
// https://github.com/llvm/llvm-project/issues/88997
|
||||
|
||||
#define PTHREAD_STACK_MIN (1 << 14) // 16KB
|
||||
|
||||
#define PTHREAD_MUTEX_INITIALIZER {0}
|
||||
@ -32,6 +35,9 @@ enum {
|
||||
PTHREAD_MUTEX_ROBUST = 0x1,
|
||||
};
|
||||
|
||||
#define PTHREAD_PROCESS_PRIVATE 0
|
||||
#define PTHREAD_PROCESS_SHARED 1
|
||||
|
||||
%%public_api()
|
||||
|
||||
#endif // LLVM_LIBC_PTHREAD_H
|
||||
|
@ -26,6 +26,7 @@ def UidT : NamedType<"uid_t">;
|
||||
def GidT : NamedType<"gid_t">;
|
||||
def DevT : NamedType<"dev_t">;
|
||||
def ClockIdT : NamedType<"clockid_t">;
|
||||
def RestrictedClockIdTPtr : RestrictedPtrType<ClockIdT>;
|
||||
def BlkSizeT : NamedType<"blksize_t">;
|
||||
def BlkCntT : NamedType<"blkcnt_t">;
|
||||
def NLinkT : NamedType<"nlink_t">;
|
||||
@ -105,6 +106,10 @@ def POSIX : StandardSpec<"POSIX"> {
|
||||
ConstType ConstPThreadAttrTPtr = ConstType<PThreadAttrTPtr>;
|
||||
ConstType ConstRestrictedPThreadAttrTPtr = ConstType<RestrictedPThreadAttrTPtr>;
|
||||
|
||||
NamedType PThreadCondAttrTType = NamedType<"pthread_condattr_t">;
|
||||
PtrType PThreadCondAttrTPtr = PtrType<PThreadCondAttrTType>;
|
||||
ConstType ConstRestrictedPThreadCondAttrTPtr = ConstType<RestrictedPtrType<PThreadCondAttrTType>>;
|
||||
|
||||
NamedType PThreadMutexAttrTType = NamedType<"pthread_mutexattr_t">;
|
||||
PtrType PThreadMutexAttrTPtr = PtrType<PThreadMutexAttrTType>;
|
||||
RestrictedPtrType RestrictedPThreadMutexAttrTPtr = RestrictedPtrType<PThreadMutexAttrTType>;
|
||||
@ -980,7 +985,9 @@ def POSIX : StandardSpec<"POSIX"> {
|
||||
[], // Macros
|
||||
[
|
||||
AtForkCallbackT,
|
||||
ClockIdT,
|
||||
PThreadAttrTType,
|
||||
PThreadCondAttrTType,
|
||||
PThreadKeyT,
|
||||
PThreadMutexAttrTType,
|
||||
PThreadMutexTType,
|
||||
@ -1047,6 +1054,36 @@ def POSIX : StandardSpec<"POSIX"> {
|
||||
RetValSpec<IntType>,
|
||||
[ArgSpec<PThreadAttrTPtr>, ArgSpec<VoidPtr>, ArgSpec<SizeTType>]
|
||||
>,
|
||||
FunctionSpec<
|
||||
"pthread_condattr_destroy",
|
||||
RetValSpec<IntType>,
|
||||
[ArgSpec<PThreadCondAttrTPtr>]
|
||||
>,
|
||||
FunctionSpec<
|
||||
"pthread_condattr_getclock",
|
||||
RetValSpec<IntType>,
|
||||
[ArgSpec<ConstRestrictedPThreadCondAttrTPtr>, ArgSpec<RestrictedClockIdTPtr>]
|
||||
>,
|
||||
FunctionSpec<
|
||||
"pthread_condattr_getpshared",
|
||||
RetValSpec<IntType>,
|
||||
[ArgSpec<ConstRestrictedPThreadCondAttrTPtr>, ArgSpec<RestrictedIntPtr>]
|
||||
>,
|
||||
FunctionSpec<
|
||||
"pthread_condattr_init",
|
||||
RetValSpec<IntType>,
|
||||
[ArgSpec<PThreadCondAttrTPtr>]
|
||||
>,
|
||||
FunctionSpec<
|
||||
"pthread_condattr_setclock",
|
||||
RetValSpec<IntType>,
|
||||
[ArgSpec<PThreadCondAttrTPtr>, ArgSpec<ClockIdT>]
|
||||
>,
|
||||
FunctionSpec<
|
||||
"pthread_condattr_setpshared",
|
||||
RetValSpec<IntType>,
|
||||
[ArgSpec<PThreadCondAttrTPtr>, ArgSpec<IntType>]
|
||||
>,
|
||||
FunctionSpec<
|
||||
"pthread_create",
|
||||
RetValSpec<IntType>,
|
||||
@ -1522,9 +1559,30 @@ def POSIX : StandardSpec<"POSIX"> {
|
||||
HeaderSpec SysTypes = HeaderSpec<
|
||||
"sys/types.h",
|
||||
[], // Macros
|
||||
[BlkCntT, BlkSizeT, ClockIdT, DevT, GidT, InoT, ModeTType, NLinkT, OffTType, PidT,
|
||||
PThreadAttrTType, PThreadKeyT, PThreadMutexTType, PThreadMutexAttrTType, PThreadOnceT, PThreadTType,
|
||||
SizeTType, SSizeTType, SuSecondsT, TimeTType, UidT],
|
||||
[
|
||||
BlkCntT,
|
||||
BlkSizeT,
|
||||
ClockIdT,
|
||||
DevT,
|
||||
GidT,
|
||||
InoT,
|
||||
ModeTType,
|
||||
NLinkT,
|
||||
OffTType,
|
||||
PThreadAttrTType,
|
||||
PThreadCondAttrTType,
|
||||
PThreadKeyT,
|
||||
PThreadMutexAttrTType,
|
||||
PThreadMutexTType,
|
||||
PThreadOnceT,
|
||||
PThreadTType,
|
||||
PidT,
|
||||
SSizeTType,
|
||||
SizeTType,
|
||||
SuSecondsT,
|
||||
TimeTType,
|
||||
UidT
|
||||
], // Types
|
||||
[], // Enumerations
|
||||
[] // Functions
|
||||
>;
|
||||
|
@ -100,6 +100,71 @@ add_entrypoint_object(
|
||||
libc.src.pthread.pthread_attr_setstacksize
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
pthread_condattr_destroy
|
||||
SRCS
|
||||
pthread_condattr_destroy.cpp
|
||||
HDRS
|
||||
pthread_condattr_destroy.h
|
||||
DEPENDS
|
||||
libc.include.pthread
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
pthread_condattr_getclock
|
||||
SRCS
|
||||
pthread_condattr_getclock.cpp
|
||||
HDRS
|
||||
pthread_condattr_getclock.h
|
||||
DEPENDS
|
||||
libc.include.pthread
|
||||
libc.include.sys_types
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
pthread_condattr_getpshared
|
||||
SRCS
|
||||
pthread_condattr_getpshared.cpp
|
||||
HDRS
|
||||
pthread_condattr_getpshared.h
|
||||
DEPENDS
|
||||
libc.include.pthread
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
pthread_condattr_init
|
||||
SRCS
|
||||
pthread_condattr_init.cpp
|
||||
HDRS
|
||||
pthread_condattr_init.h
|
||||
DEPENDS
|
||||
libc.include.pthread
|
||||
libc.include.time
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
pthread_condattr_setclock
|
||||
SRCS
|
||||
pthread_condattr_setclock.cpp
|
||||
HDRS
|
||||
pthread_condattr_setclock.h
|
||||
DEPENDS
|
||||
libc.include.errno
|
||||
libc.include.pthread
|
||||
libc.include.sys_types
|
||||
libc.include.time
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
pthread_condattr_setpshared
|
||||
SRCS
|
||||
pthread_condattr_setpshared.cpp
|
||||
HDRS
|
||||
pthread_condattr_setpshared.h
|
||||
DEPENDS
|
||||
libc.include.pthread
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
pthread_mutexattr
|
||||
HDRS
|
||||
|
23
libc/src/pthread/pthread_condattr_destroy.cpp
Normal file
23
libc/src/pthread/pthread_condattr_destroy.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
//===-- Implementation of the pthread_condattr_destroy --------------------===//
|
||||
//
|
||||
// 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_condattr_destroy.h"
|
||||
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, pthread_condattr_destroy, (pthread_condattr_t * attr)) {
|
||||
// Initializing a pthread_condattr_t acquires no resources, so this is a
|
||||
// no-op.
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
20
libc/src/pthread/pthread_condattr_destroy.h
Normal file
20
libc/src/pthread/pthread_condattr_destroy.h
Normal file
@ -0,0 +1,20 @@
|
||||
//===-- Implementation header for pthread_condattr_destroy ------*- 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_PTHREAD_PTHREAD_CONDATTR_DESTROY_H
|
||||
#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_DESTROY_H
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
int pthread_condattr_destroy(pthread_condattr_t *attr);
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_DESTROY_H
|
25
libc/src/pthread/pthread_condattr_getclock.cpp
Normal file
25
libc/src/pthread/pthread_condattr_getclock.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
//===-- Implementation of the pthread_condattr_getclock -------------------===//
|
||||
//
|
||||
// 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_condattr_getclock.h"
|
||||
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#include <pthread.h> // pthread_condattr_t
|
||||
#include <sys/types.h> // clockid_t
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, pthread_condattr_getclock,
|
||||
(const pthread_condattr_t *__restrict attr,
|
||||
clockid_t *__restrict clock_id)) {
|
||||
*clock_id = attr->clock;
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
22
libc/src/pthread/pthread_condattr_getclock.h
Normal file
22
libc/src/pthread/pthread_condattr_getclock.h
Normal file
@ -0,0 +1,22 @@
|
||||
//===-- Implementation header for pthread_condattr_getclock -----*- 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_PTHREAD_PTHREAD_CONDATTR_GETCLOCK_H
|
||||
#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_GETCLOCK_H
|
||||
|
||||
#include <pthread.h> // pthread_condattr_t
|
||||
#include <sys/types.h> // clockid_t
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
int pthread_condattr_getclock(const pthread_condattr_t *__restrict attr,
|
||||
clockid_t *__restrict clock_id);
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_GETCLOCK_H
|
24
libc/src/pthread/pthread_condattr_getpshared.cpp
Normal file
24
libc/src/pthread/pthread_condattr_getpshared.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
//===-- Implementation of the pthread_condattr_getpshared -----------------===//
|
||||
//
|
||||
// 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_condattr_getpshared.h"
|
||||
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, pthread_condattr_getpshared,
|
||||
(const pthread_condattr_t *__restrict attr,
|
||||
int *__restrict pshared)) {
|
||||
*pshared = attr->pshared;
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
21
libc/src/pthread/pthread_condattr_getpshared.h
Normal file
21
libc/src/pthread/pthread_condattr_getpshared.h
Normal file
@ -0,0 +1,21 @@
|
||||
//===-- Implementation header for pthread_condattr_getpshared ---*- 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_PTHREAD_PTHREAD_CONDATTR_PSHARED_H
|
||||
#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_PSHARED_H
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
int pthread_condattr_getpshared(const pthread_condattr_t *__restrict attr,
|
||||
int *__restrict pshared);
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_PSHARED_H
|
24
libc/src/pthread/pthread_condattr_init.cpp
Normal file
24
libc/src/pthread/pthread_condattr_init.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
//===-- Implementation of the pthread_condattr_init -----------------------===//
|
||||
//
|
||||
// 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_condattr_init.h"
|
||||
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#include <pthread.h> // pthread_condattr_t, PTHREAD_PROCESS_PRIVATE
|
||||
#include <time.h> // CLOCK_REALTIME
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, pthread_condattr_init, (pthread_condattr_t * attr)) {
|
||||
attr->clock = CLOCK_REALTIME;
|
||||
attr->pshared = PTHREAD_PROCESS_PRIVATE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
20
libc/src/pthread/pthread_condattr_init.h
Normal file
20
libc/src/pthread/pthread_condattr_init.h
Normal file
@ -0,0 +1,20 @@
|
||||
//===-- Implementation header for pthread_condattr_init ---------*- 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_PTHREAD_PTHREAD_CONDATTR_INIT_H
|
||||
#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_INIT_H
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
int pthread_condattr_init(pthread_condattr_t *attr);
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_INIT_H
|
30
libc/src/pthread/pthread_condattr_setclock.cpp
Normal file
30
libc/src/pthread/pthread_condattr_setclock.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
//===-- Implementation of the pthread_condattr_setclock -------------------===//
|
||||
//
|
||||
// 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_condattr_setclock.h"
|
||||
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#include <errno.h> // EINVAL
|
||||
#include <pthread.h> // pthread_condattr_t
|
||||
#include <sys/types.h> // clockid_t
|
||||
#include <time.h> // CLOCK_MONOTONIC, CLOCK_REALTIME
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, pthread_condattr_setclock,
|
||||
(pthread_condattr_t * attr, clockid_t clock)) {
|
||||
|
||||
if (clock != CLOCK_MONOTONIC && clock != CLOCK_REALTIME)
|
||||
return EINVAL;
|
||||
|
||||
attr->clock = clock;
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
21
libc/src/pthread/pthread_condattr_setclock.h
Normal file
21
libc/src/pthread/pthread_condattr_setclock.h
Normal file
@ -0,0 +1,21 @@
|
||||
//===-- Implementation header for pthread_condattr_setclock -----*- 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_PTHREAD_PTHREAD_CONDATTR_SETCLOCK_H
|
||||
#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_SETCLOCK_H
|
||||
|
||||
#include <pthread.h>
|
||||
#include <sys/types.h> // clockid_t
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
int pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock);
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_SETCLOCK_H
|
28
libc/src/pthread/pthread_condattr_setpshared.cpp
Normal file
28
libc/src/pthread/pthread_condattr_setpshared.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
//===-- Implementation of the pthread_condattr_setpshared -----------------===//
|
||||
//
|
||||
// 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_condattr_setpshared.h"
|
||||
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#include <errno.h> // EINVAL
|
||||
#include <pthread.h> // pthread_condattr_t, PTHREAD_PROCESS_SHARED, PTHREAD_PROCESS_PRIVATE
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, pthread_condattr_setpshared,
|
||||
(pthread_condattr_t * attr, int pshared)) {
|
||||
|
||||
if (pshared != PTHREAD_PROCESS_SHARED && pshared != PTHREAD_PROCESS_PRIVATE)
|
||||
return EINVAL;
|
||||
|
||||
attr->pshared = pshared;
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
20
libc/src/pthread/pthread_condattr_setpshared.h
Normal file
20
libc/src/pthread/pthread_condattr_setpshared.h
Normal file
@ -0,0 +1,20 @@
|
||||
//===-- Implementation header for pthread_condattr_setpshared ---*- 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_PTHREAD_PTHREAD_CONDATTR_SETPSHARED_H
|
||||
#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_SETPSHARED_H
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
int pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared);
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_SETPSHARED_H
|
@ -39,3 +39,15 @@ add_libc_unittest(
|
||||
libc.src.pthread.pthread_mutexattr_setrobust
|
||||
libc.src.pthread.pthread_mutexattr_settype
|
||||
)
|
||||
|
||||
add_libc_unittest(
|
||||
pthread_condattr_test
|
||||
SUITE
|
||||
libc_pthread_unittests
|
||||
SRCS
|
||||
pthread_condattr_test.cpp
|
||||
DEPENDS
|
||||
libc.include.errno
|
||||
libc.include.pthread
|
||||
libc.include.time
|
||||
)
|
||||
|
71
libc/test/src/pthread/pthread_condattr_test.cpp
Normal file
71
libc/test/src/pthread/pthread_condattr_test.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
//===-- Unittests for pthread_condattr_t ----------------------------------===//
|
||||
//
|
||||
// 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 "test/UnitTest/Test.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
|
||||
TEST(LlvmLibcPThreadCondAttrTest, InitAndDestroy) {
|
||||
pthread_condattr_t cond;
|
||||
ASSERT_EQ(pthread_condattr_init(&cond), 0);
|
||||
ASSERT_EQ(pthread_condattr_destroy(&cond), 0);
|
||||
}
|
||||
|
||||
TEST(LlvmLibcPThreadCondAttrTest, GetDefaultValues) {
|
||||
pthread_condattr_t cond;
|
||||
|
||||
// Invalid clock id.
|
||||
clockid_t clock = 7;
|
||||
// Invalid value.
|
||||
int pshared = 42;
|
||||
|
||||
ASSERT_EQ(pthread_condattr_init(&cond), 0);
|
||||
ASSERT_EQ(pthread_condattr_getclock(&cond, &clock), 0);
|
||||
ASSERT_EQ(clock, CLOCK_REALTIME);
|
||||
ASSERT_EQ(pthread_condattr_getpshared(&cond, &pshared), 0);
|
||||
ASSERT_EQ(pshared, PTHREAD_PROCESS_PRIVATE);
|
||||
ASSERT_EQ(pthread_condattr_destroy(&cond), 0);
|
||||
}
|
||||
|
||||
TEST(LlvmLibcPThreadCondAttrTest, SetGoodValues) {
|
||||
pthread_condattr_t cond;
|
||||
|
||||
// Invalid clock id.
|
||||
clockid_t clock = 7;
|
||||
// Invalid value.
|
||||
int pshared = 42;
|
||||
|
||||
ASSERT_EQ(pthread_condattr_init(&cond), 0);
|
||||
ASSERT_EQ(pthread_condattr_setclock(&cond, CLOCK_MONOTONIC), 0);
|
||||
ASSERT_EQ(pthread_condattr_getclock(&cond, &clock), 0);
|
||||
ASSERT_EQ(clock, CLOCK_MONOTONIC);
|
||||
ASSERT_EQ(pthread_condattr_setpshared(&cond, PTHREAD_PROCESS_SHARED), 0);
|
||||
ASSERT_EQ(pthread_condattr_getpshared(&cond, &pshared), 0);
|
||||
ASSERT_EQ(pshared, PTHREAD_PROCESS_SHARED);
|
||||
ASSERT_EQ(pthread_condattr_destroy(&cond), 0);
|
||||
}
|
||||
|
||||
TEST(LlvmLibcPThreadCondAttrTest, SetBadValues) {
|
||||
pthread_condattr_t cond;
|
||||
|
||||
// Invalid clock id.
|
||||
clockid_t clock = 7;
|
||||
// Invalid value.
|
||||
int pshared = 42;
|
||||
|
||||
ASSERT_EQ(pthread_condattr_init(&cond), 0);
|
||||
ASSERT_EQ(pthread_condattr_setclock(&cond, clock), EINVAL);
|
||||
ASSERT_EQ(pthread_condattr_getclock(&cond, &clock), 0);
|
||||
ASSERT_EQ(clock, CLOCK_REALTIME);
|
||||
ASSERT_EQ(pthread_condattr_setpshared(&cond, pshared), EINVAL);
|
||||
ASSERT_EQ(pthread_condattr_getpshared(&cond, &pshared), 0);
|
||||
ASSERT_EQ(pshared, PTHREAD_PROCESS_PRIVATE);
|
||||
ASSERT_EQ(pthread_condattr_destroy(&cond), 0);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user