Skip to content

Commit 727a613

Browse files
cpsughrueBigcheese
andcommitted
Use atomic operations on file descriptor check
Co-authored-by: Michael Spencer <[email protected]>
1 parent b10022f commit 727a613

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

llvm/lib/Support/raw_socket_stream.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,10 @@ ListeningSocket::accept(std::optional<std::chrono::milliseconds> Timeout) {
227227
}
228228

229229
void ListeningSocket::shutdown() {
230-
if (FD == -1)
230+
int ObservedFD = FD.load();
231+
if (ObservedFD == -1)
232+
return;
233+
if (!FD.compare_exchange_strong(ObservedFD, -1))
231234
return;
232235
::close(FD);
233236
::unlink(SocketPath.c_str());

0 commit comments

Comments
 (0)