From f63f8cd4f69317850dd5e8d6302acf3fbf849332 Mon Sep 17 00:00:00 2001
From: rpj <rpj>
Date: Fri, 1 Apr 2005 00:55:20 +0000
Subject: ''

---
 ChangeLog       | 14 ++++++++++++++
 dll.c           |  4 ++++
 implement.h     |  6 ++++++
 pthread.h       |  8 +++++---
 sched.h         | 10 +++++++---
 sem_timedwait.c | 22 +++++++++++-----------
 semaphore.h     | 11 +++++++----
 7 files changed, 54 insertions(+), 21 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f07632b..4102ff6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2005-04-01  Kevin Lussier <Kevin at codegreennetworks.com>
+
+	* sem_timedwait.c (sem_timedwait): Increase size of temp variables to
+	avoid int overflows for large timeout values.
+	* implement.h (int64_t): Include or define.
+
+2005-03-31   Dimitar Panayotov <develop at mail.bg>^M
+
+	* pthread.h: Fix conditional defines for static linking.
+	* sched.h: Liekwise.
+	* semaphore.h: Likewise.
+	* dll.c (PTW32_STATIC_LIB): Module is conditionally included
+	in the build.
+
 2005-03-16  Ross Johnson  <ross at callisto.canberra.edu.au>^M
 
         * pthread_setcancelstate.c: Undo the last change.
diff --git a/dll.c b/dll.c
index 314c713..c1cd4e9 100644
--- a/dll.c
+++ b/dll.c
@@ -34,6 +34,8 @@
  *      59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#ifndef PTW32_STATIC_LIB
+
 #include "pthread.h"
 #include "implement.h"
 
@@ -86,3 +88,5 @@ DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
   return (result);
 
 }				/* DllMain */
+
+#endif /* PTW32_STATIC_LIB */
diff --git a/implement.h b/implement.h
index abba13c..d2aee1b 100644
--- a/implement.h
+++ b/implement.h
@@ -90,6 +90,12 @@ typedef VOID (APIENTRY *PAPCFUNC)(DWORD dwParam);
 #define PTW32_INTERLOCKED_LPLONG PVOID*
 #endif
 
+#if defined(__MINGW32__)
+#include <stdint.h>
+#else
+#define int64_t _int64
+#endif
+
 typedef enum
 {
   /*
diff --git a/pthread.h b/pthread.h
index a9196c6..9e7b2ef 100644
--- a/pthread.h
+++ b/pthread.h
@@ -37,8 +37,8 @@
  * See the README file for an explanation of the pthreads-win32 version
  * numbering scheme and how the DLL is named etc.
  */
-#define PTW32_VERSION 2,1,0,0
-#define PTW32_VERSION_STRING "2, 1, 0, 0\0"
+#define PTW32_VERSION 2,2,0,0
+#define PTW32_VERSION_STRING "2, 2, 0, 0\0"
 
 /* There are three implementations of cancel cleanup.
  * Note that pthread.h is included in both application
@@ -556,12 +556,14 @@ extern "C"
  * do NOT define PTW32_BUILD, and then the variables/functions will
  * be imported correctly.
  */
-#ifdef _DLL
+#ifndef PTW32_STATIC_LIB
 #  ifdef PTW32_BUILD
 #    define PTW32_DLLPORT __declspec (dllexport)
 #  else
 #    define PTW32_DLLPORT __declspec (dllimport)
 #  endif
+#else
+#  define PTW32_DLLPORT
 #endif
 
 /*
diff --git a/sched.h b/sched.h
index 4a342a6..dfb8e93 100644
--- a/sched.h
+++ b/sched.h
@@ -76,10 +76,14 @@
  * do NOT define PTW32_BUILD, and then the variables/functions will
  * be imported correctly.
  */
-#ifdef PTW32_BUILD
-# define PTW32_DLLPORT __declspec (dllexport)
+#ifndef PTW32_STATIC_LIB
+#  ifdef PTW32_BUILD
+#    define PTW32_DLLPORT __declspec (dllexport)
+#  else
+#    define PTW32_DLLPORT __declspec (dllimport)
+#  endif
 #else
-# define PTW32_DLLPORT __declspec (dllimport)
+#  define PTW32_DLLPORT
 #endif
 
 /*
diff --git a/sem_timedwait.c b/sem_timedwait.c
index 6bf94d4..7fba45f 100644
--- a/sem_timedwait.c
+++ b/sem_timedwait.c
@@ -121,11 +121,11 @@ sem_timedwait (sem_t * sem, const struct timespec *abstime)
 
 #endif /* NEED_FTIME */
 
-  const DWORD NANOSEC_PER_MILLISEC = 1000000;
-  const DWORD MILLISEC_PER_SEC = 1000;
+  const int64_t NANOSEC_PER_MILLISEC = 1000000;
+  const int64_t MILLISEC_PER_SEC = 1000;
   DWORD milliseconds;
-  DWORD tmpAbsMilliseconds;
-  DWORD tmpCurrMilliseconds;
+  int64_t tmpAbsMilliseconds;
+  int64_t tmpCurrMilliseconds;
 
   if (sem == NULL)
     {
@@ -150,8 +150,8 @@ sem_timedwait (sem_t * sem, const struct timespec *abstime)
 	   *
 	   * Assume all integers are unsigned, i.e. cannot test if less than 0.
 	   */
-	  tmpAbsMilliseconds =  abstime->tv_sec * MILLISEC_PER_SEC;
-	  tmpAbsMilliseconds += (abstime->tv_nsec + (NANOSEC_PER_MILLISEC/2)) / NANOSEC_PER_MILLISEC;
+	  tmpAbsMilliseconds =  (int64_t)abstime->tv_sec * MILLISEC_PER_SEC;
+	  tmpAbsMilliseconds += ((int64_t)abstime->tv_nsec + (NANOSEC_PER_MILLISEC/2)) / NANOSEC_PER_MILLISEC;
 
 	  /* get current system time */
 
@@ -171,21 +171,21 @@ sem_timedwait (sem_t * sem, const struct timespec *abstime)
 	    ptw32_filetime_to_timespec(&ft, &currSysTime);
 	  }
 
-	  tmpCurrMilliseconds = currSysTime.tv_sec * MILLISEC_PER_SEC;
-	  tmpCurrMilliseconds += (currSysTime.tv_nsec + (NANOSEC_PER_MILLISEC/2)) / NANOSEC_PER_MILLISEC;
+	  tmpCurrMilliseconds = (int64_t)currSysTime.tv_sec * MILLISEC_PER_SEC;
+	  tmpCurrMilliseconds += ((int64_t)currSysTime.tv_nsec + (NANOSEC_PER_MILLISEC/2)) / NANOSEC_PER_MILLISEC;
 
 #else /* ! NEED_FTIME */
 
 	  _ftime(&currSysTime);
 
-	  tmpCurrMilliseconds = (DWORD) currSysTime.time * MILLISEC_PER_SEC;
-	  tmpCurrMilliseconds += (DWORD) currSysTime.millitm;
+	  tmpCurrMilliseconds = (int64_t) currSysTime.time * MILLISEC_PER_SEC;
+	  tmpCurrMilliseconds += (int64_t) currSysTime.millitm;
 
 #endif /* NEED_FTIME */
 
 	  if (tmpAbsMilliseconds > tmpCurrMilliseconds)
 	    {
-	      milliseconds = tmpAbsMilliseconds - tmpCurrMilliseconds;
+	      milliseconds = (DWORD) (tmpAbsMilliseconds - tmpCurrMilliseconds);
 	      if (milliseconds == INFINITE)
 		{
 		  /* Timeouts must be finite */
diff --git a/semaphore.h b/semaphore.h
index 7e71089..a3330a6 100644
--- a/semaphore.h
+++ b/semaphore.h
@@ -75,13 +75,16 @@
  * do NOT define PTW32_BUILD, and then the variables/functions will
  * be imported correctly.
  */
-#ifdef PTW32_BUILD
-# define PTW32_DLLPORT __declspec (dllexport)
+#ifndef PTW32_STATIC_LIB
+#  ifdef PTW32_BUILD
+#    define PTW32_DLLPORT __declspec (dllexport)
+#  else
+#    define PTW32_DLLPORT __declspec (dllimport)
+#  endif
 #else
-# define PTW32_DLLPORT __declspec (dllimport)
+#  define PTW32_DLLPORT
 #endif
 
-
 /*
  * This is a duplicate of what is in the autoconf config.h,
  * which is only used when building the pthread-win32 libraries.
-- 
cgit v1.2.3