summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Bostic <keith@wiredtiger.com>2012-10-18 10:08:58 +0000
committerKeith Bostic <keith@wiredtiger.com>2012-10-19 08:58:51 +0000
commit2af6f73b4b4d6a127fcbd4546f4e1e96d322df0c (patch)
tree591082b2d61f8566e32120333653b97a365b86ce
parentbf1cd98682b3eb44e4a2794fe2a4bd8c264a4957 (diff)
downloadmongo-2af6f73b4b4d6a127fcbd4546f4e1e96d322df0c.tar.gz
__wt_cond_wait() requires struct timespec in order to call
pthread_cond_timedwait(); if we require struct timespec, quit passing around seconds/nano-seconds, pass around a struct timespec, and call __wt_epoch() from __wt_cond_wait(), don't have two places that know OS X doesn't yet support clock_gettime().
-rw-r--r--src/include/extern.h6
-rw-r--r--src/meta/meta_ckpt.c4
-rw-r--r--src/os_posix/os_mtx.c46
-rw-r--r--src/os_posix/os_time.c20
4 files changed, 38 insertions, 38 deletions
diff --git a/src/include/extern.h b/src/include/extern.h
index ded49ce3632..fe4e1a5d03c 100644
--- a/src/include/extern.h
+++ b/src/include/extern.h
@@ -875,7 +875,7 @@ extern int __wt_cond_alloc(WT_SESSION_IMPL *session,
WT_CONDVAR **condp);
extern void __wt_cond_wait(WT_SESSION_IMPL *session,
WT_CONDVAR *cond,
- uint64_t usecs);
+ long usecs);
extern void __wt_cond_signal(WT_SESSION_IMPL *session, WT_CONDVAR *cond);
extern int __wt_cond_destroy(WT_SESSION_IMPL *session, WT_CONDVAR *cond);
extern int __wt_rwlock_alloc( WT_SESSION_IMPL *session,
@@ -913,9 +913,7 @@ extern int __wt_thread_create(pthread_t *tidret,
void *(*func)(void *),
void *arg);
extern int __wt_thread_join(pthread_t tid);
-extern int __wt_epoch(WT_SESSION_IMPL *session,
- uintmax_t *secp,
- uintmax_t *nsecp);
+extern int __wt_epoch(WT_SESSION_IMPL *session, struct timespec *tsp);
extern void __wt_yield(void);
extern int __wt_struct_check(WT_SESSION_IMPL *session,
const char *fmt,
diff --git a/src/meta/meta_ckpt.c b/src/meta/meta_ckpt.c
index c0aa76e92fe..1588711e0ec 100644
--- a/src/meta/meta_ckpt.c
+++ b/src/meta/meta_ckpt.c
@@ -357,6 +357,7 @@ int
__wt_meta_ckptlist_set(
WT_SESSION_IMPL *session, const char *fname, WT_CKPT *ckptbase)
{
+ struct timespec ts;
WT_CKPT *ckpt;
WT_DECL_RET;
WT_ITEM *buf;
@@ -407,7 +408,8 @@ __wt_meta_ckptlist_set(
if (F_ISSET(ckpt, WT_CKPT_ADD))
ckpt->order = ++maxorder;
- WT_ERR(__wt_epoch(session, &ckpt->sec, NULL));
+ WT_ERR(__wt_epoch(session, &ts));
+ ckpt->sec = (uintmax_t)ts.tv_sec;
}
if (strcmp(ckpt->name, WT_CHECKPOINT) == 0)
WT_ERR(__wt_buf_catfmt(session, buf,
diff --git a/src/os_posix/os_mtx.c b/src/os_posix/os_mtx.c
index 805a8ce4e0f..115894127c1 100644
--- a/src/os_posix/os_mtx.c
+++ b/src/os_posix/os_mtx.c
@@ -46,55 +46,63 @@ err: __wt_free(session, cond);
* Lock a mutex.
*/
void
-__wt_cond_wait(WT_SESSION_IMPL *session, WT_CONDVAR *cond, uint64_t usecs)
+__wt_cond_wait(WT_SESSION_IMPL *session, WT_CONDVAR *cond, long usecs)
{
WT_DECL_RET;
+ int locked;
+
+ locked = 0;
/*
* !!!
* This function MUST handle a NULL session handle.
*/
- if (session != NULL)
+ if (session != NULL) {
+ WT_CSTAT_INCR(session, cond_wait);
+
WT_VERBOSE_VOID(
session, mutex, "lock %s mutex (%p)", cond->name, cond);
+ }
WT_ERR(pthread_mutex_lock(&cond->mtx));
+ locked = 1;
- /*
- * Check pthread_cond_wait() return for EINTR, ETIME and ETIMEDOUT,
- * it's known to return these errors on some systems.
- */
while (cond->locked) {
if (usecs > 0) {
- struct timeval tv;
struct timespec ts;
- gettimeofday(&tv, NULL);
- ts.tv_sec = tv.tv_sec + (tv.tv_usec + usecs) / 1000000;
- ts.tv_nsec = 1000L * ((tv.tv_usec + usecs) % 1000000);
+ WT_ERR(__wt_epoch(session, &ts));
+ ts.tv_nsec += 1000 * usecs;
+ if (ts.tv_nsec > 1000000000) {
+ ++ts.tv_sec;
+ ts.tv_nsec -= 1000000000;
+ }
ret = pthread_cond_timedwait(
&cond->cond, &cond->mtx, &ts);
} else
ret = pthread_cond_wait(&cond->cond, &cond->mtx);
+
+ /*
+ * Check pthread_cond_wait() return for EINTR, ETIME and
+ * ETIMEDOUT, some systems return these errors.
+ */
if (ret != 0 &&
ret != EINTR &&
#ifdef ETIME
ret != ETIME &&
#endif
- ret != ETIMEDOUT) {
- (void)pthread_mutex_unlock(&cond->mtx);
- goto err;
- }
+ ret != ETIMEDOUT)
+ WT_ERR(ret);
}
cond->locked = 1;
- if (session != NULL)
- WT_CSTAT_INCR(session, cond_wait);
- WT_ERR(pthread_mutex_unlock(&cond->mtx));
- return;
+err: if (locked)
+ WT_ERR(pthread_mutex_unlock(&cond->mtx));
+ if (ret == 0)
+ return;
-err: __wt_err(session, ret, "mutex lock failed");
+ __wt_err(session, ret, "mutex lock failed");
__wt_abort(session);
}
diff --git a/src/os_posix/os_time.c b/src/os_posix/os_time.c
index f0c7dd37d74..1a2c72381bb 100644
--- a/src/os_posix/os_time.c
+++ b/src/os_posix/os_time.c
@@ -9,33 +9,25 @@
/*
* __wt_epoch --
- * Return the seconds and nanoseconds since the Epoch.
+ * Return the time since the Epoch.
*/
int
-__wt_epoch(WT_SESSION_IMPL *session, uintmax_t *secp, uintmax_t *nsecp)
+__wt_epoch(WT_SESSION_IMPL *session, struct timespec *tsp)
{
WT_DECL_RET;
#if defined(HAVE_CLOCK_GETTIME)
- struct timespec v;
- WT_SYSCALL_RETRY(clock_gettime(CLOCK_REALTIME, &v), ret);
- if (ret == 0) {
- if (secp != NULL)
- *secp = (uintmax_t)v.tv_sec;
- if (nsecp != NULL)
- *nsecp = (uintmax_t)v.tv_nsec;
+ WT_SYSCALL_RETRY(clock_gettime(CLOCK_REALTIME, tsp), ret);
+ if (ret == 0)
return (0);
- }
WT_RET_MSG(session, ret, "clock_gettime");
#elif defined(HAVE_GETTIMEOFDAY)
struct timeval v;
WT_SYSCALL_RETRY(gettimeofday(&v, NULL), ret);
if (ret == 0) {
- if (secp != NULL)
- *secp = (uintmax_t)v.tv_sec;
- if (nsecp != NULL) /* nanoseconds in a microsecond */
- *nsecp = (uintmax_t)(v.tv_usec * 1000);
+ tsp->tv_sec = v.tv_sec;
+ tsp->tv_nsec = v.tv_usec * 1000;
return (0);
}
WT_RET_MSG(session, ret, "gettimeofday");