]> git.sur5r.net Git - openldap/commitdiff
ITS#6262 fix gettime() regression
authorHoward Chu <hyc@openldap.org>
Wed, 11 Jul 2012 23:53:33 +0000 (16:53 -0700)
committerHoward Chu <hyc@openldap.org>
Wed, 11 Jul 2012 23:53:33 +0000 (16:53 -0700)
Add a mutex in ldap_pvt_gettime(), delete the mutex comment
since it's no longer relevant (and was ignored anyway). This
could only ever affect multi-processor machines.

libraries/libldap/util-int.c

index f451cc541c05fcecb6711ac6ca245fc8c5441ee4..570b296c2e6ae449c6db060af91ea7251d51f211 100644 (file)
@@ -59,6 +59,7 @@ extern int h_errno;
 # include <ldap_pvt_thread.h>
   ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
   ldap_pvt_thread_mutex_t ldap_int_hostname_mutex;
+  static ldap_pvt_thread_mutex_t ldap_int_gettime_mutex;
 
 # if (defined( HAVE_CTIME_R ) || defined( HAVE_REENTRANT_FUNCTIONS)) \
         && defined( CTIME_R_NARGS )
@@ -179,7 +180,6 @@ ldap_pvt_localtime( const time_t *timep, struct tm *result )
 #endif /* !USE_LOCALTIME_R */
 
 /* return a broken out time, with microseconds
- * Must be mutex-protected.
  */
 #ifdef _WIN32
 /* Windows SYSTEMTIME only has 10 millisecond resolution, so we
@@ -202,12 +202,14 @@ ldap_pvt_gettime( struct lutil_tm *tm )
        /* It shouldn't ever go backwards, but multiple CPUs might
         * be able to hit in the same tick.
         */
+       LDAP_MUTEX_LOCK( &ldap_int_gettime_mutex );
        if ( count.QuadPart <= prevCount.QuadPart ) {
                subs++;
        } else {
                subs = 0;
                prevCount = count;
        }
+       LDAP_MUTEX_UNLOCK( &ldap_int_gettime_mutex );
 
        /* We assume Windows has at least a vague idea of
         * when a second begins. So we align our microsecond count
@@ -271,6 +273,7 @@ ldap_pvt_gettime( struct lutil_tm *ltm )
        gettimeofday( &tv, NULL );
        t = tv.tv_sec;
 
+       LDAP_MUTEX_LOCK( &ldap_int_gettime_mutex );
        if ( tv.tv_sec < prevTv.tv_sec
                || ( tv.tv_sec == prevTv.tv_sec && tv.tv_usec <= prevTv.tv_usec )) {
                subs++;
@@ -278,6 +281,7 @@ ldap_pvt_gettime( struct lutil_tm *ltm )
                subs = 0;
                prevTv = tv;
        }
+       LDAP_MUTEX_UNLOCK( &ldap_int_gettime_mutex );
 
        ltm->tm_usub = subs;
 
@@ -606,6 +610,8 @@ void ldap_int_utils_init( void )
 
        ldap_pvt_thread_mutex_init( &ldap_int_hostname_mutex );
 
+       ldap_pvt_thread_mutex_init( &ldap_int_gettime_mutex );
+
 #ifdef HAVE_CYRUS_SASL
        ldap_pvt_thread_mutex_init( &ldap_int_sasl_mutex );
 #endif