Roy Lyseng wrote:
Jay Pipes 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...
2) Is the proposed solution (of moving the above code out of mysys and
into Session) a good idea?
IMHO, this belongs in a utility library, even though it is used only one
place, because
1) it is a (time) utility function, and
2) it is platform dependent, and
3) it is not a logical part of a Session.
Actually, it is...the Session needs to be able to have a reliable and
accurate start_time member variable set to the results of
gettimeofday(). Trond benchmarked gettimeofday() versus gethrtime()
this evening and found that gettimeofday() outperformed gethrtime()
easily, in both threaded and non-threaded environments on Solaris, and
therefore we will use gettimeofday() in the initialization of Session in
order to get a start_time value for the session.
The mutex, although unwanted, does not by itself add complexity, so I
would say that the change is not very urgent.
True. This is just something I stumbled upon while working on the
temporal data stuff.
However, the interface does not look very intuitive. A good review of
all related interfaces could be useful at some point in time...
Yep, which is actually what this is all about. Here was an interface
that wasn't particularly intuitive, used platform-dependent stuff when
it didn't need to, and could be moved into the Session. Reviewed. :)
Cheers!
Jay
Thanks,
Roy
_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help : https://help.launchpad.net/ListHelp
_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help : https://help.launchpad.net/ListHelp