Helper.cpp revision 4a483241663cfa1ec31b562ebc7bdc41022f3bfa
/** @file
*
* VBox frontends: VBoxSDL (simple frontend based on SDL):
* Miscellaneous helpers
*/
/*
* Copyright (C) 2006-2007 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#define LOG_GROUP LOG_GROUP_GUI
#include <iprt/semaphore.h>
#include "VBoxSDL.h"
#include "Helper.h"
/**
* Globals
*/
#ifdef USE_XPCOM_QUEUE_THREAD
/** global flag indicating that the event queue thread should terminate */
static bool volatile g_fTerminateXPCOMQueueThread = false;
/** How many XPCOM user events are on air. Only allow one pending event to
* prevent an overflow of the SDL event queue. */
static volatile int32_t g_s32XPCOMEventsPending;
/** Semaphore the XPCOM event thread will sleep on while it waits for the main thread to process pending requests. */
/**
* Thread method to wait for XPCOM events and notify the SDL thread.
*
* @returns Error code
* @param thread Thread ID
* @param pvUser User specific parameter, the file descriptor
* of the event queue socket
*/
{
unsigned cErrors = 0;
int rc;
/* Wait with the processing till the main thread needs it. */
do
{
/* are there any events to process? */
if ((n > 0) && !g_fTerminateXPCOMQueueThread)
{
/*
* Wait until all XPCOM events are processed. 1s just for sanity.
*/
int iWait = 1000;
/*
* Don't post an event if there is a pending XPCOM event to prevent an
* overflow of the SDL event queue.
*/
if (g_s32XPCOMEventsPending < 1)
{
/*
* Post the event and wait for it to be processed. If we don't wait,
* we'll flood the queue on SMP systems and when the main thread is busy.
* In the event of a push error, we'll yield the timeslice and retry.
*/
if (!rc)
{
/* success */
cErrors = 0;
}
else
{
/* failure */
cErrors++;
if (!RTThreadYield())
RTThreadSleep(2);
}
}
else
if (iWait)
}
} while (!g_fTerminateXPCOMQueueThread);
return VINF_SUCCESS;
}
/**
* Creates the XPCOM event thread
*
* @returns VBOX status code
* @param eqFD XPCOM event queue file descriptor
*/
int startXPCOMEventQueueThread(int eqFD)
{
if (RT_SUCCESS(rc))
{
0, RTTHREADTYPE_MSG_PUMP, 0, "XPCOMEvent");
}
return rc;
}
/**
* Notify the XPCOM thread that we consumed an XPCOM event.
*/
void consumedXPCOMUserEvent(void)
{
}
/**
* Signal to the XPCOM even queue thread that it should select for more events.
*/
void signalXPCOMEventQueueThread(void)
{
}
/**
* Indicates to the XPCOM thread that it should terminate now.
*/
void terminateXPCOMQueueThread(void)
{
g_fTerminateXPCOMQueueThread = true;
{
}
}
#endif /* USE_XPCOM_QUEUE_THREAD */