Moved all Bochs event / wait functions required for multi-threading to a new

file called "bxthread.cc".
This commit is contained in:
Volker Ruppert 2017-09-14 16:18:12 +00:00
parent 2a47615bb6
commit 0311f47bc3
4 changed files with 84 additions and 53 deletions

View File

@ -143,6 +143,7 @@ NONINLINE_OBJS = \
osdep.o \
plugin.o \
crc.o \
bxthread.o \
@EXTRA_BX_OBJS@
EXTERN_ENVIRONMENT_OBJS = \
@ -784,6 +785,10 @@ install_macosx: all download_dlx install_man @INSTALL_DOCBOOK_VAR@
# dependencies generated by
# gcc -MM -I. -Iinstrument/stubs *.cc | sed -e 's/\.cc/.@CPP_SUFFIX@/g' -e 's,cpu/,cpu/,g'
###########################################
bxthread.o: bxthread.@CPP_SUFFIX@ bochs.h config.h osdep.h bx_debug/debug.h \
config.h osdep.h gui/siminterface.h cpudb.h gui/paramtree.h \
memory/memory-bochs.h pc_system.h gui/gui.h \
instrument/stubs/instrument.h bxthread.h
config.o: config.@CPP_SUFFIX@ bochs.h config.h osdep.h bx_debug/debug.h config.h \
osdep.h gui/siminterface.h cpudb.h gui/paramtree.h memory/memory-bochs.h \
pc_system.h gui/gui.h instrument/stubs/instrument.h bxversion.h \
@ -809,7 +814,7 @@ load32bitOShack.o: load32bitOShack.@CPP_SUFFIX@ bochs.h config.h osdep.h \
iodev/iodev.h bochs.h plugin.h extplugin.h param_names.h
logio.o: logio.@CPP_SUFFIX@ bochs.h config.h osdep.h bx_debug/debug.h config.h \
osdep.h gui/siminterface.h cpudb.h gui/paramtree.h memory/memory-bochs.h \
pc_system.h gui/gui.h instrument/stubs/instrument.h cpu/cpu.h \
pc_system.h gui/gui.h instrument/stubs/instrument.h bxthread.h cpu/cpu.h \
cpu/decoder/decoder.h cpu/i387.h cpu/fpu/softfloat.h cpu/fpu/tag_w.h \
cpu/fpu/status_w.h cpu/fpu/control_w.h cpu/crregs.h cpu/descriptor.h \
cpu/decoder/instr.h cpu/decoder/ia_opcodes.h cpu/lazy_flags.h cpu/tlb.h \
@ -825,7 +830,7 @@ main.o: main.@CPP_SUFFIX@ bochs.h config.h osdep.h bx_debug/debug.h config.h \
bochs.h plugin.h extplugin.h param_names.h
osdep.o: osdep.@CPP_SUFFIX@ bochs.h config.h osdep.h bx_debug/debug.h config.h \
osdep.h gui/siminterface.h cpudb.h gui/paramtree.h memory/memory-bochs.h \
pc_system.h gui/gui.h instrument/stubs/instrument.h
pc_system.h gui/gui.h instrument/stubs/instrument.h bxthread.h
pc_system.o: pc_system.@CPP_SUFFIX@ bochs.h config.h osdep.h bx_debug/debug.h \
config.h osdep.h gui/siminterface.h cpudb.h gui/paramtree.h \
memory/memory-bochs.h pc_system.h gui/gui.h \

72
bochs/bxthread.cc Normal file
View File

@ -0,0 +1,72 @@
/////////////////////////////////////////////////////////////////////////
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
/////////////////////////////////////////////////////////////////////////
#include "bochs.h"
#include "bxthread.h"
// Bochs multi-threading support
void bx_create_event(bx_thread_event_t *thread_ev)
{
#ifdef WIN32
thread_ev->event = CreateEvent(NULL, FALSE, FALSE, "event");
#else
pthread_cond_init(&thread_ev->cond, NULL);
pthread_mutex_init(&thread_ev->mutex, NULL);
#endif
}
void bx_destroy_event(bx_thread_event_t *thread_ev)
{
#ifdef WIN32
CloseHandle(thread_ev->event);
#else
pthread_cond_destroy(&thread_ev->cond);
pthread_mutex_destroy(&thread_ev->mutex);
#endif
}
void bx_set_event(bx_thread_event_t *thread_ev)
{
#ifdef WIN32
SetEvent(thread_ev->event);
#else
pthread_mutex_lock(&thread_ev->mutex);
pthread_cond_signal(&thread_ev->cond);
pthread_mutex_unlock(&thread_ev->mutex);
#endif
}
bx_bool bx_wait_for_event(bx_thread_event_t *thread_ev)
{
#ifdef WIN32
if (WaitForSingleObject(thread_ev->event, 1) == WAIT_OBJECT_0) {
return 1;
} else {
return 0;
}
#else
pthread_mutex_lock(&thread_ev->mutex);
pthread_cond_wait(&thread_ev->cond, &thread_ev->mutex);
pthread_mutex_unlock(&thread_ev->mutex);
return 1;
#endif
}

View File

@ -1,4 +1,4 @@
# Copyright (C) 2012-2014 The Bochs Project
# Copyright (C) 2012-2017 The Bochs Project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@ -152,7 +152,8 @@ voodoo.o: voodoo.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h ../../osde
../../memory/memory-bochs.h ../../pc_system.h ../../gui/gui.h \
../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
../../param_names.h ../pci.h vgacore.h voodoo.h ../virt_timer.h \
voodoo_types.h voodoo_data.h voodoo_main.h voodoo_func.h voodoo_raster.h
../../bxthread.h voodoo_types.h voodoo_data.h voodoo_main.h \
voodoo_func.h voodoo_raster.h
svga_cirrus.lo: svga_cirrus.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
@ -177,4 +178,5 @@ voodoo.lo: voodoo.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h ../../osd
../../memory/memory-bochs.h ../../pc_system.h ../../gui/gui.h \
../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
../../param_names.h ../pci.h vgacore.h voodoo.h ../virt_timer.h \
voodoo_types.h voodoo_data.h voodoo_main.h voodoo_func.h voodoo_raster.h
../../bxthread.h voodoo_types.h voodoo_data.h voodoo_main.h \
voodoo_func.h voodoo_raster.h

View File

@ -370,51 +370,3 @@ Bit64u bx_get_realtime64_usec(void)
}
#endif
#endif
void bx_create_event(bx_thread_event_t *thread_ev)
{
#ifdef WIN32
thread_ev->event = CreateEvent(NULL, FALSE, FALSE, "event");
#else
pthread_cond_init(&thread_ev->cond, NULL);
pthread_mutex_init(&thread_ev->mutex, NULL);
#endif
}
void bx_destroy_event(bx_thread_event_t *thread_ev)
{
#ifdef WIN32
CloseHandle(thread_ev->event);
#else
pthread_cond_destroy(&thread_ev->cond);
pthread_mutex_destroy(&thread_ev->mutex);
#endif
}
void bx_set_event(bx_thread_event_t *thread_ev)
{
#ifdef WIN32
SetEvent(thread_ev->event);
#else
pthread_mutex_lock(&thread_ev->mutex);
pthread_cond_signal(&thread_ev->cond);
pthread_mutex_unlock(&thread_ev->mutex);
#endif
}
bx_bool bx_wait_for_event(bx_thread_event_t *thread_ev)
{
#ifdef WIN32
if (WaitForSingleObject(thread_ev->event, 1) == WAIT_OBJECT_0) {
return 1;
} else {
return 0;
}
#else
pthread_mutex_lock(&thread_ev->mutex);
pthread_cond_wait(&thread_ev->cond, &thread_ev->mutex);
pthread_mutex_unlock(&thread_ev->mutex);
return 1;
#endif
}