All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yu Ning <ning.yu@canonical.com>
To: Ian Kent <raven@themaw.net>
Cc: autofs <autofs@vger.kernel.org>, Yu Ning <ning.yu@ubuntu.com>
Subject: [PATCH v3 2/3] autofs-5.1.1 - use monotonic clock for pthread cond timed wait.
Date: Thu, 17 Sep 2015 11:48:52 +0800	[thread overview]
Message-ID: <1442461733-22907-2-git-send-email-ning.yu@ubuntu.com> (raw)
In-Reply-To: <1442461733-22907-1-git-send-email-ning.yu@ubuntu.com>

The default PTHREAD_COND_INITIALIZER initializer uses realtime clock,
we need to switch to use the monotic clock.

Signed-off-by: Yu Ning <ning.yu@ubuntu.com>
---
 lib/alarm.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/alarm.c b/lib/alarm.c
index 65a80ae..5b98b2d 100755
--- a/lib/alarm.c
+++ b/lib/alarm.c
@@ -23,7 +23,7 @@ struct alarm {
 };
 
 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+static pthread_cond_t cond;
 static LIST_HEAD(alarms);
 
 #define alarm_lock() \
@@ -212,6 +212,7 @@ int alarm_start_handler(void)
 	pthread_t thid;
 	pthread_attr_t attrs;
 	pthread_attr_t *pattrs = &attrs;
+	pthread_condattr_t condattrs;
 	int status;
 
 	status = pthread_attr_init(pattrs);
@@ -224,8 +225,18 @@ int alarm_start_handler(void)
 #endif
 	}
 
+	status = pthread_condattr_init(&condattrs);
+	if (status)
+		fatal(status);
+
+	pthread_condattr_setclock(&condattrs, CLOCK_MONOTONIC);
+	pthread_cond_init(&cond, &condattrs);
+
 	status = pthread_create(&thid, pattrs, alarm_handler, NULL);
 
+	pthread_condattr_destroy(&condattrs);
+	pthread_condattr_destroy(&cond);
+
 	if (pattrs)
 		pthread_attr_destroy(pattrs);
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe autofs" in

  reply	other threads:[~2015-09-17  3:48 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-16  8:29 Mount point not auto unmounted after system date/time change Ning Yu
2015-09-16  8:45 ` Ning Yu
2015-09-16  9:16   ` Ian Kent
2015-09-16 10:28     ` Ning Yu
2015-09-16 10:43       ` Ian Kent
2015-09-16 11:02         ` Ning Yu
2015-09-16 11:21           ` Ian Kent
2015-09-17  3:48             ` [PATCH v3 1/3] autofs-5.1.1 - use clock_gettime() instead of gettimeofday() Yu Ning
2015-09-17  3:48               ` Yu Ning [this message]
2015-09-17  6:49                 ` [PATCH v3 2/3] autofs-5.1.1 - use monotonic clock for pthread cond timed wait Ian Kent
2015-09-17  7:19                   ` Ning Yu
2015-09-17  8:39                     ` Ian Kent
2015-09-17  9:12                       ` Ning Yu
2015-09-18  1:36                         ` Ian Kent
2015-09-18  7:16                           ` [PATCH v5 1/3] autofs-5.1.1 - use clock_gettime() instead of gettimeofday() Yu Ning
2015-09-18  7:16                             ` [PATCH v5 2/3] autofs-5.1.1 - use monotonic clock for pthread cond timed wait Yu Ning
2015-09-18  7:16                             ` [PATCH v5 3/3] autofs-5.1.1 - use monotonic clock instead of time() Yu Ning
2015-09-18  7:20                           ` [PATCH v3 2/3] autofs-5.1.1 - use monotonic clock for pthread cond timed wait Ning Yu
2015-09-17  3:48               ` [PATCH v3 3/3] autofs-5.1.1 - use monotonic clock instead of time() Yu Ning
2015-09-17  7:04                 ` Ian Kent
2015-09-17  7:16                   ` Ian Kent
2015-09-17  7:34                     ` Ning Yu
2015-09-17  4:02             ` Mount point not auto unmounted after system date/time change Ning Yu
2015-09-17  4:09               ` [PATCH v4 1/3] autofs-5.1.1 - use clock_gettime() instead of gettimeofday() Yu Ning
2015-09-17  4:09                 ` [PATCH v4 2/3] autofs-5.1.1 - use monotonic clock for pthread cond timed wait Yu Ning
2015-09-17  4:09                 ` [PATCH v4 3/3] autofs-5.1.1 - use monotonic clock instead of time() Yu Ning
2015-09-17  4:17               ` Mount point not auto unmounted after system date/time change Ning Yu
2015-09-17  6:07                 ` Ian Kent
2015-09-17  6:05               ` Ian Kent
2015-09-16 10:30     ` Ning Yu
2015-09-16 10:30     ` Ning Yu
2015-09-16 10:30     ` Ning Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1442461733-22907-2-git-send-email-ning.yu@ubuntu.com \
    --to=ning.yu@canonical.com \
    --cc=autofs@vger.kernel.org \
    --cc=ning.yu@ubuntu.com \
    --cc=raven@themaw.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.