]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rados/client: fix waiting on the condition variable more efficient. 9939/head
authorYan Jun <yan.jun8@zte.com.cn>
Mon, 27 Jun 2016 04:28:25 +0000 (12:28 +0800)
committerYan Jun <yan.jun8@zte.com.cn>
Tue, 28 Jun 2016 11:40:02 +0000 (19:40 +0800)
Maybe we can simply use "cond.Wait" if timeout is zero, so
that it wait and sleep forever until being waked up by
cond.Signal, which seems to be more efficient.

Signed-off-by: Yan Jun <yan.jun8@zte.com.cn>
src/librados/RadosClient.cc

index b731c80f0f11b249ac7737a1d0f6c4457e0ed3cf..97639fb60c9a6bf473e10a39dbe4ddb35c84eeb1 100644 (file)
@@ -516,7 +516,7 @@ int librados::RadosClient::wait_for_osdmap()
   bool need_map = false;
   objecter->with_osdmap([&](const OSDMap& o) {
       if (o.get_epoch() == 0) {
-       need_map = true;
+        need_map = true;
       }
     });
 
@@ -527,25 +527,21 @@ int librados::RadosClient::wait_for_osdmap()
     if (cct->_conf->rados_mon_op_timeout > 0)
       timeout.set_from_double(cct->_conf->rados_mon_op_timeout);
 
-    bool wait_forever = false;
-    if (timeout.is_zero()) {
-      // we'll going to wait forever, but wake up every 1 seconds,
-      // e.g., to avoid cpu burning.
-      wait_forever = true;
-      timeout = utime_t(1, 0);
-    }
-
     if (objecter->with_osdmap(std::mem_fn(&OSDMap::get_epoch)) == 0) {
       ldout(cct, 10) << __func__ << " waiting" << dendl;
       utime_t start = ceph_clock_now(cct);
       while (objecter->with_osdmap(std::mem_fn(&OSDMap::get_epoch)) == 0) {
-       cond.WaitInterval(cct, lock, timeout);
-       utime_t elapsed = ceph_clock_now(cct) - start;
-       if (!wait_forever && elapsed > timeout) {
-         lderr(cct) << "timed out waiting for first osdmap from monitors"
-                    << dendl;
-         return -ETIMEDOUT;
-       }
+        if (timeout.is_zero()) {
+          cond.Wait(lock);
+        } else {
+          cond.WaitInterval(cct, lock, timeout);
+          utime_t elapsed = ceph_clock_now(cct) - start;
+          if (elapsed > timeout) {
+            lderr(cct) << "timed out waiting for first osdmap from monitors"
+                       << dendl;
+            return -ETIMEDOUT;
+          }
+        }
       }
       ldout(cct, 10) << __func__ << " done waiting" << dendl;
     }