Ceci n'est pas une pipe

This commit is contained in:
Victor Zverovich 2023-12-29 08:11:29 -08:00
parent d83c1b8d4a
commit d5823aae36
2 changed files with 6 additions and 0 deletions

View File

@ -315,6 +315,7 @@ class FMT_API file {
// Creates a pipe setting up read_end and write_end file objects for reading // Creates a pipe setting up read_end and write_end file objects for reading
// and writing respectively. // and writing respectively.
// DEPRECATED! Taking files as out parameters is deprecated.
static void pipe(file& read_end, file& write_end); static void pipe(file& read_end, file& write_end);
// Creates a buffered_file object associated with this file and detaches // Creates a buffered_file object associated with this file and detaches

View File

@ -143,6 +143,7 @@ TEST(scan_test, file) {
} }
TEST(scan_test, lock) { TEST(scan_test, lock) {
fmt::file read_end, write_end; fmt::file read_end, write_end;
fmt::file::pipe(read_end, write_end); fmt::file::pipe(read_end, write_end);
@ -152,6 +153,7 @@ TEST(scan_test, lock) {
write_end.close(); write_end.close();
}); });
std::atomic<int> count = 0;
fmt::buffered_file f = read_end.fdopen("r"); fmt::buffered_file f = read_end.fdopen("r");
auto fun = [&]() { auto fun = [&]() {
int value = 0; int value = 0;
@ -161,6 +163,7 @@ TEST(scan_test, lock) {
EXPECT_EQ(value, 42); EXPECT_EQ(value, 42);
break; break;
} }
++count;
} }
}; };
std::thread consumer1(fun); std::thread consumer1(fun);
@ -168,5 +171,7 @@ TEST(scan_test, lock) {
producer.join(); producer.join();
consumer1.join(); consumer1.join();
consumer2.join(); consumer2.join();
EXPECT_EQ(count, 1000);
} }
#endif // FMT_USE_FCNTL #endif // FMT_USE_FCNTL