1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-01 18:55:36 +00:00
sgminer/compat.h

89 lines
1.7 KiB
C
Raw Normal View History

2010-11-26 20:50:36 +00:00
#ifndef __COMPAT_H__
#define __COMPAT_H__
#ifdef WIN32
2013-04-04 14:59:10 +00:00
#include "config.h"
#include <errno.h>
#include <time.h>
#include <pthread.h>
#include <sys/time.h>
2010-11-26 20:50:36 +00:00
#include "miner.h" // for timersub
2013-04-21 09:10:37 +00:00
#include "util.h"
2013-04-04 14:59:10 +00:00
#include <windows.h>
#ifndef HAVE_LIBWINPTHREAD
static inline int nanosleep(const struct timespec *req, struct timespec *rem)
{
struct timeval tstart;
DWORD msecs;
2013-04-21 09:10:37 +00:00
cgtime(&tstart);
msecs = (req->tv_sec * 1000) + ((999999 + req->tv_nsec) / 1000000);
if (SleepEx(msecs, true) == WAIT_IO_COMPLETION) {
if (rem) {
struct timeval tdone, tnow, tleft;
tdone.tv_sec = tstart.tv_sec + req->tv_sec;
tdone.tv_usec = tstart.tv_usec + ((999 + req->tv_nsec) / 1000);
if (tdone.tv_usec > 1000000) {
tdone.tv_usec -= 1000000;
++tdone.tv_sec;
}
2013-04-21 09:10:37 +00:00
cgtime(&tnow);
if (timercmp(&tnow, &tdone, >))
return 0;
timersub(&tdone, &tnow, &tleft);
rem->tv_sec = tleft.tv_sec;
rem->tv_nsec = tleft.tv_usec * 1000;
}
errno = EINTR;
return -1;
}
return 0;
}
2013-04-04 14:59:10 +00:00
#endif
static inline int sleep(unsigned int secs)
2010-11-26 20:50:36 +00:00
{
struct timespec req, rem;
req.tv_sec = secs;
req.tv_nsec = 0;
if (!nanosleep(&req, &rem))
return 0;
return rem.tv_sec + (rem.tv_nsec ? 1 : 0);
2010-11-26 20:50:36 +00:00
}
2010-11-26 21:28:12 +00:00
enum {
PRIO_PROCESS = 0,
};
2012-09-21 12:04:39 +00:00
static inline int setpriority(__maybe_unused int which, __maybe_unused int who, __maybe_unused int prio)
2010-11-26 21:28:12 +00:00
{
/* FIXME - actually do something */
return 0;
}
2011-06-24 18:43:37 +00:00
typedef unsigned long int ulong;
typedef unsigned short int ushort;
typedef unsigned int uint;
2011-07-18 01:37:16 +00:00
#ifndef __SUSECONDS_T_TYPE
typedef long suseconds_t;
#endif
2013-04-04 14:59:10 +00:00
#ifdef HAVE_LIBWINPTHREAD
#define PTH(thr) ((thr)->pth)
#else
#define PTH(thr) ((thr)->pth.p)
2013-04-04 14:59:10 +00:00
#endif
#else
#define PTH(thr) ((thr)->pth)
2010-11-26 20:50:36 +00:00
#endif /* WIN32 */
#endif /* __COMPAT_H__ */