Fix integer sign consistency. v2018.01.22.00
authorMaged Michael <magedmichael@fb.com>
Sat, 20 Jan 2018 05:46:22 +0000 (21:46 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Sat, 20 Jan 2018 06:06:40 +0000 (22:06 -0800)
Summary: Keeping all variables that interact with hazptr_domain::rcount_ signed int to avoid conversion errors.

Reviewed By: yfeldblum

Differential Revision: D6754593

fbshipit-source-id: e283f127a112a529a0e98eb82b6061b44aa9d2ca

folly/concurrency/test/DynamicBoundedQueueTest.cpp
folly/experimental/hazptr/hazptr-impl.h
folly/experimental/hazptr/hazptr.h

index 290df3daffa550bc1d671e846f1d4d06f8e7100b..a4421011f4307a8d6f37623d169eb4c8c110ef78 100644 (file)
@@ -93,17 +93,6 @@ TEST(DynamicBoundedQueue, basic) {
   basic_test<DMPMC, true>();
 }
 
-TEST(DynamicBoundedQueue, size) {
-  {
-    folly::DynamicBoundedQueue<int, true, true, true> q(10);
-    ASSERT_EQ(sizeof(q), 640);
-  }
-  {
-    folly::DynamicBoundedQueue<uint64_t, false, false, false, 7, 4> q(10);
-    ASSERT_EQ(sizeof(q), 80 + sizeof(folly::hazptr::hazptr_obj_batch));
-  }
-}
-
 template <template <typename, bool, typename> class Q, bool MayBlock>
 void move_test() {
   struct Foo {
index 3bcf6186a13e1e4d48d4e22a248fe744e26afcf7..26765c88c7058da0f17a306631f3f926691ce557 100644 (file)
@@ -1084,15 +1084,15 @@ inline hazptr_tls_life::~hazptr_tls_life() {
  *  and a thread-safe access only, for now. */
 
 class hazptr_obj_batch {
-  static constexpr size_t DefaultThreshold = 20;
+  static constexpr int DefaultThreshold = 20;
   hazptr_obj* head_{nullptr};
   hazptr_obj* tail_{nullptr};
-  size_t rcount_{0};
-  size_t threshold_{DefaultThreshold};
+  int rcount_{0};
+  int threshold_{DefaultThreshold};
 
  public:
   hazptr_obj_batch() {}
-  hazptr_obj_batch(hazptr_obj* head, hazptr_obj* tail, size_t rcount)
+  hazptr_obj_batch(hazptr_obj* head, hazptr_obj* tail, int rcount)
       : head_(head), tail_(tail), rcount_(rcount) {}
 
   ~hazptr_obj_batch() {
@@ -1135,7 +1135,7 @@ class hazptr_obj_batch {
     }
   }
 
-  void set_threshold(size_t thresh) {
+  void set_threshold(int thresh) {
     threshold_ = thresh;
   }
 
index 5c71b34eefb0289ca81b4b79efadc38a64d4be2c..21df54e6bab443cd2a20973bbf577781021e6a89 100644 (file)
@@ -80,6 +80,9 @@ class hazptr_domain {
   std::atomic<hazptr_obj*> retired_ = {nullptr};
   std::atomic<int> hcount_ = {0};
   std::atomic<int> rcount_ = {0};
+  /* Using signed int for rcount_ because it may transiently be
+   * negative.  Using signed int for all integer variables that may be
+   * involved in calculations related to the value of rcount_. */
 
   void objRetire(hazptr_obj*);
   hazptr_rec* hazptrAcquire();