mirror of https://gitlab.com/nakst/essence
only include semaphore stuff for emulator timeout in build.c if host is linux
This commit is contained in:
parent
d6d5c8ca44
commit
3337f37279
12
util/build.c
12
util/build.c
|
@ -34,7 +34,9 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <spawn.h>
|
#include <spawn.h>
|
||||||
|
#ifdef __linux__
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
|
#endif
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
@ -56,7 +58,9 @@ bool interactiveMode;
|
||||||
bool canBuildLuigi;
|
bool canBuildLuigi;
|
||||||
volatile int emulatorTimeout;
|
volatile int emulatorTimeout;
|
||||||
volatile bool emulatorDidTimeout;
|
volatile bool emulatorDidTimeout;
|
||||||
|
#ifdef __linux__
|
||||||
sem_t emulatorSemaphore;
|
sem_t emulatorSemaphore;
|
||||||
|
#endif
|
||||||
FILE *systemLog;
|
FILE *systemLog;
|
||||||
char compilerPath[4096];
|
char compilerPath[4096];
|
||||||
int argc;
|
int argc;
|
||||||
|
@ -438,6 +442,7 @@ void Build(int optimise, bool compile) {
|
||||||
(double) (endTime.tv_sec - startTime.tv_sec) + (double) (endTime.tv_nsec - startTime.tv_nsec) / 1000000000);
|
(double) (endTime.tv_sec - startTime.tv_sec) + (double) (endTime.tv_nsec - startTime.tv_nsec) / 1000000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
void *TimeoutThread(void *_unused) {
|
void *TimeoutThread(void *_unused) {
|
||||||
(void) _unused;
|
(void) _unused;
|
||||||
emulatorDidTimeout = false;
|
emulatorDidTimeout = false;
|
||||||
|
@ -491,6 +496,7 @@ void *TimeoutThread(void *_unused) {
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#define LOG_VERBOSE (0)
|
#define LOG_VERBOSE (0)
|
||||||
#define LOG_NORMAL (1)
|
#define LOG_NORMAL (1)
|
||||||
|
@ -601,6 +607,7 @@ void Run(int emulator, int log, int debug) {
|
||||||
const char *displayFlags = emulator == EMULATOR_QEMU_NO_GUI ? " -display none " : "";
|
const char *displayFlags = emulator == EMULATOR_QEMU_NO_GUI ? " -display none " : "";
|
||||||
|
|
||||||
char timeoutFlags[256];
|
char timeoutFlags[256];
|
||||||
|
#ifdef __linux__
|
||||||
pthread_t timeoutThread;
|
pthread_t timeoutThread;
|
||||||
|
|
||||||
if (emulatorTimeout) {
|
if (emulatorTimeout) {
|
||||||
|
@ -610,6 +617,9 @@ void Run(int emulator, int log, int debug) {
|
||||||
} else {
|
} else {
|
||||||
timeoutFlags[0] = 0;
|
timeoutFlags[0] = 0;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
timeoutFlags[0] = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
int exitCode = CallSystemF("%s %s " QEMU_EXECUTABLE " %s%s %s -m %d %s -smp cores=%d -cpu Haswell "
|
int exitCode = CallSystemF("%s %s " QEMU_EXECUTABLE " %s%s %s -m %d %s -smp cores=%d -cpu Haswell "
|
||||||
" -device qemu-xhci,id=xhci -device usb-kbd,bus=xhci.0,id=mykeyboard -device usb-mouse,bus=xhci.0,id=mymouse "
|
" -device qemu-xhci,id=xhci -device usb-kbd,bus=xhci.0,id=mykeyboard -device usb-mouse,bus=xhci.0,id=mymouse "
|
||||||
|
@ -622,12 +632,14 @@ void Run(int emulator, int log, int debug) {
|
||||||
|
|
||||||
bool printStartupErrorMessage = exitCode != 0;
|
bool printStartupErrorMessage = exitCode != 0;
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
if (emulatorTimeout) {
|
if (emulatorTimeout) {
|
||||||
sem_post(&emulatorSemaphore);
|
sem_post(&emulatorSemaphore);
|
||||||
pthread_join(timeoutThread, NULL);
|
pthread_join(timeoutThread, NULL);
|
||||||
if (emulatorDidTimeout) printStartupErrorMessage = false;
|
if (emulatorDidTimeout) printStartupErrorMessage = false;
|
||||||
sem_destroy(&emulatorSemaphore);
|
sem_destroy(&emulatorSemaphore);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (printStartupErrorMessage) {
|
if (printStartupErrorMessage) {
|
||||||
printf("Unable to start Qemu. To manually run the system, use the drive image located at \"bin/drive\".\n");
|
printf("Unable to start Qemu. To manually run the system, use the drive image located at \"bin/drive\".\n");
|
||||||
|
|
Loading…
Reference in New Issue