portlib for ndb on win32

ooo bzr diff -r1 -pa/:b/ ndb/include/ ndb/src/common/portlib/ |di -X Make
--- a/ndb/include/kernel/ndb_limits.h	2007-08-29 07:25:53 +0000
+++ b/ndb/include/kernel/ndb_limits.h	2007-09-08 11:07:00 +0000
@@ -15,8 +15,8 @@
 
 #ifndef NDB_LIMITS_H
 #define NDB_LIMITS_H
-
-#include <mysql.h>
+#include <my_global.h>
+#include <mysql_com.h>
 
 #define RNIL    0xffffff00
 

--- a/ndb/include/ndb_global.h.in	2007-08-29 07:25:53 +0000
+++ b/ndb/include/ndb_global.h.in	2007-09-06 13:30:48 +0000
@@ -23,7 +23,7 @@
 
 #if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
 #define NDB_WIN32
-#include <winsock2.h>
+#define NDB_WIN
 #define PATH_MAX 256
 #define DIR_SEPARATOR "\\"
 #define MYSQLCLUSTERDIR "c:\\mysql\\mysql-cluster"
@@ -32,6 +32,7 @@
 #pragma warning(disable: 4503 4786)
 #else
 #undef NDB_WIN32
+#undef NDB_WIN
 #define DIR_SEPARATOR "/"
 #endif
 

--- a/ndb/include/ndb_types.h.in	2007-08-29 07:25:53 +0000
+++ b/ndb/include/ndb_types.h.in	2007-09-07 13:53:50 +0000
@@ -20,22 +20,22 @@
 #ifndef NDB_TYPES_H
 #define NDB_TYPES_H
 
-#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(_WIN64)
-#define NDB_SIZEOF_CHARP SIZEOF_CHARP
-#define NDB_SIZEOF_CHAR SIZEOF_CHAR
-#define NDB_SIZEOF_SHORT 2
-#define NDB_SIZEOF_INT SIZEOF_INT
-#define NDB_SIZEOF_LONG SIZEOF_LONG
-#define NDB_SIZEOF_LONG_LONG SIZEOF_LONG_LONG
-typedef unsigned __int64 Uint64;
-typedef   signed __int64 Int64;
-#else
 #define NDB_SIZEOF_CHARP @NDB_SIZEOF_CHARP@
 #define NDB_SIZEOF_CHAR @NDB_SIZEOF_CHAR@
 #define NDB_SIZEOF_INT @NDB_SIZEOF_INT@
 #define NDB_SIZEOF_SHORT @NDB_SIZEOF_SHORT@
 #define NDB_SIZEOF_LONG @NDB_SIZEOF_LONG@
 #define NDB_SIZEOF_LONG_LONG @NDB_SIZEOF_LONG_LONG@
+
+#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(_WIN64)
+typedef unsigned __int64 Uint64;
+typedef   signed __int64 Int64;
+#define ssize_t SSIZE_T 
+#ifndef my_socket_defined
+#define my_socket SOCKET
+#define my_socket_defined
+#endif
+#else
 typedef unsigned long long Uint64;
 typedef   signed long long Int64;
 #endif

--- a/ndb/include/portlib/NdbDaemon.h	2007-08-29 07:25:53 +0000
+++ b/ndb/include/portlib/NdbDaemon.h	2007-09-08 06:00:59 +0000
@@ -31,6 +31,10 @@
 extern int
 NdbDaemon_Make(const char* lockfile, const char* logfile, unsigned flags);
 
+typedef int(*F)(void*);
+extern int
+NdbDaemonService_Make(const char*argv0,const char* lockfile, const char* logfile, unsigned flags, F restofmain);
+
 /*
  * Test if the daemon is running (file is locked).
  * lockfile     the "pid file"

--- a/ndb/include/portlib/NdbMutex.h	2007-08-29 07:25:53 +0000
+++ b/ndb/include/portlib/NdbMutex.h	2007-09-08 13:35:49 +0000
@@ -18,11 +18,6 @@
 
 #include <ndb_global.h>
 
-#ifdef NDB_WIN32
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#endif
-
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -30,10 +25,8 @@
 #if defined NDB_OSE || defined NDB_SOFTOSE
 #include <ose.h>
 typedef SEMAPHORE NdbMutex;
-#elif defined NDB_WIN32
-typedef CRITICAL_SECTION NdbMutex;
 #else
-#include <pthread.h>
+#include <my_pthread.h>
 typedef pthread_mutex_t NdbMutex;
 #endif
 

--- a/ndb/include/portlib/NdbTCP.h	2007-08-29 07:25:53 +0000
+++ b/ndb/include/portlib/NdbTCP.h	2007-09-06 13:30:48 +0000
@@ -30,7 +30,7 @@
 #define NDB_NONBLOCK FNDELAY
 #define NDB_SOCKET_TYPE int
 #define NDB_INVALID_SOCKET -1
-#define _NDB_CLOSE_SOCKET(x) close(x)
+#define _NDB_CLOSE_SOCKET(x) socket_close(x)
 
 /**
  * socklen_t not defined in the header files of OSE 
@@ -41,12 +41,6 @@
 
 #elif defined NDB_WIN32
 
-/**
- * Include files needed
- */
-#include <winsock2.h>
-#include <ws2tcpip.h>
-
 #define InetErrno WSAGetLastError()
 #define EWOULDBLOCK WSAEWOULDBLOCK
 #define NDB_SOCKET_TYPE SOCKET

--- a/ndb/include/util/NdbOut.hpp	2007-08-29 07:25:53 +0000
+++ b/ndb/include/util/NdbOut.hpp	2007-09-06 13:30:48 +0000
@@ -84,6 +84,9 @@
   int isHex;
 };
 
+typedef int(*NdbOutF)(char*);
+extern NdbOutF ndbout_svc;
+
 inline NdbOut& NdbOut::operator<<(NdbOut& (* _f)(NdbOut&)) {
   (* _f)(*this); 
   return * this; 

--- a/ndb/src/common/portlib/NdbCondition.c	2007-08-29 07:25:53 +0000
+++ b/ndb/src/common/portlib/NdbCondition.c	2007-09-16 12:55:19 +0000
@@ -26,8 +26,6 @@
   pthread_cond_t cond;
 };
 
-
-
 struct NdbCondition* 
 NdbCondition_Create(void)
 {
@@ -71,30 +69,8 @@
   
   if (p_cond == NULL || p_mutex == NULL)
     return 1;
-  
-#ifdef HAVE_CLOCK_GETTIME
-  clock_gettime(CLOCK_REALTIME, &abstime);
-#else
-  {
-    struct timeval tick_time;
-    gettimeofday(&tick_time, 0);
-    abstime.tv_sec  = tick_time.tv_sec;
-    abstime.tv_nsec = tick_time.tv_usec * 1000;
-  }
-#endif
-
-  if(msecs >= 1000){
-    secs  = msecs / 1000;
-    msecs = msecs % 1000;
-  }
-
-  abstime.tv_sec  += secs;
-  abstime.tv_nsec += msecs * 1000000;
-  if (abstime.tv_nsec >= 1000000000) {
-    abstime.tv_sec  += 1;
-    abstime.tv_nsec -= 1000000000;
-  }
-    
+
+  set_timespec_nsec(abstime,msecs*1000000)    ;
   result = pthread_cond_timedwait(&p_cond->cond, p_mutex, &abstime);
   
   return result;
@@ -121,7 +97,7 @@
     return 1;
 
   result = pthread_cond_broadcast(&p_cond->cond);
-                             
+  
   return result;
 }
 

--- a/ndb/src/common/portlib/NdbConfig.c	2007-08-29 07:25:53 +0000
+++ b/ndb/src/common/portlib/NdbConfig.c	2007-09-09 09:06:04 +0000
@@ -79,7 +79,8 @@
   if (node_id > 0)
     basestring_snprintf(tmp_buf, sizeof(tmp_buf), "ndb_%u", node_id);
   else
-    basestring_snprintf(tmp_buf, sizeof(tmp_buf), "ndb_pid%u", getpid());
+    basestring_snprintf(tmp_buf, sizeof(tmp_buf), "ndb_pid%u",
+                        NdbHost_GetProcessId());
   tmp_buf[sizeof(tmp_buf)-1]= 0;
 
   buf= NdbConfig_AllocHomePath(len+strlen(tmp_buf));

--- a/ndb/src/common/portlib/NdbDaemon.c	2007-08-29 07:25:53 +0000
+++ b/ndb/src/common/portlib/NdbDaemon.c	2007-09-09 09:06:04 +0000
@@ -21,78 +21,101 @@
 int NdbDaemon_ErrorCode = 0;
 char NdbDaemon_ErrorText[NdbDaemon_ErrorSize] = "";
 
+#ifdef NDB_WIN32
+#define F_ULOCK _LK_UNLCK
+#define F_LOCK _LK_LOCK
+#define F_TLOCK _LK_NBLCK
+#define lockf(fd,mode,size) _locking((fd),(mode),(size))
+#endif
+
+int restofmake(void*);
+struct Dstate 
+{ int lockfd,logfd;
+  const char*lockfile,*logfile;
+  F restofmain;
+} dstate;
+
+int nothing(void*p){return 0; }
+
 int
 NdbDaemon_Make(const char* lockfile, const char* logfile, unsigned flags)
+{ return NdbDaemonService_Make("",lockfile,logfile,flags,nothing); }
+
+int
+NdbDaemonService_Make(const char*argv0,const char* lockfile, const char* logfile, unsigned flags, F restofmain)
 {
-  int lockfd = -1, logfd = -1, n;
+  int n;
   char buf[64];
-
+  dstate.lockfd = -1, dstate.logfd = -1;
+  dstate.lockfile=lockfile, dstate.logfile=logfile;
+  dstate.restofmain=restofmain;
   (void)flags; /* remove warning for unused parameter */
 
   /* Check that we have write access to lock file */
-  assert(lockfile != NULL);
-  lockfd = open(lockfile, O_CREAT|O_RDWR, 0644);
-  if (lockfd == -1) {
+  assert(dstate.lockfile != NULL);
+  fopen(dstate.lockfile,"w");
+  dstate.lockfd = open(dstate.lockfile, O_CREAT|O_RDWR, 0644);
+  if (dstate.lockfd == -1) {
     NdbDaemon_ErrorCode = errno;
-    snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
-	"%s: open for write failed: %s", lockfile, strerror(errno));
+    basestring_snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
+	"%s: open for write failed: %s", dstate.lockfile, strerror(errno));
+
     return -1;
   }
   /* Read any old pid from lock file */
   buf[0] = 0;
-  n = read(lockfd, buf, sizeof(buf));
+  n = read(dstate.lockfd, buf, sizeof(buf));
   if (n < 0) {
     NdbDaemon_ErrorCode = errno;
-    snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
-	"%s: read failed: %s", lockfile, strerror(errno));
+    basestring_snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
+	"%s: read failed: %s", dstate.lockfile, strerror(errno));
     return -1;
   }
   NdbDaemon_DaemonPid = atol(buf);
-  if (lseek(lockfd, 0, SEEK_SET) == -1) {
+  if (lseek(dstate.lockfd, 0, SEEK_SET) == -1) {
     NdbDaemon_ErrorCode = errno;
-    snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
-	"%s: lseek failed: %s", lockfile, strerror(errno));
+    basestring_snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
+	"%s: lseek failed: %s", dstate.lockfile, strerror(errno));
     return -1;
   }
 #ifdef F_TLOCK
   /* Test for lock before becoming daemon */
-  if (lockf(lockfd, F_TLOCK, 0) == -1) 
+  if (lockf(dstate.lockfd, F_TLOCK, 0) == -1) 
   {
     if (errno == EACCES || errno == EAGAIN) {   /* results may vary */
-      snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
-	       "%s: already locked by pid=%ld", lockfile, NdbDaemon_DaemonPid);
+      basestring_snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
+	       "%s: already locked by pid=%ld", dstate.lockfile, NdbDaemon_DaemonPid);
       return -1;
     }
     NdbDaemon_ErrorCode = errno;
-    snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
-        "%s: lock test failed: %s", lockfile, strerror(errno));
+    basestring_snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
+        "%s: lock test failed: %s", dstate.lockfile, strerror(errno));
     return -1;
   }
 #endif
   /* Test open log file before becoming daemon */
-  if (logfile != NULL) {
-    logfd = open(logfile, O_CREAT|O_WRONLY|O_APPEND, 0644);
-    if (logfd == -1) {
+  if (dstate.logfile != NULL) {
+    dstate.logfd = open(dstate.logfile, O_CREAT|O_WRONLY|O_APPEND, 0644);
+    if (dstate.logfd == -1) {
       NdbDaemon_ErrorCode = errno;
-      snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
-	  "%s: open for write failed: %s", logfile, strerror(errno));
+      basestring_snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
+	  "%s: open for write failed: %s", dstate.logfile, strerror(errno));
       return -1;
     }
   }
 #ifdef F_TLOCK
-  if (lockf(lockfd, F_ULOCK, 0) == -1) 
+  if (lockf(dstate.lockfd, F_ULOCK, 0) == -1) 
   {
-    snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
-	     "%s: fail to unlock", lockfile);
+    basestring_snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
+	     "%s: fail to unlock", dstate.lockfile);
     return -1;
   }
 #endif
-  
-  /* Fork */
+#ifndef NDB_WIN32
   n = fork();
   if (n == -1) {
     NdbDaemon_ErrorCode = errno;
-    snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
+    basestring_snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
 	"fork failed: %s", strerror(errno));
     return -1;
   }
@@ -100,66 +123,67 @@
   if (n != 0) {
     exit(0);
   }
-  /* Running in child process */
-  NdbDaemon_DaemonPid = getpid();
-  /* Lock the lock file (likely to succeed due to test above) */
-  if (lockf(lockfd, F_LOCK, 0) == -1) {
-    NdbDaemon_ErrorCode = errno;
-    snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
-	"%s: lock failed: %s", lockfile, strerror(errno));
-    return -1;
+#endif
+  {
+    char buf[64];int n;
+    /* Running in child process */
+    NdbDaemon_DaemonPid = NdbHost_GetProcessId();
+    /* Lock the lock file (likely to succeed due to test above) */
+    if (lockf(dstate.lockfd, F_LOCK, 0) == -1) {
+	NdbDaemon_ErrorCode = errno;
+	basestring_snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
+	    "%s: lock failed: %s", dstate.lockfile, strerror(errno));
+	return -1;
   }
+#ifndef NDB_WIN32
   /* Become process group leader */
   if (setsid() == -1) {
     NdbDaemon_ErrorCode = errno;
-    snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
+    basestring_snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
 	"setsid failed: %s", strerror(errno));
     return -1;
   }
   /* Write pid to lock file */
-  if (ftruncate(lockfd, 0) == -1) {
+  if (ftruncate(dstate.lockfd, 0) == -1) {
+#else
+  if (_chsize(dstate.lockfd, 0) == -1) {
+#endif
     NdbDaemon_ErrorCode = errno;
-    snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
-	"%s: ftruncate failed: %s", lockfile, strerror(errno));
+    basestring_snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
+	"%s: ftruncate failed: %s", dstate.lockfile, strerror(errno));
     return -1;
   }
   sprintf(buf, "%ld\n", NdbDaemon_DaemonPid);
   n = strlen(buf);
-  if (write(lockfd, buf, n) != n) {
+  if (write(dstate.lockfd, buf, n) != n) {
     NdbDaemon_ErrorCode = errno;
-    snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
-	"%s: write failed: %s", lockfile, strerror(errno));
+    basestring_snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
+	"%s: write failed: %s", dstate.lockfile, strerror(errno));
     return -1;
   }
   /* Do input/output redirections (assume fd 0,1,2 not in use) */
   close(0);
+#ifndef NDB_WIN32
   open("/dev/null", O_RDONLY);
-  if (logfile != 0) {
-    dup2(logfd, 1);
-    dup2(logfd, 2);
-    close(logfd);
+#else
+  open("nul:", O_RDONLY);
+#endif
+  if (dstate.logfile != 0) {
+    dup2(dstate.logfd, 1);
+    dup2(dstate.logfd, 2);
+    close(dstate.logfd);
   }
   /* Success */
-  return 0;
-}
-
-#if 0
-int
-NdbDaemon_Make(const char* lockfile, const char* logfile, unsigned flags)
-{
-  /* Fail */
-  snprintf(NdbDaemon_ErrorText, NdbDaemon_ErrorSize,
-	   "Daemon mode not implemented");
-  return -1;
-}
-#endif
+  return dstate.restofmain(0);
+  }
+}
 
 #ifdef NDB_DAEMON_TEST
-
+int daemontest(void*p){return p==0;}
 int
-main()
+main(int argc, char**argv)
 {
-  if (NdbDaemon_Make("test.pid", "test.log", 0) == -1) {
+  if (NdbDaemon_Make(argv[0],"test.pid", "test.log", 0,daemontest) == -1) {
     fprintf(stderr, "NdbDaemon_Make: %s\n", NdbDaemon_ErrorText);
     return 1;
   }

--- a/ndb/src/common/portlib/NdbHost.c	2007-08-29 07:25:53 +0000
+++ b/ndb/src/common/portlib/NdbHost.c	2007-09-09 09:06:04 +0000
@@ -19,13 +19,15 @@
 
 int NdbHost_GetHostName(char* buf)
 {
-  if (gethostname(buf, MAXHOSTNAMELEN) != 0)
-  {     
-     return -1;
-   }
+  if(gethostname(buf, MAXHOSTNAMELEN))
+    return -1;
   return 0;
 }
 
+#ifdef NDB_WIN
+#include <process.h>
+#define getpid _getpid
+#endif
 int NdbHost_GetProcessId(void)
 {
   return getpid();

--- a/ndb/src/common/portlib/NdbMutex.c	2007-08-29 07:25:53 +0000
+++ b/ndb/src/common/portlib/NdbMutex.c	2007-09-09 09:06:04 +0000
@@ -17,6 +17,7 @@
 #include <ndb_global.h>
 
 #include <NdbThread.h>
+#include <my_pthread.h>
 #include <NdbMutex.h>
 #include <NdbMem.h>
 

--- a/ndb/src/common/portlib/NdbPortLibTest.cpp	2007-08-29 07:25:53 +0000
+++ b/ndb/src/common/portlib/NdbPortLibTest.cpp	2007-09-09 09:06:04 +0000
@@ -53,7 +53,7 @@
   if (arg1 != 7)
     fail("TEST1", "Wrong arg");
 
-  return returnvalue;
+  return (void*) returnvalue;
 }
 
 // test 2 variables and funcs
@@ -76,7 +76,7 @@
     fail("TEST2", "Failed to unlock mutex");
 
   int returnvalue = arg1;
-  return returnvalue;
+  return (void*) returnvalue;
 }
 
 

--- a/ndb/src/common/portlib/NdbSleep.c	2007-08-29 07:25:53 +0000
+++ b/ndb/src/common/portlib/NdbSleep.c	2007-09-09 09:06:04 +0000
@@ -19,24 +19,16 @@
 #include <NdbSleep.h>
 
 int
-NdbSleep_MilliSleep(int milliseconds){
-  my_sleep(milliseconds*1000);
+NdbSleep_MilliSleep(int milliseconds)
+{
+  my_sleep(milliseconds);
   return 0;
-#if 0
-  int result = 0;
-  struct timespec sleeptime;
-  sleeptime.tv_sec = milliseconds / 1000;
-  sleeptime.tv_nsec = (milliseconds - (sleeptime.tv_sec * 1000)) * 1000000;
-  result = nanosleep(&sleeptime, NULL);
-  return result;
-#endif
 }
 
 int
-NdbSleep_SecSleep(int seconds){
-  int result = 0;
-  result = sleep(seconds);
-  return result;
+NdbSleep_SecSleep(int seconds)
+{
+  return NdbSleep_MilliSleep(seconds*1000);
 }
 
 

--- a/ndb/src/common/portlib/NdbTCP.cpp	2007-08-29 07:25:53 +0000
+++ b/ndb/src/common/portlib/NdbTCP.cpp	2007-09-10 08:04:49 +0000
@@ -21,7 +21,6 @@
 extern "C"
 int 
 Ndb_getInAddr(struct in_addr * dst, const char *address) {
-  //  DBUG_ENTER("Ndb_getInAddr");
   {
     int tmp_errno;
     struct hostent tmp_hostent, *hp;
@@ -32,7 +31,7 @@
     {
       memcpy(dst, hp->h_addr, min(sizeof(*dst), (size_t) hp->h_length));
       my_gethostbyname_r_free();
-      return 0; //DBUG_RETURN(0);
+      return 0;
     }
     my_gethostbyname_r_free();
   }
@@ -46,13 +45,12 @@
 #endif
       )
   {
-    return 0; //DBUG_RETURN(0);
+    return 0;
   }
-  //  DBUG_PRINT("error",("inet_addr(%s) - %d - %s",
-  //		      address, errno, strerror(errno)));
-  return -1; //DBUG_RETURN(-1);
+  DBUG_PRINT("error",("inet_addr(%s) - %d - %s",
+		      address, socket_errno, strerror(socket_errno))); 
+  return -1;
 }
-
 #ifndef DBUG_OFF
 extern "C"
 int NDB_CLOSE_SOCKET(int fd)
@@ -61,7 +59,6 @@
   return _NDB_CLOSE_SOCKET(fd);
 }
 #endif
-
 #if 0
 int 
 Ndb_getInAddr(struct in_addr * dst, const char *address) {
@@ -111,7 +108,7 @@
   FD_SET(sock, &writefds);
   FD_SET(sock, &errorfds);
 
-  if(select(1, &readfds, &writefds, &errorfds, &tv)<0)
+  if(select(sock+1, &readfds, &writefds, &errorfds, &tv)<0)
     return 1;
 
   if(FD_ISSET(sock,&errorfds))

--- a/ndb/src/common/portlib/NdbThread.c	2007-08-29 07:25:53 +0000
+++ b/ndb/src/common/portlib/NdbThread.c	2007-09-16 12:55:19 +0000
@@ -28,7 +28,7 @@
 #endif
 
 struct NdbThread 
-{ 
+{
   pthread_t thread;
   char thread_name[MAX_THREAD_NAME];
   NDB_THREAD_FUNC * func;
@@ -41,6 +41,7 @@
   my_thread_init();
   {
     DBUG_ENTER("ndb_thread_wrapper");
+#ifndef NDB_WIN32
 #ifdef NDB_SHM_TRANSPORTER
     if (g_ndb_shm_signum)
     {
@@ -60,6 +61,7 @@
       sigfillset(&mask);
       pthread_sigmask(SIG_BLOCK, &mask, 0);
     }      
+#endif
     
     {
       void *ret;

--- a/ndb/src/common/portlib/NdbTick.c	2007-08-29 07:25:53 +0000
+++ b/ndb/src/common/portlib/NdbTick.c	2007-09-09 09:06:04 +0000
@@ -24,7 +24,26 @@
 #define MILLISEC_PER_NANOSEC 1000000
 
 
-#ifdef HAVE_CLOCK_GETTIME
+#ifdef NDB_WIN32
+NDB_TICKS NdbTick_CurrentMillisecond(void)
+{
+  NDB_TICKS sec;Uint32 usec;
+  NdbTick_CurrentMicrosecond(&sec,&usec);
+  return sec*1000+usec/1000;
+}
+
+int 
+NdbTick_CurrentMicrosecond(NDB_TICKS * secs, Uint32 * micros)
+{
+  LARGE_INTEGER liCount, liFreq;
+  QueryPerformanceCounter(&liCount);
+  QueryPerformanceFrequency(&liFreq);
+  *secs = liCount.QuadPart / liFreq.QuadPart;
+  liCount.QuadPart -= *secs * liFreq.QuadPart;
+  *micros = (liCount.QuadPart*1000000) / liFreq.QuadPart;
+  return 0;
+}
+#elif defined(HAVE_CLOCK_GETTIME)
 NDB_TICKS NdbTick_CurrentMillisecond(void)
 {
   struct timespec tick_time;

