Skip to content
Snippets Groups Projects
Commit ae1a0eb4 authored by deuce's avatar deuce
Browse files

General clean-up of YIELD and SLEEP macros... SLEEP shouldn't have been

touched in the first place (Twice the bugs in half the time!) use
use -D_THREAD_SAFE to compile object files for a threaded app (You have to
do that on BSD already anyways)
parent 96cfbc73
No related branches found
No related tags found
No related merge requests found
...@@ -43,15 +43,13 @@ ...@@ -43,15 +43,13 @@
#include "wrapdll.h" /* DLLEXPORT and DLLCALL */ #include "wrapdll.h" /* DLLEXPORT and DLLCALL */
#if defined(__unix__) #if defined(__unix__)
#include <unistd.h> /* usleep */
#include <sys/time.h> /* struct timeval */
#include <sched.h> /* sched_yield */ #include <sched.h> /* sched_yield */
#endif #include <sys/time.h> /* struct timeval */
#if defined(__QNX__)
#include <strings.h> /* strcasecmp() */ #include <strings.h> /* strcasecmp() */
#include <unistd.h> /* usleep */
#endif #endif
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
...@@ -90,7 +88,6 @@ extern "C" { ...@@ -90,7 +88,6 @@ extern "C" {
/* Macros */ /* Macros */
/**********/ /**********/
#define FORK() fork()
/* Target Platform Description */ /* Target Platform Description */
#if defined(_WIN64) #if defined(_WIN64)
#define PLATFORM_DESC "Win64" #define PLATFORM_DESC "Win64"
...@@ -118,8 +115,6 @@ extern "C" { ...@@ -118,8 +115,6 @@ extern "C" {
#define PLATFORM_DESC "GNU/Hurd" #define PLATFORM_DESC "GNU/Hurd"
#elif defined(__QNX__) #elif defined(__QNX__)
#define PLATFORM_DESC "QNX" #define PLATFORM_DESC "QNX"
#undef FORK
#define FORK() vfork()
#elif defined(__unix__) #elif defined(__unix__)
#define PLATFORM_DESC "Unix" #define PLATFORM_DESC "Unix"
#else #else
...@@ -175,19 +170,28 @@ extern "C" { ...@@ -175,19 +170,28 @@ extern "C" {
#elif defined(__unix__) #elif defined(__unix__)
#ifndef SLEEP
#ifndef YIELD #if defined(_PTH_PTHREAD_H_)
#if defined(__OpenBSD__) || defined(__NetBSD__) #define SLEEP(x) ({ int y=x; struct timeval tv; \
#define YIELD() tv.tv_sec=(y/1000); tv.tv_usec=((y%1000)*1000); \
pth_nap(tv); })
#else #else
#define YIELD() sched_yield() #define SLEEP(x) ({ int y=x; struct timeval tv; \
#endif
#endif
#define SLEEP(x) ({ int y=x; struct timeval tv; \
tv.tv_sec=(y/1000); tv.tv_usec=((y%1000)*1000); \ tv.tv_sec=(y/1000); tv.tv_usec=((y%1000)*1000); \
YIELD(); \
select(0,NULL,NULL,NULL,&tv); }) select(0,NULL,NULL,NULL,&tv); })
#endif #endif
/*
* QNX doesn't support fork() in threaded apps (yet) using vfork() instead
* works, but relies on undefined behaviours not being nasty. On most OSs
* vfork() will share the stack between the parent and child...
*/
#if defined(__QNX__)
#define FORK() vfork()
#else
#define FORK() fork()
#endif
#define BEEP(freq,dur) unix_beep(freq,dur) #define BEEP(freq,dur) unix_beep(freq,dur)
DLLEXPORT void DLLCALL unix_beep(int freq, int dur); DLLEXPORT void DLLCALL unix_beep(int freq, int dur);
...@@ -223,8 +227,22 @@ DLLEXPORT char* DLLCALL lastchar(const char* str); ...@@ -223,8 +227,22 @@ DLLEXPORT char* DLLCALL lastchar(const char* str);
} }
#endif #endif
#ifndef YIELD #ifdef _THREAD_SAFE
#define YIELD() #if defined(__FreeBSD__)
#define YIELD() pthread_yield()
#elif defined(_PTH_PTHREAD_H_)
#define YIELD() pth_yield(NULL)
#elif defined(_POSIX_PRIORITY_SCHEDULING)
#define YIELD() sched_yield()
#else
#define YIELD()
#endif
#else
#if defined(_POSIX_PRIORITY_SCHEDULING)
#define YIELD() sched_yield()
#else
#define YIELD()
#endif
#endif #endif
#endif /* Don't add anything after this line */ #endif /* Don't add anything after this line */
...@@ -49,14 +49,6 @@ extern "C" { ...@@ -49,14 +49,6 @@ extern "C" {
#include <sys/param.h> #include <sys/param.h>
#include <pthread.h> /* POSIX threads and mutexes */ #include <pthread.h> /* POSIX threads and mutexes */
#undef YIELD
#if defined(__linux__) || defined(__QNX__)
#define YIELD() sched_yield()
#elif defined(_PTH_PTHREAD_H_)
#define YIELD() pth_yield(NULL)
#else
#define YIELD() pthread_yield()
#endif
#if defined(_NEED_SEM) #if defined(_NEED_SEM)
#include "sem.h" #include "sem.h"
#else #else
...@@ -124,12 +116,4 @@ extern "C" { ...@@ -124,12 +116,4 @@ extern "C" {
} }
#endif #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 */ #endif /* Don't add anything after this line */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment