about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--absl/container/flat_hash_map.h2
-rw-r--r--absl/memory/memory.h24
-rw-r--r--absl/synchronization/internal/per_thread_sem_test.cc7
-rw-r--r--absl/synchronization/notification_test.cc9
4 files changed, 31 insertions, 11 deletions
diff --git a/absl/container/flat_hash_map.h b/absl/container/flat_hash_map.h
index 9e7f682180e5..e5570d100441 100644
--- a/absl/container/flat_hash_map.h
+++ b/absl/container/flat_hash_map.h
@@ -88,7 +88,7 @@ struct FlatHashMapPolicy;
 //     {{"a", "huey"}, {"b", "dewey"}, {"c", "louie"}};
 //
 //  // Insert a new element into the flat hash map
-//  ducks.insert({"d", "donald"}};
+//  ducks.insert({"d", "donald"});
 //
 //  // Force a rehash of the flat hash map
 //  ducks.rehash(0);
diff --git a/absl/memory/memory.h b/absl/memory/memory.h
index a80aab0af641..1eaec0f40aea 100644
--- a/absl/memory/memory.h
+++ b/absl/memory/memory.h
@@ -39,16 +39,30 @@ namespace absl {
 // Function Template: WrapUnique()
 // -----------------------------------------------------------------------------
 //
-//  Adopts ownership from a raw pointer and transfers it to the returned
-//  `std::unique_ptr`, whose type is deduced. DO NOT specify the template type T
-//  when calling WrapUnique.
+// Adopts ownership from a raw pointer and transfers it to the returned
+// `std::unique_ptr`, whose type is deduced. Because of this deduction, *do not*
+// specify the template type `T` when calling `WrapUnique`.
 //
 // Example:
 //   X* NewX(int, int);
 //   auto x = WrapUnique(NewX(1, 2));  // 'x' is std::unique_ptr<X>.
 //
-// `absl::WrapUnique` is useful for capturing the output of a raw pointer
-// factory. However, prefer 'absl::make_unique<T>(args...) over
+// The purpose of WrapUnique is to automatically deduce the pointer type. If you
+// wish to make the type explicit, for readability reasons or because you prefer
+// to use a base-class pointer rather than a derived one, just use
+// `std::unique_ptr` directly.
+//
+// Example:
+//   X* Factory(int, int);
+//   auto x = std::unique_ptr<X>(Factory(1, 2));
+//                  - or -
+//   std::unique_ptr<X> x(Factory(1, 2));
+//
+// This has the added advantage of working whether Factory returns a raw
+// pointer or a `std::unique_ptr`.
+//
+// While `absl::WrapUnique` is useful for capturing the output of a raw
+// pointer factory, prefer 'absl::make_unique<T>(args...)' over
 // 'absl::WrapUnique(new T(args...))'.
 //
 //   auto x = WrapUnique(new X(1, 2));  // works, but nonideal.
diff --git a/absl/synchronization/internal/per_thread_sem_test.cc b/absl/synchronization/internal/per_thread_sem_test.cc
index 2b52ea76ab0e..c29d8403df43 100644
--- a/absl/synchronization/internal/per_thread_sem_test.cc
+++ b/absl/synchronization/internal/per_thread_sem_test.cc
@@ -153,12 +153,15 @@ TEST_F(PerThreadSemTest, WithTimeout) {
 
 TEST_F(PerThreadSemTest, Timeouts) {
   absl::Time timeout = absl::Now() + absl::Milliseconds(50);
+  // Allow for a slight early return, to account for quality of implementation
+  // issues on various platforms.
+  const absl::Duration slop = absl::Microseconds(200);
   EXPECT_FALSE(Wait(timeout));
-  EXPECT_LE(timeout, absl::Now());
+  EXPECT_LE(timeout, absl::Now() + slop);
 
   absl::Time negative_timeout = absl::UnixEpoch() - absl::Milliseconds(100);
   EXPECT_FALSE(Wait(negative_timeout));
-  EXPECT_LE(negative_timeout, absl::Now());  // trivially true :)
+  EXPECT_LE(negative_timeout, absl::Now() + slop);  // trivially true :)
 
   Post(GetOrCreateCurrentThreadIdentity());
   // The wait here has an expired timeout, but we have a wake to consume,
diff --git a/absl/synchronization/notification_test.cc b/absl/synchronization/notification_test.cc
index 9b3b6a5a9e84..d8708d551a15 100644
--- a/absl/synchronization/notification_test.cc
+++ b/absl/synchronization/notification_test.cc
@@ -71,10 +71,13 @@ static void BasicTests(bool notify_before_waiting, Notification* notification) {
       notification->WaitForNotificationWithTimeout(absl::Milliseconds(0)));
   EXPECT_FALSE(notification->WaitForNotificationWithDeadline(absl::Now()));
 
+  const absl::Duration delay = absl::Milliseconds(50);
+  // Allow for a slight early return, to account for quality of implementation
+  // issues on various platforms.
+  const absl::Duration slop = absl::Microseconds(200);
   absl::Time start = absl::Now();
-  EXPECT_FALSE(
-      notification->WaitForNotificationWithTimeout(absl::Milliseconds(50)));
-  EXPECT_LE(start + absl::Milliseconds(50), absl::Now());
+  EXPECT_FALSE(notification->WaitForNotificationWithTimeout(delay));
+  EXPECT_LE(start + delay, absl::Now() + slop);
 
   ThreadSafeCounter ready_counter;
   ThreadSafeCounter done_counter;