Conflict resolution.

This commit is contained in:
OBattler
2021-09-25 14:24:29 +02:00
8 changed files with 52 additions and 237 deletions

View File

@@ -88,10 +88,6 @@ CMAKE_DEPENDENT_OPTION(VNC "VNC renderer" ON "DEV_BRANCH" OFF)
CMAKE_DEPENDENT_OPTION(XL24 "ATI VGA Wonder XL24 (ATI-28800-6)" ON "DEV_BRANCH" OFF) CMAKE_DEPENDENT_OPTION(XL24 "ATI VGA Wonder XL24 (ATI-28800-6)" ON "DEV_BRANCH" OFF)
CMAKE_DEPENDENT_OPTION(VECT486VL "HP Vectra 486VL" ON "DEV_BRANCH" OFF) CMAKE_DEPENDENT_OPTION(VECT486VL "HP Vectra 486VL" ON "DEV_BRANCH" OFF)
if(WIN32)
option(PTHREAD "Use POSIX threads (pthreads) instead of Win32 threads" ON)
endif()
# HACK: Avoid a MSVC2019 compiler bug on ARM64 Debug builds # HACK: Avoid a MSVC2019 compiler bug on ARM64 Debug builds
if(MSVC_TOOLSET_VERSION GREATER_EQUAL 142 AND ARCH STREQUAL "arm64") if(MSVC_TOOLSET_VERSION GREATER_EQUAL 142 AND ARCH STREQUAL "arm64")
# Define a cache option in case somebody wants to disable this workaround # Define a cache option in case somebody wants to disable this workaround

View File

@@ -47,22 +47,6 @@ if(VNC)
endif() endif()
endif() endif()
if(NOT WIN32 OR PTHREAD)
target_sources(86Box PRIVATE thread.c)
if(WIN32 AND VCPKG_TOOLCHAIN)
find_package(pthreads REQUIRED)
if (PThreads4W_FOUND)
target_link_libraries(86Box PThreads4W::PThreads4W)
else()
target_link_libraries(86Box pthreads)
endif()
else()
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
target_link_libraries(86Box Threads::Threads)
endif()
endif()
target_link_libraries(86Box cpu chipset mch dev mem fdd game cdrom zip mo hdd target_link_libraries(86Box cpu chipset mch dev mem fdd game cdrom zip mo hdd
net print scsi sio snd vid voodoo plat ui) net print scsi sio snd vid voodoo plat ui)

View File

@@ -8,10 +8,14 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
else() else()
set(PLAT_SOURCES unix_midi.c) set(PLAT_SOURCES unix_midi.c)
endif() endif()
add_library(plat STATIC ${PLAT_SOURCES}) add_library(plat STATIC ${PLAT_SOURCES} unix_thread.c)
add_library(ui STATIC unix.c unix_sdl.c unix_cdrom.c) add_library(ui STATIC unix.c unix_sdl.c unix_cdrom.c)
target_compile_definitions(ui PUBLIC _FILE_OFFSET_BITS=64) target_compile_definitions(ui PUBLIC _FILE_OFFSET_BITS=64)
target_link_libraries(ui dl) target_link_libraries(ui dl)
if (ALSA_FOUND) if (ALSA_FOUND)
target_link_libraries(plat ALSA::ALSA) target_link_libraries(plat ALSA::ALSA)
endif() endif()
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
target_link_libraries(86Box Threads::Threads)

View File

@@ -1,191 +1,52 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <time.h> #include <time.h>
#ifdef __APPLE__ #include <pthread.h>
#include <sys/time.h> #include <inttypes.h>
#endif
#include <86box/86box.h> #include <86box/86box.h>
#include <86box/plat.h> #include <86box/plat.h>
#if (defined WIN32) || (defined _WIN32) || (defined _WIN32)
#include <windows.h>
#include <process.h>
typedef struct {
HANDLE handle;
} win_event_t;
thread_t *
thread_create(void (*func)(void *param), void *param)
{
uintptr_t bt = _beginthread(func, 0, param);
return((thread_t *)bt);
}
int
thread_wait(thread_t *arg, int timeout)
{
if (arg == NULL) return(0);
if (timeout == -1)
timeout = INFINITE;
if (WaitForSingleObject(arg, timeout)) return(1);
return(0);
}
event_t *
thread_create_event(void)
{
win_event_t *ev = malloc(sizeof(win_event_t));
ev->handle = CreateEvent(NULL, FALSE, FALSE, NULL);
return((event_t *)ev);
}
void
thread_set_event(event_t *arg)
{
win_event_t *ev = (win_event_t *)arg;
if (arg == NULL) return;
SetEvent(ev->handle);
}
void
thread_reset_event(event_t *arg)
{
win_event_t *ev = (win_event_t *)arg;
if (arg == NULL) return;
ResetEvent(ev->handle);
}
int
thread_wait_event(event_t *arg, int timeout)
{
win_event_t *ev = (win_event_t *)arg;
if (arg == NULL) return(0);
if (ev->handle == NULL) return(0);
if (timeout == -1)
timeout = INFINITE;
if (WaitForSingleObject(ev->handle, timeout)) return(1);
return(0);
}
void
thread_destroy_event(event_t *arg)
{
win_event_t *ev = (win_event_t *)arg;
if (arg == NULL) return;
CloseHandle(ev->handle);
free(ev);
}
mutex_t *
thread_create_mutex(void)
{
mutex_t *mutex = malloc(sizeof(CRITICAL_SECTION));
InitializeCriticalSection(mutex);
return mutex;
}
mutex_t *
thread_create_mutex_with_spin_count(unsigned int spin_count)
{
mutex_t *mutex = malloc(sizeof(CRITICAL_SECTION));
InitializeCriticalSectionAndSpinCount(mutex, spin_count);
return mutex;
}
int
thread_wait_mutex(mutex_t *mutex)
{
if (mutex == NULL) return(0);
LPCRITICAL_SECTION critsec = (LPCRITICAL_SECTION)mutex;
EnterCriticalSection(critsec);
return 1;
}
int
thread_release_mutex(mutex_t *mutex)
{
if (mutex == NULL) return(0);
LPCRITICAL_SECTION critsec = (LPCRITICAL_SECTION)mutex;
LeaveCriticalSection(critsec);
return 1;
}
void
thread_close_mutex(mutex_t *mutex)
{
if (mutex == NULL) return;
LPCRITICAL_SECTION critsec = (LPCRITICAL_SECTION)mutex;
DeleteCriticalSection(critsec);
free(critsec);
}
#else
#include <pthread.h>
#include <unistd.h>
typedef struct event_pthread_t typedef struct event_pthread_t
{ {
pthread_cond_t cond; pthread_cond_t cond;
pthread_mutex_t mutex; pthread_mutex_t mutex;
int state; int state;
} event_pthread_t; } event_pthread_t;
typedef struct thread_param
{
void (*thread_rout)(void*);
void * param;
} thread_param;
typedef struct pt_mutex_t typedef struct pt_mutex_t
{ {
pthread_mutex_t mutex; pthread_mutex_t mutex;
} pt_mutex_t; } pt_mutex_t;
void *
thread_run_wrapper(thread_param* arg)
{
thread_param localparam = *arg;
free(arg);
localparam.thread_rout(localparam.param);
return NULL;
}
thread_t * thread_t *
thread_create(void (*thread_rout)(void *param), void *param) thread_create(void (*thread_rout)(void *param), void *param)
{ {
pthread_t *thread = malloc(sizeof(pthread_t)); pthread_t *thread = malloc(sizeof(pthread_t));
thread_param *thrparam = malloc(sizeof(thread_param));
thrparam->thread_rout = thread_rout;
thrparam->param = param;
pthread_create(thread, NULL, (void*)thread_rout, param); pthread_create(thread, NULL, (void* (*)(void*))thread_run_wrapper, thrparam);
return thread; return thread;
} }
@@ -240,13 +101,10 @@ thread_wait_event(event_t *handle, int timeout)
event_pthread_t *event = (event_pthread_t *)handle; event_pthread_t *event = (event_pthread_t *)handle;
struct timespec abstime; struct timespec abstime;
#ifdef __linux__ #ifdef HAS_TIMESPEC_GET
clock_gettime(CLOCK_REALTIME, &abstime); timespec_get(&abstime, TIME_UTC);
#else #else
struct timeval now; clock_gettime(CLOCK_REALTIME, &abstime);
gettimeofday(&now, 0);
abstime.tv_sec = now.tv_sec;
abstime.tv_nsec = now.tv_usec*1000UL;
#endif #endif
abstime.tv_nsec += (timeout % 1000) * 1000000; abstime.tv_nsec += (timeout % 1000) * 1000000;
abstime.tv_sec += (timeout / 1000); abstime.tv_sec += (timeout / 1000);
@@ -301,22 +159,23 @@ thread_create_mutex_with_spin_count(unsigned int spin_count)
int int
thread_wait_mutex(mutex_t *_mutex) thread_wait_mutex(mutex_t *_mutex)
{ {
if (_mutex == NULL)
return(0);
pt_mutex_t *mutex = (pt_mutex_t *)_mutex; pt_mutex_t *mutex = (pt_mutex_t *)_mutex;
pthread_mutex_lock(&mutex->mutex); return
pthread_mutex_lock(&mutex->mutex) != 0;
return 1;
} }
int int
thread_release_mutex(mutex_t *_mutex) thread_release_mutex(mutex_t *_mutex)
{ {
if (_mutex == NULL)
return(0);
pt_mutex_t *mutex = (pt_mutex_t *)_mutex; pt_mutex_t *mutex = (pt_mutex_t *)_mutex;
pthread_mutex_unlock(&mutex->mutex); return pthread_mutex_unlock(&mutex->mutex) != 0;
return 1;
} }
@@ -329,4 +188,3 @@ thread_close_mutex(mutex_t *_mutex)
free(mutex); free(mutex);
} }
#endif

View File

@@ -1847,11 +1847,11 @@ s3_hwcursor_draw(svga_t *svga, int displine)
if (svga->crtc[0x55] & 0x10) { if (svga->crtc[0x55] & 0x10) {
/*X11*/ /*X11*/
for (xx = 0; xx < 16; xx++) { for (xx = 0; xx < 16; xx++) {
if (offset >= svga->hwcursor_latch.x) { if (offset >= 0) {
if (dat[0] & 0x8000) if (dat[0] & 0x8000)
buffer32->line[displine][offset + svga->x_add] = (dat[1] & 0x8000) ? fg : bg; buffer32->line[displine][offset + svga->x_add] = (dat[1] & 0x8000) ? fg : bg;
} }
offset++; offset++;
dat[0] <<= shift; dat[0] <<= shift;
dat[1] <<= shift; dat[1] <<= shift;
@@ -1859,16 +1859,16 @@ s3_hwcursor_draw(svga_t *svga, int displine)
} else { } else {
/*Windows*/ /*Windows*/
for (xx = 0; xx < width; xx++) { for (xx = 0; xx < width; xx++) {
if (offset >= svga->hwcursor_latch.x) { if (offset >= 0) {
if (!(dat[0] & 0x8000)) if (!(dat[0] & 0x8000))
buffer32->line[displine][offset + svga->x_add] = (dat[1] & 0x8000) ? fg : bg; buffer32->line[displine][offset + svga->x_add] = (dat[1] & 0x8000) ? fg : bg;
else if (dat[1] & 0x8000) else if (dat[1] & 0x8000)
buffer32->line[displine][offset + svga->x_add] ^= 0xffffff; buffer32->line[displine][offset + svga->x_add] ^= 0xffffff;
} }
offset++; offset++;
dat[0] <<= shift; dat[0] <<= shift;
dat[1] <<= shift; dat[1] <<= shift;
} }
} }
svga->hwcursor_latch.addr += 4; svga->hwcursor_latch.addr += 4;

View File

@@ -3316,7 +3316,7 @@ static void s3_virge_hwcursor_draw(svga_t *svga, int displine)
/*X11*/ /*X11*/
for (xx = 0; xx < 16; xx++) for (xx = 0; xx < 16; xx++)
{ {
if (offset >= svga->hwcursor_latch.x) if (offset >= 0)
{ {
if (dat[0] & 0x8000) if (dat[0] & 0x8000)
buffer32->line[displine][offset + svga->x_add] = (dat[1] & 0x8000) ? fg : bg; buffer32->line[displine][offset + svga->x_add] = (dat[1] & 0x8000) ? fg : bg;
@@ -3332,7 +3332,7 @@ static void s3_virge_hwcursor_draw(svga_t *svga, int displine)
/*Windows*/ /*Windows*/
for (xx = 0; xx < 16; xx++) for (xx = 0; xx < 16; xx++)
{ {
if (offset >= svga->hwcursor_latch.x) if (offset >= 0)
{ {
if (!(dat[0] & 0x8000)) if (!(dat[0] & 0x8000))
buffer32->line[displine][offset + svga->x_add] = (dat[1] & 0x8000) ? fg : bg; buffer32->line[displine][offset + svga->x_add] = (dat[1] & 0x8000) ? fg : bg;

View File

@@ -15,7 +15,7 @@
enable_language(RC) enable_language(RC)
add_library(plat OBJECT win.c win_dynld.c win_cdrom.c add_library(plat OBJECT win.c win_dynld.c win_cdrom.c win_thread.c
win_keyboard.c win_crashdump.c win_midi.c win_mouse.c) win_keyboard.c win_crashdump.c win_midi.c win_mouse.c)
add_library(ui OBJECT win_ui.c win_stbar.c win_sdl.c win_dialog.c win_about.c add_library(ui OBJECT win_ui.c win_stbar.c win_sdl.c win_dialog.c win_about.c
@@ -58,9 +58,5 @@ if(OPENGL)
target_sources(ui PRIVATE glad.c win_opengl.c win_opengl_glslp.c) target_sources(ui PRIVATE glad.c win_opengl.c win_opengl_glslp.c)
endif() endif()
if(NOT PTHREAD)
target_sources(plat PRIVATE win_thread.c)
endif()
target_link_libraries(86Box advapi32 comctl32 comdlg32 gdi32 shell32 iphlpapi target_link_libraries(86Box advapi32 comctl32 comdlg32 gdi32 shell32 iphlpapi
dxguid imm32 hid setupapi uxtheme version winmm psapi) dxguid imm32 hid setupapi uxtheme version winmm psapi)

View File

@@ -26,10 +26,6 @@ ifndef DEV_BUILD
DEV_BUILD := n DEV_BUILD := n
endif endif
ifneq ($(PTHREAD), n)
PTHREAD := y
endif
ifeq ($(DEV_BUILD), y) ifeq ($(DEV_BUILD), y)
ifndef DEBUG ifndef DEBUG
DEBUG := y DEBUG := y
@@ -589,17 +585,10 @@ CXXFLAGS := $(CFLAGS)
######################################################################### #########################################################################
# Create the (final) list of objects to build. # # Create the (final) list of objects to build. #
######################################################################### #########################################################################
ifeq ($(PTHREAD), y)
MAINOBJ := 86box.o config.o log.o random.o timer.o io.o acpi.o apm.o dma.o ddma.o \
nmi.o pic.o pit.o port_6x.o port_92.o ppi.o pci.o mca.o \
usb.o device.o nvr.o nvr_at.o nvr_ps2.o thread.o \
$(VNCOBJ)
else
MAINOBJ := 86box.o config.o log.o random.o timer.o io.o acpi.o apm.o dma.o ddma.o \ MAINOBJ := 86box.o config.o log.o random.o timer.o io.o acpi.o apm.o dma.o ddma.o \
nmi.o pic.o pit.o port_6x.o port_92.o ppi.o pci.o mca.o \ nmi.o pic.o pit.o port_6x.o port_92.o ppi.o pci.o mca.o \
usb.o device.o nvr.o nvr_at.o nvr_ps2.o \ usb.o device.o nvr.o nvr_at.o nvr_ps2.o \
$(VNCOBJ) $(VNCOBJ)
endif
MEMOBJ := catalyst_flash.o i2c_eeprom.o intel_flash.o mem.o rom.o smram.o spd.o sst_flash.o MEMOBJ := catalyst_flash.o i2c_eeprom.o intel_flash.o mem.o rom.o smram.o spd.o sst_flash.o
@@ -801,19 +790,11 @@ VOODOOOBJ := vid_voodoo.o vid_voodoo_banshee.o \
vid_voodoo_render.o vid_voodoo_setup.o \ vid_voodoo_render.o vid_voodoo_setup.o \
vid_voodoo_texture.o vid_voodoo_texture.o
ifeq ($(PTHREAD), y)
PLATOBJ := win.o \
win_dynld.o \
win_cdrom.o win_keyboard.o \
win_crashdump.o win_midi.o \
win_mouse.o
else
PLATOBJ := win.o \ PLATOBJ := win.o \
win_dynld.o win_thread.o \ win_dynld.o win_thread.o \
win_cdrom.o win_keyboard.o \ win_cdrom.o win_keyboard.o \
win_crashdump.o win_midi.o \ win_crashdump.o win_midi.o \
win_mouse.o win_mouse.o
endif
ifeq ($(DINPUT), y) ifeq ($(DINPUT), y)
PLATOBJ += win_joystick.o PLATOBJ += win_joystick.o
@@ -839,11 +820,7 @@ endif
ifneq ($(WX), n) ifneq ($(WX), n)
LIBS += $(WX_LIBS) -lm LIBS += $(WX_LIBS) -lm
endif endif
ifeq ($(PTHREAD), y)
LIBS += -lpng -lz -lwsock32 -lshell32 -liphlpapi -lpsapi -lSDL2 -limm32 -lhid -lsetupapi -loleaut32 -luxtheme -lversion -lwinmm -static -lstdc++ -lpthread
else
LIBS += -lpng -lz -lwsock32 -lshell32 -liphlpapi -lpsapi -lSDL2 -limm32 -lhid -lsetupapi -loleaut32 -luxtheme -lversion -lwinmm -static -lstdc++ LIBS += -lpng -lz -lwsock32 -lshell32 -liphlpapi -lpsapi -lSDL2 -limm32 -lhid -lsetupapi -loleaut32 -luxtheme -lversion -lwinmm -static -lstdc++
endif
ifneq ($(X64), y) ifneq ($(X64), y)
ifneq ($(ARM64), y) ifneq ($(ARM64), y)
LIBS += -Wl,--large-address-aware LIBS += -Wl,--large-address-aware