From: Adam C. Emerson Date: Mon, 14 Sep 2015 16:19:13 +0000 (-0400) Subject: time: Overload for std:chrono in Cond::TimedWait X-Git-Tag: v10.0.3~194^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=08f26766b3a52f1178c3a8e04a18cea761040bc3;p=ceph.git time: Overload for std:chrono in Cond::TimedWait Signed-off-by: Adam C. Emerson --- diff --git a/src/common/Cond.h b/src/common/Cond.h index 46fdf159112..c0301ea8ac9 100644 --- a/src/common/Cond.h +++ b/src/common/Cond.h @@ -1,4 +1,4 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system @@ -7,9 +7,9 @@ * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software + * License version 2.1, as published by the Free Software * Foundation. See file COPYING. - * + * */ @@ -17,13 +17,14 @@ #define CEPH_COND_H #include - -#include "Mutex.h" -#include "Clock.h" +#include #include "include/Context.h" -#include +#include "common/ceph_time.h" +#include "common/Mutex.h" +#include "common/Clock.h" + class Cond { // my bits @@ -73,12 +74,27 @@ class Cond { return r; } + int WaitInterval(CephContext *cct, Mutex &mutex, utime_t interval) { utime_t when = ceph_clock_now(cct); when += interval; return WaitUntil(mutex, when); } + template + int WaitInterval(CephContext *cct, Mutex &mutex, Duration interval) { + ceph::real_time when(ceph::real_clock::now(cct)); + when += interval; + + struct timespec ts = ceph::real_clock::to_timespec(when); + + mutex._pre_unlock(); + int r = pthread_cond_timedwait(&_c, &mutex._m, &ts); + mutex._post_lock(); + + return r; + } + int SloppySignal() { int r = pthread_cond_broadcast(&_c); return r;