mirror of
https://github.com/intel/llvm.git
synced 2026-01-16 13:35:38 +08:00
[libc][pthread] fix -Wmissing-field-initializers (#126314)
Fixes:
llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp:59:29:
warning: missing field '__preference' initializer
[-Wmissing-field-initializers]
59 | pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
| ^
Also, add a test that demonstrates the same issue for
PTHREAD_MUTEX_INITIALIZER, and fix that, too.
PTHREAD_ONCE_INIT does not have this issue and does have test coverage.
This commit is contained in:
@@ -328,6 +328,8 @@ add_macro_header(
|
||||
pthread_macros
|
||||
HDR
|
||||
pthread-macros.h
|
||||
DEPENDS
|
||||
.null_macro
|
||||
)
|
||||
|
||||
add_macro_header(
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#ifndef LLVM_LIBC_MACROS_PTHREAD_MACRO_H
|
||||
#define LLVM_LIBC_MACROS_PTHREAD_MACRO_H
|
||||
|
||||
#include "null-macro.h"
|
||||
|
||||
#define PTHREAD_CREATE_JOINABLE 0
|
||||
#define PTHREAD_CREATE_DETACHED 1
|
||||
|
||||
@@ -25,8 +27,34 @@
|
||||
#define PTHREAD_PROCESS_PRIVATE 0
|
||||
#define PTHREAD_PROCESS_SHARED 1
|
||||
|
||||
#define PTHREAD_MUTEX_INITIALIZER {0}
|
||||
#define PTHREAD_RWLOCK_INITIALIZER {0}
|
||||
#ifdef __linux__
|
||||
#define PTHREAD_MUTEX_INITIALIZER \
|
||||
{ \
|
||||
/* .__timed = */ 0, /* .__recursive = */ 0, \
|
||||
/* .__robust = */ 0, /* .__owner = */ NULL, \
|
||||
/* .__lock_count = */ 0, /* .__futex_word = */ {0}, \
|
||||
}
|
||||
#else
|
||||
#define PTHREAD_MUTEX_INITIALIZER \
|
||||
{ \
|
||||
/* .__timed = */ 0, /* .__recursive = */ 0, \
|
||||
/* .__robust = */ 0, /* .__owner = */ NULL, \
|
||||
/* .__lock_count = */ 0, \
|
||||
}
|
||||
#endif
|
||||
|
||||
#define PTHREAD_RWLOCK_INITIALIZER \
|
||||
{ \
|
||||
/* .__is_pshared = */ 0, \
|
||||
/* .__preference = */ 0, \
|
||||
/* .__state = */ 0, \
|
||||
/* .__write_tid = */ 0, \
|
||||
/* .__wait_queue_mutex = */ {0}, \
|
||||
/* .__pending_readers = */ {0}, \
|
||||
/* .__pending_writers = */ {0}, \
|
||||
/* .__reader_serialization = */ {0}, \
|
||||
/* .__writer_serialization = */ {0}, \
|
||||
}
|
||||
|
||||
// glibc extensions
|
||||
#define PTHREAD_STACK_MIN (1 << 14) // 16KB
|
||||
|
||||
@@ -186,6 +186,10 @@ void multiple_waiters() {
|
||||
LIBC_NAMESPACE::pthread_mutex_destroy(&counter_lock);
|
||||
}
|
||||
|
||||
// Test the initializer
|
||||
[[maybe_unused]]
|
||||
static pthread_mutex_t test_initializer = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
TEST_MAIN() {
|
||||
relay_counter();
|
||||
wait_and_step();
|
||||
|
||||
Reference in New Issue
Block a user