st-1.5.0 patch

[email protected] Mon, 10 May 2004 23:34:58 +0000
Newsgroups gmane.comp.lib.state-threads.devel
Message-ID <051020042334.20509.40A011A200093D4F0000501D2200735446FF978C9A919A@comcast.net>
--NextPart_Webmail_9m3u9jl4l_20509_1084232098
Content-Type: text/plain
Content-Transfer-Encoding: 8bit

A small patch to add a new function allowing to replace the default
implementation of st_utime() with the user-provided one.
On Linux/FreeBSD/etc. st_utime() is implemented via gettimeofday()
(a syscall). Sometimes it's desirable to use hi-res time function
implemented more efficiently, e.g. by reading CPU cycle counter.
This patch adds ability to plug in user's implementation of st_utime().


--NextPart_Webmail_9m3u9jl4l_20509_1084232098
Content-Type: application/octet-stream; name="st150.patch"
Content-Transfer-Encoding: 7bit

--- ../st-1.5.0/sync.c	Sun Jan 11 14:18:15 2004
+++ sync.c	Fri May  7 18:19:51 2004
@@ -47,6 +47,9 @@
 
 extern time_t _st_curr_time;
 extern st_utime_t _st_last_tset;
+extern int _st_active_count;
+
+static st_utime_t (*_st_utime)(void) = NULL;
 
 
 /*****************************************
@@ -55,11 +58,28 @@
 
 st_utime_t st_utime(void)
 {
+  if (_st_utime == NULL) {
 #ifdef MD_GET_UTIME
-  MD_GET_UTIME();
+    MD_GET_UTIME();
 #else
 #error Unknown OS
 #endif
+  }
+
+  return (*_st_utime)();
+}
+
+
+int st_set_utime_function(st_utime_t (*func)(void))
+{
+  if (_st_active_count) {
+    errno = EINVAL;
+    return -1;
+  }
+
+  _st_utime = func;
+
+  return 0;
 }
 
 
--- ../st-1.5.0/public.h	Thu Mar 28 21:09:08 2002
+++ public.h	Mon May 10 15:24:40 2004
@@ -96,6 +96,7 @@
 extern st_thread_t st_thread_create(void *(*start)(void *arg), void *arg,
 				    int joinable, int stack_size);
 extern int st_randomize_stacks(int on);
+extern int st_set_utime_function(st_utime_t (*func)(void));
 
 extern st_utime_t st_utime(void);
 extern st_utime_t st_utime_last_clock(void);
--- ../st-1.5.0/docs/reference.html	Fri Oct 25 19:54:20 2002
+++ docs/reference.html	Mon May 10 16:11:04 2004
@@ -61,6 +61,7 @@
 <P>
 <DL><DD><A HREF=#utime_t><B>st_utime_t</B> type</A></DD></DL>
 <DL><DD><A HREF=#utime>st_utime()</A></DD></DL>
+<DL><DD><A HREF=#utime_func>st_set_utime_function()</A></DD></DL>
 <DL><DD><A HREF=#timecache_set>st_timecache_set()</A></DD></DL>
 <DL><DD><A HREF=#time>st_time()</A></DD></DL>
 <P>
@@ -1217,6 +1218,7 @@
 <P>
 <DL>
 <DD><A HREF=#utime>st_utime()</A></DD>
+<DD><A HREF=#utime_func>st_set_utime_function()</A></DD>
 <DD><A HREF=#timecache_set>st_timecache_set()</A></DD>
 <DD><A HREF=#time>st_time()</A></DD>
 </DL>
@@ -1247,6 +1249,42 @@
 This function returns the current high-resolution time. Time is expressed as
 microseconds since some arbitrary time in the past. It is not correlated in
 any way to the time of day (see <A HREF=#utime_t><B>st_utime_t</B></A>).
+<P>
+<HR>
+<P>
+<A NAME="utime_func">
+<H4>st_set_utime_function()</H4>
+</A>
+Set high-resolution time function.
+<P>
+<H5>Syntax</H5>
+
+<PRE>
+#include &lt;st.h&gt;
+
+int st_set_utime_function(st_utime_t (*func)(void));
+</PRE>
+<P>
+<H5>Parameters</H5>
+<TT>st_set_utime_function()</TT> has the following parameters:<P>
+<TT>func</TT><P>
+This function will be called to get high-resolution time instead of the
+default <A HREF=#utime>st_utime()</A> function. It must return
+number of microseconds since some arbitrary time in the past.
+<P>
+<H5>Returns</H5>
+Upon successful completion, a value of <TT>0</TT> is returned.
+Otherwise, a value of <TT>-1</TT> is returned and <TT>errno</TT> is set
+to <TT>EINVAL</TT> to indicate the error.
+<P>
+<H5>Description</H5>
+This function may be called to replace the default implementation of the
+<A HREF=#utime>st_utime()</A> function.  It must be called before the ST
+library has been initialized (see <A HREF=#st_init>st_init()</A>).
+The user-provided function <TT>func</TT> will be invoked whenever
+<A HREF=#utime>st_utime()</A> is called to obtain current high-resolution time.
+Replacing default implementation may be useful, for example, for taking
+advantage of high performance CPU cycle counters.
 <P>
 <HR>
 <P>

--NextPart_Webmail_9m3u9jl4l_20509_1084232098--


-------------------------------------------------------
This SF.Net email is sponsored by Sleepycat Software
Learn developer strategies Cisco, Motorola, Ericsson & Lucent use to 
deliver higher performing products faster, at low TCO.
http://www.sleepycat.com/telcomwpreg.php?From=osdnemail3