From patchwork Mon Jun 3 12:15:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Crowe X-Patchwork-Id: 32968 Received: (qmail 119249 invoked by alias); 3 Jun 2019 12:16:15 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 119239 invoked by uid 89); 3 Jun 2019 12:16:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 spammy=H*r:smtp, HX-Languages-Length:1210, HContent-Transfer-Encoding:8bit X-HELO: avasout02.plus.net X-CM-Score: 0.00 From: Mike Crowe To: libc-alpha@sourceware.org Cc: Mike Crowe Subject: [PATCH v1 1/4] support: Add xclock_now helper function. Date: Mon, 3 Jun 2019 13:15:52 +0100 Message-Id: <8d0cf9eafcb53a98f684feffe54b78057fa9d1df.1559564077.git-series.mac@mcrowe.com> In-Reply-To: References: MIME-Version: 1.0 It's easier to read and write tests with: const struct timespec ts = xclock_now(CLOCK_REALTIME); than struct timespec ts; xclock_gettime(CLOCK_REALTIME, &ts); * support/xtime.h: Add xclock_now() helper function. Reviewed-by: Adhemerval Zanella --- ChangeLog | 4 ++++ support/xtime.h | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/ChangeLog b/ChangeLog index 2f5deee..abb958d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2019-05-30 Mike Crowe + + * support/xtime.h: Add xclock_now() helper function. + 2019-05-27 Mike Crowe * NEWS: Mention new pthread_cond_clockwait, diff --git a/support/xtime.h b/support/xtime.h index 68af1a5..6e19ce1 100644 --- a/support/xtime.h +++ b/support/xtime.h @@ -28,6 +28,16 @@ __BEGIN_DECLS void xclock_gettime (clockid_t clock, struct timespec *ts); +/* This helper can often simplify tests by avoiding an explicit + variable declaration or allowing that declaration to be const. */ + +static inline struct timespec xclock_now (clockid_t clock) +{ + struct timespec ts; + xclock_gettime (clock, &ts); + return ts; +} + __END_DECLS #endif /* SUPPORT_TIME_H */