On Thu, Jan 8, 2009 at 7:49 AM, Jay Pipes <[email protected]> wrote: > Hi all, > > In working on the temporal data stuff, I ran into a mutex that I believe can > be removed. Since we're trying to be as public as possible about coding > decisions, I'd like some input on a proposed solution. > > The mutex is in the file mysys/my_getsystime.cc, in the following function: > > uint64_t my_micro_time_and_time(time_t *time_arg) > { > #if defined(HAVE_GETHRTIME) > /* > Solaris has a very slow time() call. We optimize this by using the very > fast gethrtime() call and only calling time() every 1/2 second > */ > > #define DELTA_FOR_SECONDS 500000000LL /* Half a second */ > > static hrtime_t prev_gethrtime= 0; > static time_t cur_time= 0; > hrtime_t cur_gethrtime; > > pthread_mutex_lock(&THR_LOCK_time); > cur_gethrtime= gethrtime(); > if ((cur_gethrtime - prev_gethrtime) > DELTA_FOR_SECONDS) > { > cur_time= time(0); > prev_gethrtime= cur_gethrtime; > } > *time_arg= cur_time; > pthread_mutex_unlock(&THR_LOCK_time); > return cur_gethrtime/1000; > #else > <snip> > #endif /* defined(HAVE_GETHRTIME) */ > } > > I've cut out the non-Solaris/HPUX part of the function as it does not need a > mutex (it has a separate issue, but that's a different story...). > > My proposed solution is to move this code out of mysys/ and up as a member > method of the Session class where no mutex would be needed. > > According to ack-grep, Session is the only one which calls it anyway. > > Here are my two questions: > > 1) Is the gettimeofday() function reliable and fast on Solaris? If so, > there really is no need to use gethrtime() here...
On some Linux kernels that I have used gettimeofday() fails intermittently for reasons other than those listed in the man page. The code in my_getsystime.c does not check the return value for the getimeofday() call. > > 2) Is the proposed solution (of moving the above code out of mysys and into > Session) a good idea? > > Cheers, > > -jay > > _______________________________________________ > Mailing list: https://launchpad.net/~drizzle-discuss > Post to : [email protected] > Unsubscribe : https://launchpad.net/~drizzle-discuss > More help : https://help.launchpad.net/ListHelp > -- Mark Callaghan [email protected] _______________________________________________ Mailing list: https://launchpad.net/~drizzle-discuss Post to : [email protected] Unsubscribe : https://launchpad.net/~drizzle-discuss More help : https://help.launchpad.net/ListHelp

