Merging the dlmstp for Windows and Linux, so that a common module can be used for building. Untested.

This commit is contained in:
skarg
2008-08-02 15:41:51 +00:00
parent 395f7fea18
commit 6328b51cbc
5 changed files with 855 additions and 45 deletions
+2 -4
View File
@@ -70,10 +70,8 @@
# include <sys/sockio.h>
#endif
#ifdef HAVE_PTHREAD_H
# include <pthread.h>
#endif
#include <pthread.h>
#include <semaphore.h>
#define ENUMS
#include <sys/socket.h>
+72
View File
@@ -36,9 +36,81 @@
#endif
#include <winsock2.h>
#include <sys/timeb.h>
#include <process.h>
#define close closesocket
typedef int socklen_t;
typedef HANDLE sem_t;
#define sem_post(x) ReleaseSemaphore(*(x), 1, NULL)
#define sem_close(x) CloseHandle(*(x))
struct timespec {
time_t tv_sec; /* Seconds */
long tv_nsec; /* Nanoseconds [0 .. 999999999] */
};
static inline int gettimeofday(struct timeval *tp, void *tzp)
{
struct _timeb timebuffer;
_ftime(&timebuffer);
tp->tv_sec = timebuffer.time;
tp->tv_usec = timebuffer.millitm * 1000;
return 0;
}
/* FIXME: not a complete implementation of the posix function */
static inline int sem_timedwait(sem_t *sem,
const struct timespec *abs_timeout)
{
struct timeval tp;
DWORD dwMilliseconds = (abs_timeout->tv_sec * 1000) +
(abs_timeout->tv_nsec / 1000);
gettimeofday(&tp,NULL);
if (abs_timeout->tv_sec >= tp.tv_sec) {
dwMilliseconds = (abs_timeout->tv_sec - tp.tv_sec) * 1000;
if (abs_timeout->tv_usec >= tp.tv_usec) {
dwMilliseconds +=
((abs_timeout->tv_usec - tp.tv_usec) / 1000);
}
} else {
dwMilliseconds = 0;
}
wait_status = WaitForSingleObject(*sem, dwMilliseconds);
if (wait_status == WAIT_OBJECT_0) {
return 0;
}
return -1;
}
static inline int sem_init(sem_t *sem, int pshared, unsigned int value);
{
(void)pshared;
*sem = CreateSemaphore(
NULL/*lpSecurityDescriptor*/,
value /* lInitialCount */,
1 /* lMaximumCount */,
NULL /* lpName */);
if ((*sem) == NULL) {
return -1;
}
return 0;
}
static inline int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
{
DWORD dwMilliseconds = (rqtp->tv_sec * 1000) +
(rqtp->tv_nsec / 1000);
Sleep(dwMilliseconds);
}
#endif