Bug Summary

File:out/../deps/v8/src/base/platform/condition-variable.cc
Warning:line 29, column 3
Value stored to 'result' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name condition-variable.cc -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/home/maurizio/node-v18.6.0/out -resource-dir /usr/local/lib/clang/16.0.0 -D _GLIBCXX_USE_CXX11_ABI=1 -D NODE_OPENSSL_CONF_NAME=nodejs_conf -D NODE_OPENSSL_HAS_QUIC -D V8_GYP_BUILD -D V8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64 -D __STDC_FORMAT_MACROS -D OPENSSL_NO_PINSHARED -D OPENSSL_THREADS -D V8_TARGET_ARCH_X64 -D V8_HAVE_TARGET_OS -D V8_TARGET_OS_LINUX -D V8_EMBEDDER_STRING="-node.8" -D ENABLE_DISASSEMBLER -D V8_PROMISE_INTERNAL_FIELD_COUNT=1 -D V8_SHORT_BUILTIN_CALLS -D OBJECT_PRINT -D V8_INTL_SUPPORT -D V8_ATOMIC_OBJECT_FIELD_WRITES -D V8_ENABLE_LAZY_SOURCE_POSITIONS -D V8_USE_SIPHASH -D V8_SHARED_RO_HEAP -D V8_WIN64_UNWINDING_INFO -D V8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH -D V8_SNAPSHOT_COMPRESSION -D V8_ENABLE_WEBASSEMBLY -D V8_ENABLE_JAVASCRIPT_PROMISE_HOOKS -D V8_ALLOCATION_FOLDING -D V8_ALLOCATION_SITE_TRACKING -D V8_SCRIPTORMODULE_LEGACY_LIFETIME -D V8_ADVANCED_BIGINT_ALGORITHMS -D BUILDING_V8_BASE_SHARED -I ../deps/v8 -I ../deps/v8/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8 -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/x86_64-redhat-linux -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/backward -internal-isystem /usr/local/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-unused-parameter -Wno-return-type -std=gnu++17 -fdeprecated-macro -fdebug-compilation-dir=/home/maurizio/node-v18.6.0/out -ferror-limit 19 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-08-22-142216-507842-1 -x c++ ../deps/v8/src/base/platform/condition-variable.cc
1// Copyright 2013 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "src/base/platform/condition-variable.h"
6
7#include <errno(*__errno_location ()).h>
8#include <time.h>
9
10#include "src/base/platform/time.h"
11
12#if V8_OS_WIN
13#include <windows.h>
14#endif
15
16namespace v8 {
17namespace base {
18
19#if V8_OS_POSIX1
20
21ConditionVariable::ConditionVariable() {
22#if (V8_OS_FREEBSD || V8_OS_NETBSD || V8_OS_OPENBSD || \
23 (V8_OS_LINUX1 && V8_LIBC_GLIBC1))
24 // On Free/Net/OpenBSD and Linux with glibc we can change the time
25 // source for pthread_cond_timedwait() to use the monotonic clock.
26 pthread_condattr_t attr;
27 int result = pthread_condattr_init(&attr);
28 DCHECK_EQ(0, result)((void) 0);
29 result = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC1);
Value stored to 'result' is never read
30 DCHECK_EQ(0, result)((void) 0);
31 result = pthread_cond_init(&native_handle_, &attr);
32 DCHECK_EQ(0, result)((void) 0);
33 result = pthread_condattr_destroy(&attr);
34#else
35 int result = pthread_cond_init(&native_handle_, nullptr);
36#endif
37 DCHECK_EQ(0, result)((void) 0);
38 USE(result)do { ::v8::base::Use unused_tmp_array_for_use_macro[]{result}
; (void)unused_tmp_array_for_use_macro; } while (false)
;
39}
40
41
42ConditionVariable::~ConditionVariable() {
43#if defined(V8_OS_DARWIN)
44 // This hack is necessary to avoid a fatal pthreads subsystem bug in the
45 // Darwin kernel. http://crbug.com/517681.
46 {
47 Mutex lock;
48 MutexGuard l(&lock);
49 struct timespec ts;
50 ts.tv_sec = 0;
51 ts.tv_nsec = 1;
52 pthread_cond_timedwait_relative_np(&native_handle_, &lock.native_handle(),
53 &ts);
54 }
55#endif
56 int result = pthread_cond_destroy(&native_handle_);
57 DCHECK_EQ(0, result)((void) 0);
58 USE(result)do { ::v8::base::Use unused_tmp_array_for_use_macro[]{result}
; (void)unused_tmp_array_for_use_macro; } while (false)
;
59}
60
61
62void ConditionVariable::NotifyOne() {
63 int result = pthread_cond_signal(&native_handle_);
64 DCHECK_EQ(0, result)((void) 0);
65 USE(result)do { ::v8::base::Use unused_tmp_array_for_use_macro[]{result}
; (void)unused_tmp_array_for_use_macro; } while (false)
;
66}
67
68
69void ConditionVariable::NotifyAll() {
70 int result = pthread_cond_broadcast(&native_handle_);
71 DCHECK_EQ(0, result)((void) 0);
72 USE(result)do { ::v8::base::Use unused_tmp_array_for_use_macro[]{result}
; (void)unused_tmp_array_for_use_macro; } while (false)
;
73}
74
75
76void ConditionVariable::Wait(Mutex* mutex) {
77 mutex->AssertHeldAndUnmark();
78 int result = pthread_cond_wait(&native_handle_, &mutex->native_handle());
79 DCHECK_EQ(0, result)((void) 0);
80 USE(result)do { ::v8::base::Use unused_tmp_array_for_use_macro[]{result}
; (void)unused_tmp_array_for_use_macro; } while (false)
;
81 mutex->AssertUnheldAndMark();
82}
83
84
85bool ConditionVariable::WaitFor(Mutex* mutex, const TimeDelta& rel_time) {
86 struct timespec ts;
87 int result;
88 mutex->AssertHeldAndUnmark();
89#if V8_OS_DARWIN
90 // Mac OS X provides pthread_cond_timedwait_relative_np(), which does
91 // not depend on the real time clock, which is what you really WANT here!
92 ts = rel_time.ToTimespec();
93 DCHECK_GE(ts.tv_sec, 0)((void) 0);
94 DCHECK_GE(ts.tv_nsec, 0)((void) 0);
95 result = pthread_cond_timedwait_relative_np(
96 &native_handle_, &mutex->native_handle(), &ts);
97#else
98#if (V8_OS_FREEBSD || V8_OS_NETBSD || V8_OS_OPENBSD || \
99 (V8_OS_LINUX1 && V8_LIBC_GLIBC1))
100 // On Free/Net/OpenBSD and Linux with glibc we can change the time
101 // source for pthread_cond_timedwait() to use the monotonic clock.
102 result = clock_gettime(CLOCK_MONOTONIC1, &ts);
103 DCHECK_EQ(0, result)((void) 0);
104 Time now = Time::FromTimespec(ts);
105#else
106 // The timeout argument to pthread_cond_timedwait() is in absolute time.
107 Time now = Time::NowFromSystemTime();
108#endif
109 Time end_time = now + rel_time;
110 DCHECK_GE(end_time, now)((void) 0);
111 ts = end_time.ToTimespec();
112 result = pthread_cond_timedwait(
113 &native_handle_, &mutex->native_handle(), &ts);
114#endif // V8_OS_DARWIN
115 mutex->AssertUnheldAndMark();
116 if (result == ETIMEDOUT110) {
117 return false;
118 }
119 DCHECK_EQ(0, result)((void) 0);
120 return true;
121}
122
123#elif V8_OS_WIN
124
125ConditionVariable::ConditionVariable() {
126 InitializeConditionVariable(V8ToWindowsType(&native_handle_));
127}
128
129
130ConditionVariable::~ConditionVariable() {}
131
132void ConditionVariable::NotifyOne() {
133 WakeConditionVariable(V8ToWindowsType(&native_handle_));
134}
135
136void ConditionVariable::NotifyAll() {
137 WakeAllConditionVariable(V8ToWindowsType(&native_handle_));
138}
139
140
141void ConditionVariable::Wait(Mutex* mutex) {
142 mutex->AssertHeldAndUnmark();
143 SleepConditionVariableSRW(V8ToWindowsType(&native_handle_),
144 V8ToWindowsType(&mutex->native_handle()), INFINITE,
145 0);
146 mutex->AssertUnheldAndMark();
147}
148
149
150bool ConditionVariable::WaitFor(Mutex* mutex, const TimeDelta& rel_time) {
151 int64_t msec = rel_time.InMilliseconds();
152 mutex->AssertHeldAndUnmark();
153 BOOL result = SleepConditionVariableSRW(
154 V8ToWindowsType(&native_handle_),
155 V8ToWindowsType(&mutex->native_handle()), static_cast<DWORD>(msec), 0);
156#ifdef DEBUG
157 if (!result) {
158 // On failure, we only expect the CV to timeout. Any other error value means
159 // that we've unexpectedly woken up.
160 // Note that WAIT_TIMEOUT != ERROR_TIMEOUT. WAIT_TIMEOUT is used with the
161 // WaitFor* family of functions as a direct return value. ERROR_TIMEOUT is
162 // used with GetLastError().
163 DCHECK_EQ(static_cast<DWORD>(ERROR_TIMEOUT), GetLastError())((void) 0);
164 }
165#endif
166 mutex->AssertUnheldAndMark();
167 return result != 0;
168}
169
170#elif V8_OS_STARBOARD
171
172ConditionVariable::ConditionVariable() {
173 SbConditionVariableCreate(&native_handle_, nullptr);
174}
175
176ConditionVariable::~ConditionVariable() {
177 SbConditionVariableDestroy(&native_handle_);
178}
179
180void ConditionVariable::NotifyOne() {
181 SbConditionVariableSignal(&native_handle_);
182}
183
184void ConditionVariable::NotifyAll() {
185 SbConditionVariableBroadcast(&native_handle_);
186}
187
188void ConditionVariable::Wait(Mutex* mutex) {
189 SbConditionVariableWait(&native_handle_, &mutex->native_handle());
190}
191
192bool ConditionVariable::WaitFor(Mutex* mutex, const TimeDelta& rel_time) {
193 SbTime microseconds = static_cast<SbTime>(rel_time.InMicroseconds());
194 SbConditionVariableResult result = SbConditionVariableWaitTimed(
195 &native_handle_, &mutex->native_handle(), microseconds);
196 DCHECK(result != kSbConditionVariableFailed)((void) 0);
197 return result == kSbConditionVariableSignaled;
198}
199
200#endif // V8_OS_STARBOARD
201
202} // namespace base
203} // namespace v8