Moved all Bochs multi-threading definitions from bochs.h and osdep.h to a new
file called "bxthread.h".
This commit is contained in:
parent
ad9f1c3417
commit
b61b9d255a
@ -629,32 +629,4 @@ BX_CPP_INLINE Bit64u bx_bswap64(Bit64u val64)
|
||||
#define CopyHostQWordLittleEndian(hostAddrDst, hostAddrSrc) \
|
||||
(* (Bit64u *)(hostAddrDst)) = (* (Bit64u *)(hostAddrSrc));
|
||||
|
||||
// multithreading support
|
||||
#ifdef WIN32
|
||||
#define BX_THREAD_VAR(name) HANDLE (name)
|
||||
#define BX_THREAD_FUNC(name,arg) DWORD WINAPI name(LPVOID arg)
|
||||
#define BX_THREAD_EXIT return 0
|
||||
#define BX_THREAD_CREATE(name,arg,var) do { var = CreateThread(NULL, 0, name, arg, 0, NULL); } while (0)
|
||||
#define BX_THREAD_KILL(var) TerminateThread(var, 0)
|
||||
#define BX_LOCK(mutex) EnterCriticalSection(&(mutex))
|
||||
#define BX_UNLOCK(mutex) LeaveCriticalSection(&(mutex))
|
||||
#define BX_MUTEX(mutex) CRITICAL_SECTION (mutex)
|
||||
#define BX_INIT_MUTEX(mutex) InitializeCriticalSection(&(mutex))
|
||||
#define BX_FINI_MUTEX(mutex) DeleteCriticalSection(&(mutex))
|
||||
#define BX_MSLEEP(val) Sleep(val)
|
||||
#else
|
||||
#define BX_THREAD_VAR(name) pthread_t (name)
|
||||
#define BX_THREAD_FUNC(name,arg) void name(void* arg)
|
||||
#define BX_THREAD_EXIT pthread_exit(NULL)
|
||||
#define BX_THREAD_CREATE(name,arg,var) \
|
||||
pthread_create(&(var), NULL, (void *(*)(void *))&(name), arg)
|
||||
#define BX_THREAD_KILL(var) pthread_cancel(var); pthread_join(var, NULL)
|
||||
#define BX_LOCK(mutex) pthread_mutex_lock(&(mutex));
|
||||
#define BX_UNLOCK(mutex) pthread_mutex_unlock(&(mutex));
|
||||
#define BX_MUTEX(mutex) pthread_mutex_t (mutex)
|
||||
#define BX_INIT_MUTEX(mutex) pthread_mutex_init(&(mutex),NULL)
|
||||
#define BX_FINI_MUTEX(mutex) pthread_mutex_destroy(&(mutex))
|
||||
#define BX_MSLEEP(val) usleep(val*1000)
|
||||
#endif
|
||||
|
||||
#endif /* BX_BOCHS_H */
|
||||
|
73
bochs/bxthread.h
Normal file
73
bochs/bxthread.h
Normal file
@ -0,0 +1,73 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $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
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef BX_THREAD_H
|
||||
#define BX_THREAD_H
|
||||
|
||||
#ifndef WIN32
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
// Bochs multi-threading support
|
||||
|
||||
#ifdef WIN32
|
||||
#define BX_THREAD_VAR(name) HANDLE (name)
|
||||
#define BX_THREAD_FUNC(name,arg) DWORD WINAPI name(LPVOID arg)
|
||||
#define BX_THREAD_EXIT return 0
|
||||
#define BX_THREAD_CREATE(name,arg,var) do { var = CreateThread(NULL, 0, name, arg, 0, NULL); } while (0)
|
||||
#define BX_THREAD_KILL(var) TerminateThread(var, 0)
|
||||
#define BX_LOCK(mutex) EnterCriticalSection(&(mutex))
|
||||
#define BX_UNLOCK(mutex) LeaveCriticalSection(&(mutex))
|
||||
#define BX_MUTEX(mutex) CRITICAL_SECTION (mutex)
|
||||
#define BX_INIT_MUTEX(mutex) InitializeCriticalSection(&(mutex))
|
||||
#define BX_FINI_MUTEX(mutex) DeleteCriticalSection(&(mutex))
|
||||
#define BX_MSLEEP(val) Sleep(val)
|
||||
#else
|
||||
#define BX_THREAD_VAR(name) pthread_t (name)
|
||||
#define BX_THREAD_FUNC(name,arg) void name(void* arg)
|
||||
#define BX_THREAD_EXIT pthread_exit(NULL)
|
||||
#define BX_THREAD_CREATE(name,arg,var) \
|
||||
pthread_create(&(var), NULL, (void *(*)(void *))&(name), arg)
|
||||
#define BX_THREAD_KILL(var) pthread_cancel(var); pthread_join(var, NULL)
|
||||
#define BX_LOCK(mutex) pthread_mutex_lock(&(mutex));
|
||||
#define BX_UNLOCK(mutex) pthread_mutex_unlock(&(mutex));
|
||||
#define BX_MUTEX(mutex) pthread_mutex_t (mutex)
|
||||
#define BX_INIT_MUTEX(mutex) pthread_mutex_init(&(mutex),NULL)
|
||||
#define BX_FINI_MUTEX(mutex) pthread_mutex_destroy(&(mutex))
|
||||
#define BX_MSLEEP(val) usleep(val*1000)
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
#ifdef WIN32
|
||||
HANDLE event;
|
||||
#else
|
||||
pthread_cond_t cond;
|
||||
pthread_mutex_t mutex;
|
||||
#endif
|
||||
} bx_thread_event_t;
|
||||
|
||||
void bx_create_event(bx_thread_event_t *thread_ev);
|
||||
void bx_destroy_event(bx_thread_event_t *thread_ev);
|
||||
void bx_set_event(bx_thread_event_t *thread_ev);
|
||||
bx_bool bx_wait_for_event(bx_thread_event_t *thread_ev);
|
||||
|
||||
#endif
|
@ -46,6 +46,9 @@
|
||||
#include "rfb.h"
|
||||
#include "rfbkeys.h"
|
||||
|
||||
#include "bxthread.h"
|
||||
|
||||
|
||||
class bx_rfb_gui_c : public bx_gui_c {
|
||||
public:
|
||||
bx_rfb_gui_c (void) {}
|
||||
@ -87,9 +90,6 @@ IMPLEMENT_GUI_PLUGIN_CODE(rfb)
|
||||
#else
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#if !defined(__CYGWIN__)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
typedef int SOCKET;
|
||||
#ifndef INVALID_SOCKET
|
||||
|
@ -59,6 +59,9 @@
|
||||
#include "rfb.h"
|
||||
#include "rfbkeys.h"
|
||||
|
||||
#include "bxthread.h"
|
||||
|
||||
|
||||
class bx_vncsrv_gui_c: public bx_gui_c {
|
||||
public:
|
||||
bx_vncsrv_gui_c(void) : screen(NULL) {}
|
||||
@ -100,7 +103,6 @@ IMPLEMENT_GUI_PLUGIN_CODE(vncsrv)
|
||||
#else
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#include <pthread.h>
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -70,15 +70,12 @@
|
||||
#include "vgacore.h"
|
||||
#include "voodoo.h"
|
||||
#include "virt_timer.h"
|
||||
#include "bxthread.h"
|
||||
|
||||
#define LOG_THIS theVoodooDevice->
|
||||
|
||||
bx_voodoo_c* theVoodooDevice = NULL;
|
||||
|
||||
#ifndef WIN32
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include "voodoo_types.h"
|
||||
#include "voodoo_data.h"
|
||||
#include "voodoo_main.h"
|
||||
|
@ -20,9 +20,7 @@
|
||||
|
||||
// Common code for sound lowlevel modules
|
||||
|
||||
#ifndef WIN32
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#include "bxthread.h"
|
||||
|
||||
#if BX_HAVE_LIBSAMPLERATE
|
||||
#include <samplerate.h>
|
||||
|
@ -25,9 +25,6 @@
|
||||
#include "speaker.h"
|
||||
|
||||
#if BX_SUPPORT_SOUNDLOW
|
||||
#ifndef WIN32
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#include "sound/soundlow.h"
|
||||
#include "sound/soundmod.h"
|
||||
#endif
|
||||
|
@ -2,7 +2,7 @@
|
||||
// $Id$
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2001-2016 The Bochs Project
|
||||
// Copyright (C) 2001-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
|
||||
@ -21,13 +21,10 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "bochs.h"
|
||||
#include "bxthread.h"
|
||||
#include "cpu/cpu.h"
|
||||
#include <assert.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#if BX_WITH_CARBON
|
||||
#include <Carbon/Carbon.h>
|
||||
#endif
|
||||
|
@ -30,6 +30,7 @@
|
||||
//
|
||||
|
||||
#include "bochs.h"
|
||||
#include "bxthread.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Missing library functions. These should work on any platform
|
||||
|
@ -379,23 +379,4 @@ extern Bit64u bx_get_realtime64_usec (void);
|
||||
|
||||
#endif // BX_LARGE_RAMFILE
|
||||
|
||||
#ifndef WIN32
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
#ifdef WIN32
|
||||
HANDLE event;
|
||||
#else
|
||||
pthread_cond_t cond;
|
||||
pthread_mutex_t mutex;
|
||||
#endif
|
||||
} bx_thread_event_t;
|
||||
|
||||
void bx_create_event(bx_thread_event_t *thread_ev);
|
||||
void bx_destroy_event(bx_thread_event_t *thread_ev);
|
||||
void bx_set_event(bx_thread_event_t *thread_ev);
|
||||
bx_bool bx_wait_for_event(bx_thread_event_t *thread_ev);
|
||||
|
||||
#endif /* ifdef BX_OSDEP_H */
|
||||
|
Loading…
Reference in New Issue
Block a user