Changeset View
Changeset View
Standalone View
Standalone View
lld/trunk/ELF/Filesystem.cpp
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | #else | ||||
// We cannot just remove path from a different thread because we are now going | // We cannot just remove path from a different thread because we are now going | ||||
// to create path as a new file. | // to create path as a new file. | ||||
// Instead we open the file and unlink it on this thread. The unlink is fast | // Instead we open the file and unlink it on this thread. The unlink is fast | ||||
// since the open fd guarantees that it is not removing the last reference. | // since the open fd guarantees that it is not removing the last reference. | ||||
int FD; | int FD; | ||||
std::error_code EC = sys::fs::openFileForRead(Path, FD); | std::error_code EC = sys::fs::openFileForRead(Path, FD); | ||||
sys::fs::remove(Path); | sys::fs::remove(Path); | ||||
if (EC) | |||||
return; | |||||
// close and therefore remove TempPath in background. | // close and therefore remove TempPath in background. | ||||
if (!EC) | std::mutex M; | ||||
std::thread([=] { ::close(FD); }).detach(); | std::condition_variable CV; | ||||
bool Started = false; | |||||
std::thread([&, FD] { | |||||
{ | |||||
std::lock_guard<std::mutex> L(M); | |||||
Started = true; | |||||
CV.notify_all(); | |||||
} | |||||
::close(FD); | |||||
}).detach(); | |||||
// GLIBC 2.26 and earlier have race condition that crashes an entire process | |||||
// if the main thread calls exit(2) while other thread is starting up. | |||||
std::unique_lock<std::mutex> L(M); | |||||
CV.wait(L, [&] { return Started; }); | |||||
#endif | #endif | ||||
} | } | ||||
// Simulate file creation to see if Path is writable. | // Simulate file creation to see if Path is writable. | ||||
// | // | ||||
// Determining whether a file is writable or not is amazingly hard, | // Determining whether a file is writable or not is amazingly hard, | ||||
// and after all the only reliable way of doing that is to actually | // and after all the only reliable way of doing that is to actually | ||||
// create a file. But we don't want to do that in this function | // create a file. But we don't want to do that in this function | ||||
Show All 14 Lines |