Skip to content

include/pthread : initialize wait_count in PTHREAD_COND_INITIALIZER#19109

Merged
acassis merged 1 commit into
apache:masterfrom
nicolasWDC:master
Jun 16, 2026
Merged

include/pthread : initialize wait_count in PTHREAD_COND_INITIALIZER#19109
acassis merged 1 commit into
apache:masterfrom
nicolasWDC:master

Conversation

@nicolasWDC

@nicolasWDC nicolasWDC commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

PR: Fix PTHREAD_COND_INITIALIZER missing wait_count initializer

Summary

This PR patches NuttX 12.13.0 to fully initialize pthread_cond_s in PTHREAD_COND_INITIALIZER.

The patch updates:

#define PTHREAD_COND_INITIALIZER {SEM_INITIALIZER(0), CLOCK_REALTIME }

to:

#define PTHREAD_COND_INITIALIZER {SEM_INITIALIZER(0), CLOCK_REALTIME, 0}

Motivation

During the NuttX 12.13.0 migration, strict builds emitted:

warning: missing initializer for member 'pthread_cond_s::wait_count' [-Wmissing-field-initializers]

The warning is caused by the mismatch between the structure definition and the static initializer.

pthread_cond_s is defined with three fields:

struct pthread_cond_s
{
  sem_t sem;
  clockid_t clockid;
  int wait_count;
};

but the initializer only covered sem and clockid.

Fix

Initialize the third field explicitly:

wait_count = 0

This makes PTHREAD_COND_INITIALIZER consistent with struct pthread_cond_s.

Patch

File:

OTSS/OS/nuttx/patches/0003-pthread_cond_initializer.patch

Change:

--- include/pthread.h
+++ include/pthread.h
@@ -279,7 +279,7 @@
 #  define __PTHREAD_COND_T_DEFINED 1
 #endif

-#define PTHREAD_COND_INITIALIZER {SEM_INITIALIZER(0), CLOCK_REALTIME }
+#define PTHREAD_COND_INITIALIZER {SEM_INITIALIZER(0), CLOCK_REALTIME, 0}

 struct pthread_mutexattr_s
 {

Validation

Validated with a minimal compile test:

#include <pthread.h>

pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

The test now builds without the pthread_cond_s::wait_count missing-initializer warning.

Closes #19108

@nicolasWDC

Copy link
Copy Markdown
Contributor Author

Fixes #19108

struct pthread_cond_s contains three fields: sem, clockid, and
wait_count. However, PTHREAD_COND_INITIALIZER only initialized the first
two fields, which triggers -Wmissing-field-initializers when a condition
variable is statically initialized.

Initialize wait_count explicitly to zero so the macro matches the structure
definition and remains warning-free with strict compiler flags.

Validated with a minimal compile test using:

pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

Signed-off-by: nicolasWDC <nicolasWDC@users.noreply.github.com>
@github-actions github-actions Bot added Area: OS Components OS Components issues Size: XS The size of the change in this PR is very small labels Jun 10, 2026
@acassis acassis merged commit dc830ce into apache:master Jun 16, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] PTHREAD_COND_INITIALIZER misses wait_count initialization

3 participants