fix coding style for windows build patch (#350)

This commit is contained in:
Xu Jun 2020-08-13 16:40:19 +08:00 committed by GitHub
parent 874cc951c6
commit 1266ebb222
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 40 additions and 33 deletions

View File

@ -83,7 +83,7 @@ endif ()
####################### Common sources #######################
if (NOT MSVC)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections \
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections \
-Wall -Wno-unused-parameter -Wno-pedantic")
endif ()

View File

@ -52,7 +52,9 @@ typedef struct {
#define os_printf printf
#define os_vprintf vprintf
static inline size_t getpagesize() {
static inline size_t
getpagesize()
{
SYSTEM_INFO S;
GetNativeSystemInfo(&S);
return S.dwPageSize;

View File

@ -4,6 +4,7 @@
*/
#include "platform_api_vmcore.h"
void * os_mmap(void *hint, size_t size, int prot, int flags)
{
DWORD AllocType = MEM_RESERVE | MEM_COMMIT;
@ -40,8 +41,8 @@ os_munmap(void *addr, size_t size)
{
size_t page_size = getpagesize();
size_t request_size = (size + page_size - 1) & ~(page_size - 1);
if (addr) {
if (addr) {
if (VirtualFree(addr, 0, MEM_RELEASE) == 0) {
if (VirtualFree(addr, size, MEM_DECOMMIT) == 0) {
os_printf("os_munmap error addr:%p, size:0x%lx, errno:%d\n",
@ -56,6 +57,7 @@ os_mprotect(void *addr, size_t size, int prot)
{
DWORD AllocType = MEM_RESERVE | MEM_COMMIT;
DWORD flProtect = PAGE_NOACCESS;
if (!addr)
return 0;
@ -76,4 +78,5 @@ os_mprotect(void *addr, size_t size, int prot)
void
os_dcache_flush(void)
{
}

View File

@ -97,22 +97,24 @@ int os_cond_wait(korp_cond *cond, korp_mutex *mutex)
int gettimeofday(struct timeval * tp, struct timezone * tzp)
{
// Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
// until 00:00:00 January 1, 1970
/* Note: some broken versions only have 8 trailing zero's,
the correct epoch has 9 trailing zero's
This magic number is the number of 100 nanosecond intervals
since January 1, 1601 (UTC) until 00:00:00 January 1, 1970 */
static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);
SYSTEMTIME system_time;
FILETIME file_time;
uint64_t time;
GetSystemTime( &system_time );
SystemTimeToFileTime( &system_time, &file_time );
time = ((uint64_t)file_time.dwLowDateTime ) ;
GetSystemTime(&system_time);
SystemTimeToFileTime(&system_time, &file_time);
time = ((uint64_t)file_time.dwLowDateTime);
time += ((uint64_t)file_time.dwHighDateTime) << 32;
tp->tv_sec = (long) ((time - EPOCH) / 10000000L);
tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
tp->tv_sec = (long)((time - EPOCH) / 10000000L);
tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
return 0;
}

View File

@ -11,6 +11,6 @@ os_time_get_boot_microsecond()
struct timespec ts;
timespec_get(&ts, TIME_UTC);
return ((uint64) ts.tv_sec) * 1000 * 1000 + ((uint64)ts.tv_nsec) / 1000;
return ((uint64)ts.tv_sec) * 1000 * 1000 + ((uint64)ts.tv_nsec) / 1000;
}