From 96cc5612f54025f77190a91b85d2cb1718e490a2 Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Sun, 27 Apr 2003 22:54:14 +0000
Subject: [PATCH] Fix NetBSD SLEEP() issues with non-threaded programs

---
 src/xpdev/genwrap.h    | 16 +---------------
 src/xpdev/threadwrap.h |  8 ++++++++
 2 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/src/xpdev/genwrap.h b/src/xpdev/genwrap.h
index a2f3169a55..ac87bcd850 100644
--- a/src/xpdev/genwrap.h
+++ b/src/xpdev/genwrap.h
@@ -45,9 +45,6 @@
 #if defined(__unix__)
 	#include <unistd.h>		/* usleep */
 	#include <sys/time.h>	/* struct timeval */
-	#if defined(_NEED_SEM)	/* Assumes that if you don't have semaphores, you're using the GNU Pth lib */
-		#include <pth.h>
-	#endif
 #endif
 
 #if defined(__QNX__)
@@ -172,20 +169,9 @@ extern "C" {
 	#define SLEEP(x)		DosSleep(x)
 	#define BEEP(freq,dur)	DosBeep(freq,dur)
 
-#elif defined(_PTH_H_)
-
-	#define SLEEP(x)		({	int y=x; struct timeval tv; \
-								tv.tv_sec=(y/1000); tv.tv_usec=((y%1000)*1000); \
-								pth_nap(tv); })
-	#define BEEP(freq,dur)	unix_beep(freq,dur)
-	DLLEXPORT void	DLLCALL	unix_beep(int freq, int dur);
-
 #elif defined(__unix__)
 
-		/* usleep() apparently doesn't work right (100% CPU utilization) */
-#if 0	/* with multiple clients/threads on *BSD */
-	#define SLEEP(x)		usleep(x*1000)
-#else
+#ifndef SLEEP
 	#define SLEEP(x)		({	int y=x; struct timeval tv; \
 								tv.tv_sec=(y/1000); tv.tv_usec=((y%1000)*1000); \
 								select(0,NULL,NULL,NULL,&tv); })
diff --git a/src/xpdev/threadwrap.h b/src/xpdev/threadwrap.h
index 6b1776e0ff..6f414977f5 100644
--- a/src/xpdev/threadwrap.h
+++ b/src/xpdev/threadwrap.h
@@ -116,4 +116,12 @@ extern "C" {
 }
 #endif
 
+#ifdef _PTH_PTHREAD_H_
+#include <pth.h>
+#undef SLEEP
+#define SLEEP(x)		({	int y=x; struct timeval tv; \
+								tv.tv_sec=(y/1000); tv.tv_usec=((y%1000)*1000); \
+								pth_nap(tv); })
+#endif
+
 #endif	/* Don't add anything after this line */
-- 
GitLab