I submit this patch to point out a problem. Not for review.

来自我的华为手机


-------- 原始邮件 --------
主题:Re: [vbox-dev] vbox-dev@virtualbox.org
发件人:Michal Necasek
收件人:manjian2...@gmail.com
抄送:vbox-dev@virtualbox.org



I'm sure this solves a real problem, unfortunately I'm also certain this patch has absolutely zero chance of being accepted the way it is.

The code you're changing is currently under development (and known to be less than perfect). What revision exactly is the patch intended for? It's possible that it's already been fixed, or if not, will be soon enough.

- Michal

----- Original Message -----
From: manjian2...@gmail.com
To: vbox-dev@virtualbox.org
Sent: Friday, December 25, 2015 8:45:19 AM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
Subject: [vbox-dev] vbox-dev@virtualbox.org

Hi friends,
I find my vbox will hanging after a short while playing Android
games. Then I use debugger and figure out linux kernel driver of
intel ac97 is dead looping. And this is result from the
multithreading data inconsistency.
So I use my patch:
diff --git a/include/iprt/AutoLock.h b/include/iprt/AutoLock.h
new file mode 100644
index 0000000..c15a19b
--- /dev/null
+++ b/include/iprt/AutoLock.h
@@ -0,0 +1,48 @@
+#ifndef __XX_AUTOLOCK__
+#define __XX_AUTOLOCK__
+#include
+
+class CLock
+{
+public:
+ CLock(void){
+ Init();
+ }
+ ~CLock(){
+ Close();
+ }
+ void Lock(){
+ RTCritSectEnter(&m_lock);
+ }
+ void UnLock(){
+ RTCritSectLeave(&m_lock);
+ }
+private:
+ RTCRITSECT m_lock;
+ void Init(){
+ RTCritSectInit(&m_lock);
+ }
+ void Close(){
+ RTCritSectDelete(&m_lock);
+ }
+};
+
+class CAutoLock{
+public:
+ CAutoLock(CLock *pLock){
+ m_pLock=pLock;
+ if (NULL!=m_pLock)
+ {
+ m_pLock->Lock();
+ }
+ }
+ ~CAutoLock(){
+ if (NULL!=m_pLock)
+ {
+ m_pLock->UnLock();
+ }
+ }
+private:
+ CLock * m_pLock;
+};
+#endif
\ No newline at end of file
diff --git a/src/VBox/Devices/Audio/DevIchAc97.cpp b/src/VBox/Devices/Audio/DevIchAc97.cpp
index 84ac678..ddc199b 100644
--- a/src/VBox/Devices/Audio/DevIchAc97.cpp
+++ b/src/VBox/Devices/Audio/DevIchAc97.cpp
@@ -24,6 +24,8 @@
#include
#include

+#include
+
#include "VBoxDD.h"

extern "C" {
@@ -186,7 +188,7 @@ typedef struct AC97BusMasterRegs
} AC97BusMasterRegs;
/** Pointer to a AC97 bus master register. */
typedef AC97BusMasterRegs *PAC97BMREG;
-
+static CLock g_alock;
typedef struct AC97STATE
{
/** The PCI device state. */
@@ -743,6 +745,7 @@ static int read_audio(PAC97STATE pThis, PAC97BMREG pReg, int max, int *stop)

static void transfer_audio(PAC97STATE pThis, int index, int elapsed)
{
+ CAutoLock alock(&g_alock);
PAC97BMREG pReg = &pThis->bm_regs[index];
int written = 0;
int stop = 0;
@@ -853,6 +856,7 @@ static void po_callback(void *opaque, int free)
*/
static DECLCALLBACK(int) ichac97IOPortNABMRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
{
+ CAutoLock alock(&g_alock);
PAC97STATE pThis = (PAC97STATE)pvUser;

switch (cb)
@@ -1013,6 +1017,7 @@ static DECLCALLBACK(int) ichac97IOPortNABMRead(PPDMDEVINS pDevIns, void *pvUser,
*/
static DECLCALLBACK(int) ichac97IOPortNABMWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
{
+ CAutoLock alock(&g_alock);
PAC97STATE pThis = (PAC97STATE)pvUser;

switch (cb)
@@ -1151,6 +1156,7 @@ static DECLCALLBACK(int) ichac97IOPortNABMWrite(PPDMDEVINS pDevIns, void *pvUser
*/
static DECLCALLBACK(int) ichac97IOPortNAMRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
{
+ CAutoLock alock(&g_alock);
PAC97STATE pThis = (PAC97STATE)pvUser;

switch (cb)
@@ -1197,6 +1203,7 @@ static DECLCALLBACK(int) ichac97IOPortNAMRead(PPDMDEVINS pDevIns, void *pvUser,
*/
static DECLCALLBACK(int) ichac97IOPortNAMWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
{
+ CAutoLock alock(&g_alock);
PAC97STATE pThis = (PAC97STATE)pvUser;

switch (cb)
@@ -1457,6 +1464,7 @@ static DECLCALLBACK(void *) ichac97QueryInterface(struct PDMIBASE *pInterface, c
*/
static DECLCALLBACK(void) ac97Reset(PPDMDEVINS pDevIns)
{
+ CAutoLock alock(&g_alock);
PAC97STATE pThis = PDMINS_2_DATA(pDevIns, AC97STATE *);

/*

The patch is mean to protect the data accessing from different
thread between CPU thread which is invoking timer and
the CPU thread which is runing Linux intel ac97 drivers.
--
Lin Zuojian

_______________________________________________
vbox-dev mailing list
vbox-dev@virtualbox.org
https://www.virtualbox.org/mailman/listinfo/vbox-dev
_______________________________________________
vbox-dev mailing list
vbox-dev@virtualbox.org
https://www.virtualbox.org/mailman/listinfo/vbox-dev

Reply via email to