Add porting.h

In preparation for MSVC compilation support
master
adrido 2015-12-30 10:08:10 +01:00 committed by Rogier
parent e2b5dce3e3
commit 5761f103e1
3 changed files with 26 additions and 4 deletions

View File

@ -1,6 +1,6 @@
#include "db-sqlite3.h"
#include <stdexcept>
#include <unistd.h> // for usleep
#include "porting.h"
#include "types.h"
#define BLOCKPOSLIST_STATEMENT "SELECT pos, rowid FROM blocks"
@ -58,7 +58,7 @@ const DB::BlockPosList &DBSQLite3::getBlockPosList() {
sqlite3_int64 rowid = sqlite3_column_int64(m_blockPosListStatement, 1);
m_BlockPosList.push_back(BlockPos(blocknum, rowid));
} else if (result == SQLITE_BUSY) // Wait some time and try again
usleep(10000);
sleepMs(10);
else
break;
}
@ -94,7 +94,7 @@ DB::Block DBSQLite3::getBlockOnPos(const BlockPos &pos)
m_blocksReadCount++;
break;
} else if (result == SQLITE_BUSY) { // Wait some time and try again
usleep(10000);
sleepMs(10);
} else {
break;
}

View File

@ -17,8 +17,8 @@
#include <cstring>
#include <stdexcept>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include "porting.h"
#include "TileGenerator.h"
#include "PixelAttributes.h"
#include "util.h"

22
porting.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef _PORTING_H
#define _PORTING_H
#ifdef _WIN32
#include <windows.h>
#define sleepMs(x) Sleep(x)
#else
#include <unistd.h>
#define sleepMs(x) usleep(x*1000)
#endif
#ifdef _MSC_VER
#define strcasecmp(a, b) _stricmp(a, b)
#endif
#endif // _PORTING_H