Skip to content
This repository has been archived by the owner on May 2, 2018. It is now read-only.

Commit

Permalink
runtime: fix windows build
Browse files Browse the repository at this point in the history
Add osyield and usleep as required by recent GC changes.

R=golang-dev, r, dsymonds, rsc, r
CC=golang-dev
https://golang.org/cl/5156042
  • Loading branch information
hectorchu authored and robpike committed Sep 30, 2011
1 parent a7a7cc5 commit 38d3f58
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/pkg/runtime/windows/386/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ enum {
// Types
#pragma pack on

typedef struct SystemInfo SystemInfo;
struct SystemInfo {
byte Pad_godefs_0[4];
uint32 dwPageSize;
void *lpMinimumApplicationAddress;
void *lpMaximumApplicationAddress;
uint32 dwActiveProcessorMask;
uint32 dwNumberOfProcessors;
uint32 dwProcessorType;
uint32 dwAllocationGranularity;
uint16 wProcessorLevel;
uint16 wProcessorRevision;
};

typedef struct ExceptionRecord ExceptionRecord;
struct ExceptionRecord {
uint32 ExceptionCode;
Expand Down
14 changes: 14 additions & 0 deletions src/pkg/runtime/windows/amd64/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ enum {
// Types
#pragma pack on

typedef struct SystemInfo SystemInfo;
struct SystemInfo {
byte Pad_godefs_0[4];
uint32 dwPageSize;
void *lpMinimumApplicationAddress;
void *lpMaximumApplicationAddress;
uint64 dwActiveProcessorMask;
uint32 dwNumberOfProcessors;
uint32 dwProcessorType;
uint32 dwAllocationGranularity;
uint16 wProcessorLevel;
uint16 wProcessorRevision;
};

typedef struct ExceptionRecord ExceptionRecord;
struct ExceptionRecord {
uint32 ExceptionCode;
Expand Down
1 change: 1 addition & 0 deletions src/pkg/runtime/windows/defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum {
$EXCEPTION_INT_OVERFLOW = STATUS_INTEGER_OVERFLOW,
};

typedef SYSTEM_INFO $SystemInfo;
typedef EXCEPTION_RECORD $ExceptionRecord;
#ifdef _X86_
typedef FLOATING_SAVE_AREA $FloatingSaveArea;
Expand Down
29 changes: 29 additions & 0 deletions src/pkg/runtime/windows/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#pragma dynimport runtime·GetEnvironmentStringsW GetEnvironmentStringsW "kernel32.dll"
#pragma dynimport runtime·GetProcAddress GetProcAddress "kernel32.dll"
#pragma dynimport runtime·GetStdHandle GetStdHandle "kernel32.dll"
#pragma dynimport runtime·GetSystemInfo GetSystemInfo "kernel32.dll"
#pragma dynimport runtime·GetThreadContext GetThreadContext "kernel32.dll"
#pragma dynimport runtime·LoadLibraryEx LoadLibraryExA "kernel32.dll"
#pragma dynimport runtime·QueryPerformanceCounter QueryPerformanceCounter "kernel32.dll"
Expand All @@ -26,6 +27,7 @@
#pragma dynimport runtime·SetEvent SetEvent "kernel32.dll"
#pragma dynimport runtime·SetThreadPriority SetThreadPriority "kernel32.dll"
#pragma dynimport runtime·SetWaitableTimer SetWaitableTimer "kernel32.dll"
#pragma dynimport runtime·Sleep Sleep "kernel32.dll"
#pragma dynimport runtime·SuspendThread SuspendThread "kernel32.dll"
#pragma dynimport runtime·timeBeginPeriod timeBeginPeriod "winmm.dll"
#pragma dynimport runtime·WaitForSingleObject WaitForSingleObject "kernel32.dll"
Expand All @@ -41,6 +43,7 @@ extern void *runtime·FreeEnvironmentStringsW;
extern void *runtime·GetEnvironmentStringsW;
extern void *runtime·GetProcAddress;
extern void *runtime·GetStdHandle;
extern void *runtime·GetSystemInfo;
extern void *runtime·GetThreadContext;
extern void *runtime·LoadLibraryEx;
extern void *runtime·QueryPerformanceCounter;
Expand All @@ -50,13 +53,23 @@ extern void *runtime·SetConsoleCtrlHandler;
extern void *runtime·SetEvent;
extern void *runtime·SetThreadPriority;
extern void *runtime·SetWaitableTimer;
extern void *runtime·Sleep;
extern void *runtime·SuspendThread;
extern void *runtime·timeBeginPeriod;
extern void *runtime·WaitForSingleObject;
extern void *runtime·WriteFile;

static int64 timerfreq;

static int32
getproccount(void)
{
SystemInfo info;

runtime·stdcall(runtime·GetSystemInfo, 1, &info);
return info.dwNumberOfProcessors;
}

void
runtime·osinit(void)
{
Expand All @@ -67,6 +80,7 @@ runtime·osinit(void)
runtime·stdcall(runtime·QueryPerformanceFrequency, 1, &timerfreq);
runtime·stdcall(runtime·SetConsoleCtrlHandler, 2, runtime·ctrlhandler, (uintptr)1);
runtime·stdcall(runtime·timeBeginPeriod, 1, (uintptr)1);
runtime·ncpu = getproccount();
}

void
Expand Down Expand Up @@ -126,6 +140,21 @@ runtime·write(int32 fd, void *buf, int32 n)
return written;
}

void
runtime·osyield(void)
{
runtime·stdcall(runtime·Sleep, 1, (uintptr)0);
}

void
runtime·usleep(uint32 us)
{
us /= 1000;
if(us == 0)
us = 1;
runtime·stdcall(runtime·Sleep, 1, (uintptr)us);
}

// Thread-safe allocation of an event.
static void
initevent(void **pevent)
Expand Down

0 comments on commit 38d3f58

Please sign in to comment.