#include "rar.hpp"
#include "Util.h"
-#ifdef _LINUX
-#include "XSyncUtils.h"
-#include "XEventUtils.h"
-#endif
// a cautious wrapper around strncpy
char *strncpy_null_terminated(char *dest, const char *src, size_t n)
#include "unpack20.cpp"
#endif
-#ifdef _LINUX
-#include "XSyncUtils.h"
-#include "XEventUtils.h"
-#endif
-
Unpack::Unpack(ComprDataIO *DataIO)
{
UnpIO=DataIO;
-#ifdef _LINUX
-#include "XSyncUtils.h"
-#endif
-
#define STARTL1 2
static unsigned int DecL1[]={0x8000,0xa000,0xc000,0xd000,0xe000,0xea00,
0xee00,0xf000,0xf200,0xf200,0xffff};
using namespace std;
-CDelayedMessage::CDelayedMessage(ThreadMessage& msg, unsigned int delay)
+CDelayedMessage::CDelayedMessage(ThreadMessage& msg, unsigned int delay) : CThread("CDelayedMessage")
{
m_msg.dwMessage = msg.dwMessage;
m_msg.dwParam1 = msg.dwParam1;
#define SECTOR_COUNT 52
-CCDDAReader::CCDDAReader()
+CCDDAReader::CCDDAReader() : CThread("CCDDAReader")
{
m_sRipBuffer[0].pbtStream = NULL;
m_sRipBuffer[1].pbtStream = NULL;
#endif
}
-extern "C" BOOL WINAPI dllGetProcessTimes(HANDLE hProcess, LPFILETIME lpCreationTime, LPFILETIME lpExitTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime)
-{
- // since the xbox has only one process, we just take the current thread
- HANDLE h = GetCurrentThread();
- BOOL res = GetThreadTimes(h, lpCreationTime, lpExitTime, lpKernelTime, lpUserTime);
-
- return res;
-}
-
extern "C" int WINAPI dllDuplicateHandle(HANDLE hSourceProcessHandle, // handle to source process
HANDLE hSourceHandle, // handle to duplicate
HANDLE hTargetProcessHandle, // handle to target process
extern "C" HGLOBAL WINAPI dllLoadResource(HMODULE module, HRSRC res);
extern "C" HRSRC WINAPI dllFindResourceA(HMODULE module, LPCTSTR name, LPCTSTR type);
-extern "C" BOOL WINAPI dllGetProcessTimes(HANDLE hProcess, LPFILETIME lpCreationTime, LPFILETIME lpExitTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime);
extern "C" int WINAPI dllGetLocaleInfoA(LCID Locale, LCTYPE LCType, LPTSTR lpLCData, int cchData);
extern "C" UINT WINAPI dllGetConsoleCP();
extern "C" UINT WINAPI dllGetConsoleOutputCP();
CDummyVideoPlayer::CDummyVideoPlayer(IPlayerCallback& callback)
: IPlayer(callback),
- CThread()
+ CThread("CDummyVideoPlayer")
{
m_paused = false;
m_clock = 0;
#pragma mark -
#endif
CMPCOutputThread::CMPCOutputThread(void *device, DllLibCrystalHD *dll, bool has_bcm70015) :
- CThread(),
+ CThread("CMPCOutputThread"),
m_dll(dll),
m_device(device),
m_has_bcm70015(has_bcm70015),
*
*/
-#include "threads/SystemClock.h"
#include "system.h"
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#include "filesystem/Directory.h"
#include "utils/log.h"
#include "threads/Thread.h"
+#include "threads/SystemClock.h"
#include "utils/TimeUtils.h"
void CDemuxStreamAudioFFmpeg::GetStreamInfo(std::string& strInfo)
++it;
}
-#ifdef _MSC_VER
-static __declspec(thread) CDVDDemuxFFmpeg* g_demuxer = 0;
-#else
-static TLS g_tls;
-#define g_demuxer (*((CDVDDemuxFFmpeg**)g_tls.Get()))
-#endif
+static XbmcThreads::ThreadLocal<CDVDDemuxFFmpeg> g_demuxer;
static int interrupt_cb(void* unused)
{
- if(g_demuxer && g_demuxer->Aborted())
+ CDVDDemuxFFmpeg* demuxer = g_demuxer.get();
+ if(demuxer && demuxer->Aborted())
return 1;
return 0;
}
std::string strFile;
m_iCurrentPts = DVD_NOPTS_VALUE;
m_speed = DVD_PLAYSPEED_NORMAL;
- g_demuxer = this;
+ g_demuxer.set(this);
m_program = UINT_MAX;
const AVIOInterruptCB int_cb = { interrupt_cb, NULL };
void CDVDDemuxFFmpeg::Dispose()
{
- g_demuxer = this;
+ g_demuxer.set(this);
if (m_pFormatContext)
{
void CDVDDemuxFFmpeg::Flush()
{
- g_demuxer = this;
+ g_demuxer.set(this);
// naughty usage of an internal ffmpeg function
if (m_pFormatContext)
void CDVDDemuxFFmpeg::SetSpeed(int iSpeed)
{
- g_demuxer = this;
+ g_demuxer.set(this);
if(!m_pFormatContext)
return;
DemuxPacket* CDVDDemuxFFmpeg::Read()
{
- g_demuxer = this;
+ g_demuxer.set(this);
AVPacket pkt;
DemuxPacket* pPacket = NULL;
bool CDVDDemuxFFmpeg::SeekTime(int time, bool backwords, double *startpts)
{
- g_demuxer = this;
+ g_demuxer.set(this);
if(time < 0)
time = 0;
bool CDVDDemuxFFmpeg::SeekByte(__int64 pos)
{
- g_demuxer = this;
+ g_demuxer.set(this);
CSingleLock lock(m_critSection);
int ret = m_dllAvFormat.av_seek_frame(m_pFormatContext, -1, pos, AVSEEK_FLAG_BYTE);
#include "DVDPerformanceCounter.h"
#include "DVDMessageQueue.h"
+#include "utils/TimeUtils.h"
#include "dvd_config.h"
inline __int64 get_thread_cpu_usage(ProcessPerformance* p)
{
- if (p->hThread)
+ if (p->thread)
{
- FILETIME dummy;
- FILETIME current_time_thread;
- FILETIME current_time_system;
ULARGE_INTEGER old_time_thread;
ULARGE_INTEGER old_time_system;
old_time_thread.QuadPart = p->timer_thread.QuadPart;
old_time_system.QuadPart = p->timer_system.QuadPart;
- GetThreadTimes(p->hThread, &dummy, &dummy, ¤t_time_thread, &dummy);
- GetSystemTimeAsFileTime(¤t_time_system);
-
- FILETIME_TO_ULARGE_INTEGER(p->timer_thread, current_time_thread);
- FILETIME_TO_ULARGE_INTEGER(p->timer_system, current_time_system);
+ p->timer_thread.QuadPart = p->thread->GetAbsoluteUsage();
+ p->timer_system.QuadPart = CurrentHostCounter();
__int64 threadTime = (p->timer_thread.QuadPart - old_time_thread.QuadPart);
__int64 systemTime = (p->timer_system.QuadPart - old_time_system.QuadPart);
#define FILETIME_TO_ULARGE_INTEGER(ularge, filetime) { ularge.u.HighPart = filetime.dwHighDateTime; ularge.u.LowPart = filetime.dwLowDateTime; }
#include "system.h"
-
+#include "threads/Thread.h"
#include "threads/SingleLock.h"
class CDVDMessageQueue;
{
ULARGE_INTEGER timer_thread;
ULARGE_INTEGER timer_system;
- HANDLE hThread;
+ CThread* thread;
} ProcessPerformance;
class CDVDPerformanceCounter
bool Initialize();
void DeInitialize();
- void EnableAudioQueue(CDVDMessageQueue* pQueue) { CSingleLock lock(m_critSection); m_pAudioQueue = pQueue; }
- void DisableAudioQueue() { CSingleLock lock(m_critSection); m_pAudioQueue = NULL; }
+ void EnableAudioQueue(CDVDMessageQueue* pQueue) { CSingleLock lock(m_critSection); m_pAudioQueue = pQueue; }
+ void DisableAudioQueue() { CSingleLock lock(m_critSection); m_pAudioQueue = NULL; }
- void EnableVideoQueue(CDVDMessageQueue* pQueue) { CSingleLock lock(m_critSection); m_pVideoQueue = pQueue; }
- void DisableVideoQueue() { CSingleLock lock(m_critSection); m_pVideoQueue = NULL; }
+ void EnableVideoQueue(CDVDMessageQueue* pQueue) { CSingleLock lock(m_critSection); m_pVideoQueue = pQueue; }
+ void DisableVideoQueue() { CSingleLock lock(m_critSection); m_pVideoQueue = NULL; }
- void EnableVideoDecodePerformance(HANDLE hThread) { CSingleLock lock(m_critSection); m_videoDecodePerformance.hThread = hThread; }
- void DisableVideoDecodePerformance() { CSingleLock lock(m_critSection); m_videoDecodePerformance.hThread = NULL; }
+ void EnableVideoDecodePerformance(CThread *thread) { CSingleLock lock(m_critSection); m_videoDecodePerformance.thread = thread; }
+ void DisableVideoDecodePerformance() { CSingleLock lock(m_critSection); m_videoDecodePerformance.thread = NULL; }
- void EnableAudioDecodePerformance(HANDLE hThread) { CSingleLock lock(m_critSection); m_audioDecodePerformance.hThread = hThread; }
- void DisableAudioDecodePerformance() { CSingleLock lock(m_critSection); m_audioDecodePerformance.hThread = NULL; }
+ void EnableAudioDecodePerformance(CThread *thread) { CSingleLock lock(m_critSection); m_audioDecodePerformance.thread = thread; }
+ void DisableAudioDecodePerformance() { CSingleLock lock(m_critSection); m_audioDecodePerformance.thread = NULL; }
- void EnableMainPerformance(HANDLE hThread) { CSingleLock lock(m_critSection); m_mainPerformance.hThread = hThread; }
- void DisableMainPerformance() { CSingleLock lock(m_critSection); m_mainPerformance.hThread = NULL; }
+ void EnableMainPerformance(CThread *thread) { CSingleLock lock(m_critSection); m_mainPerformance.thread = thread; }
+ void DisableMainPerformance() { CSingleLock lock(m_critSection); m_mainPerformance.thread = NULL; }
CDVDMessageQueue* m_pAudioQueue;
CDVDMessageQueue* m_pVideoQueue;
// if playing a file close it first
// this has to be changed so we won't have to close it.
- if(ThreadHandle())
+ if(IsRunning())
CloseFile();
m_bAbortRequest = false;
m_messenger.Init();
- g_dvdPerformanceCounter.EnableMainPerformance(ThreadHandle());
-
+ g_dvdPerformanceCounter.EnableMainPerformance(this);
CUtil::ClearTempFonts();
}
m_dvdPlayerAudio.SendMessage(new CDVDMsg(CDVDMsg::PLAYER_STARTED), 1);
/* audio normally won't consume full cpu, so let it have prio */
- m_dvdPlayerAudio.SetPriority(GetThreadPriority(*this)+1);
+ m_dvdPlayerAudio.SetPriority(GetPriority()+1);
return true;
}
// the CoreAudio audio device handler thread. We do the same for
// the DVDPlayerVideo thread so it can run to sleep without getting
// swapped out by a busy OS.
- m_dvdPlayerVideo.SetPrioritySched_RR();
+ m_dvdPlayerVideo.SetPriority(GetSchedRRPriority());
#else
/* use same priority for video thread as demuxing thread, as */
/* otherwise demuxer will starve if video consumes the full cpu */
- m_dvdPlayerVideo.SetPriority(GetThreadPriority(*this));
+ m_dvdPlayerVideo.SetPriority(GetPriority());
#endif
return true;
m_decode.msg = NULL;
m_decode.Release();
- g_dvdPerformanceCounter.EnableAudioDecodePerformance(ThreadHandle());
+ g_dvdPerformanceCounter.EnableAudioDecodePerformance(this);
#ifdef _WIN32
CoInitializeEx(NULL, COINIT_MULTITHREADED);
return false;
}
- if(g_guiSettings.GetBool("videoplayer.usedisplayasclock") && g_VideoReferenceClock.ThreadHandle() == NULL)
+ if(g_guiSettings.GetBool("videoplayer.usedisplayasclock") && !g_VideoReferenceClock.IsRunning())
{
g_VideoReferenceClock.Create();
//we have to wait for the clock to start otherwise alsa can cause trouble
m_iCurrentPts = DVD_NOPTS_VALUE;
m_FlipTimeStamp = m_pClock->GetAbsoluteClock();
- g_dvdPerformanceCounter.EnableVideoDecodePerformance(ThreadHandle());
+ g_dvdPerformanceCounter.EnableVideoDecodePerformance(this);
}
void CDVDPlayerVideo::Process()
// Supporting all open audio codec standards.
// First one being nullsoft's nsv audio decoder format
-PAPlayer::PAPlayer(IPlayerCallback& callback) : IPlayer(callback)
+PAPlayer::PAPlayer(IPlayerCallback& callback) : IPlayer(callback), CThread("PAPlayer")
{
m_bIsPlaying = false;
m_bPaused = false;
*m_currentFile = file;
- if (ThreadHandle() == NULL)
+ if (!IsRunning())
Create();
m_startEvent.Set();
#include "threads/SingleLock.h"
#include "utils/TimeUtils.h"
-CGUIDialogCache::CGUIDialogCache(DWORD dwDelay, const CStdString& strHeader, const CStdString& strMsg)
+CGUIDialogCache::CGUIDialogCache(DWORD dwDelay, const CStdString& strHeader, const CStdString& strMsg) : CThread("CGUIDialogCache")
{
m_pDlg = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
};
-CFileCache::CFileCache()
+CFileCache::CFileCache() : CThread("CFileCache")
{
m_bDeleteCache = true;
m_nSeekResult = 0;
m_cacheFull = false;
}
-CFileCache::CFileCache(CCacheStrategy *pCache, bool bDeleteCache)
+CFileCache::CFileCache(CCacheStrategy *pCache, bool bDeleteCache) : CThread("CFileCache")
{
m_pCache = pCache;
m_bDeleteCache = bDeleteCache;
static CCriticalSection g_section;
-CHTSPDirectorySession::CHTSPDirectorySession()
+CHTSPDirectorySession::CHTSPDirectorySession() : CThread("CHTSPDirectorySession")
{
}
m_dlgProgress->Progress();
}
- CThread thread(this);
+ CThread thread(this, "CLastFMDirectory");
m_strSource = url;
m_strDestination = "special://temp/lastfm.xml";
thread.Create();
return;
}
-CMythSession::CMythSession(const CURL& url)
+CMythSession::CMythSession(const CURL& url) : CThread("CMythSession")
{
m_control = NULL;
m_event = NULL;
if (!m_pipe)
return -1;
- return m_pipe->Read((char *)lpBuf,(int)uiBufSize,INFINITE);
+ return m_pipe->Read((char *)lpBuf,(int)uiBufSize);
}
int CPipeFile::Write(const void* lpBuf, int64_t uiBufSize)
if (!m_pipe)
return -1;
- return (int)(m_pipe->Write((const char *)lpBuf,(int)uiBufSize,INFINITE)); // its not the size. its bool. either all was written or not.
+ return (int)(m_pipe->Write((const char *)lpBuf,(int)uiBufSize)); // its not the size. its bool. either all was written or not.
}
void CPipeFile::SetEof()
for (size_t l=0; l<m_listeners.size(); l++)
m_listeners[l]->OnPipeOverFlow();
- bool bClear = m_writeEvent.WaitMSec(nWaitMillis);
+ bool bClear = nWaitMillis < 0 ? m_writeEvent.Wait() : m_writeEvent.WaitMSec(nWaitMillis);
lock.Enter();
if (bClear && (int)m_buffer.getMaxWriteSize() >= nSize)
{
bOk = true;
break;
}
-
- if ((unsigned int) nWaitMillis != INFINITE)
+
+ // FIXME: is this right? Shouldn't we see if the time limit has been reached?
+ if (nWaitMillis > 0)
break;
}
}
int RefCount();
bool IsEmpty();
- int Read(char *buf, int nMaxSize, int nWaitMillis);
- bool Write(const char *buf, int nSize, int nWaitMillis);
+
+ /**
+ * Read into the buffer from the Pipe the num of bytes asked for
+ * blocking forever (which happens to be 5 minutes in this case).
+ *
+ * In the case where nWaitMillis is provided block for that number
+ * of milliseconds instead.
+ */
+ int Read(char *buf, int nMaxSize, int nWaitMillis = -1);
+
+ /**
+ * Write into the Pipe from the buffer the num of bytes asked for
+ * blocking forever.
+ *
+ * In the case where nWaitMillis is provided block for that number
+ * of milliseconds instead.
+ */
+ bool Write(const char *buf, int nSize, int nWaitMillis = -1);
void Flush();
#define SEEKTIMOUT 30000
#ifdef HAS_FILESYSTEM_RAR
-CRarFileExtractThread::CRarFileExtractThread() : hRunning(true), hQuit(true)
+CRarFileExtractThread::CRarFileExtractThread() : CThread("CFileRarExtractThread"), hRunning(true), hQuit(true)
{
m_pArc = NULL;
m_pCmd = NULL;
CRarManager();
~CRarManager();
bool CacheRarredFile(CStdString& strPathInCache, const CStdString& strRarPath,
- const CStdString& strPathInRar, BYTE bOptions = EXFILE_AUTODELETE,
+ const CStdString& strPathInRar, uint8_t bOptions = EXFILE_AUTODELETE,
const CStdString& strDir =RAR_DEFAULT_CACHE, const int64_t iSize=-1);
bool GetPathInCache(CStdString& strPathInCache, const CStdString& strRarPath,
const CStdString& strPathInRar = "");
using namespace SDP;
-CSAPSessions::CSAPSessions()
+CSAPSessions::CSAPSessions() : CThread("CSAPSessions")
{
m_socket = INVALID_SOCKET;
}
CSingleLock lock(g_sapsessions.m_section);
- if(g_sapsessions.ThreadHandle() == NULL)
+ if(!g_sapsessions.IsRunning())
g_sapsessions.Create();
// check if we can find this session in our cache
m_globalEvent.Set();
}
-void XBPython::WaitForEvent(CEvent& hEvent, unsigned int timeout)
+void XBPython::WaitForEvent(CEvent& hEvent)
{
// wait for either this event our our global event
XbmcThreads::CEventGroup eventGroup(&hEvent, &m_globalEvent, NULL);
- eventGroup.wait(timeout);
+ eventGroup.wait();
m_globalEvent.Reset();
}
void Process();
void PulseGlobalEvent();
- void WaitForEvent(CEvent& hEvent, unsigned int timeout);
+ void WaitForEvent(CEvent& hEvent);
int ScriptsSize();
int GetPythonScriptId(int scriptPosition);
m_threadState = state;
}
-void CGUIPythonWindow::WaitForActionEvent(unsigned int timeout)
+void CGUIPythonWindow::WaitForActionEvent()
{
- g_pythonParser.WaitForEvent(m_actionEvent, timeout);
+ g_pythonParser.WaitForEvent(m_actionEvent);
m_actionEvent.Reset();
}
virtual bool OnAction(const CAction &action);
virtual bool OnBack(int actionID);
void SetCallbackWindow(void* state, void *object);
- void WaitForActionEvent(unsigned int timeout);
+ void WaitForActionEvent();
void PulseActionEvent();
void SetDestroyAfterDeinit(bool destroy = true);
protected:
UpdateButtons();
}
-void CGUIPythonWindowXML::WaitForActionEvent(unsigned int timeout)
+void CGUIPythonWindowXML::WaitForActionEvent()
{
- g_pythonParser.WaitForEvent(m_actionEvent, timeout);
+ g_pythonParser.WaitForEvent(m_actionEvent);
m_actionEvent.Reset();
}
virtual void AllocResources(bool forceLoad = false);
virtual void FreeResources(bool forceUnLoad = false);
void Process(unsigned int currentTime, CDirtyRegionList ®ions);
- void WaitForActionEvent(unsigned int timeout);
+ void WaitForActionEvent();
void PulseActionEvent();
void AddItem(CFileItemPtr fileItem,int itemPosition);
void RemoveItem(int itemPosition);
CPyThreadState pyState;
if (WindowXML_Check(self))
- ((CGUIPythonWindowXML*)self->pWindow)->WaitForActionEvent(INFINITE);
+ ((CGUIPythonWindowXML*)self->pWindow)->WaitForActionEvent();
else if (WindowXMLDialog_Check(self))
- ((CGUIPythonWindowXMLDialog*)self->pWindow)->WaitForActionEvent(INFINITE);
+ ((CGUIPythonWindowXMLDialog*)self->pWindow)->WaitForActionEvent();
else
- ((CGUIPythonWindow*)self->pWindow)->WaitForActionEvent(INFINITE);
+ ((CGUIPythonWindow*)self->pWindow)->WaitForActionEvent();
}
}
Py_INCREF(Py_None);
LinuxResourceCounter.cpp \
LinuxTimezone.cpp \
PosixMountProvider.cpp \
- XEventUtils.cpp \
XFileUtils.cpp \
XHandle.cpp \
XLCDproc.cpp \
XMemUtils.cpp \
- XSyncUtils.cpp \
XTimeUtils.cpp \
- XThreadUtils.cpp \
LIB=linux.a
#define EXCEPTION_EXECUTE_HANDLER ...
//NOTE: dont try to define __except because it breaks g++ (already uses it).
-typedef pthread_t ThreadIdentifier;
-
struct CXHandle; // forward declaration
typedef CXHandle* HANDLE;
#include "PlatformDefs.h"
#include "XHandlePublic.h"
#include "XFileUtils.h"
-#include "XSyncUtils.h"
-#include "XEventUtils.h"
#include "XTimeUtils.h"
-#include "XThreadUtils.h"
#include "XMemUtils.h"
#include "ConvUtils.h"
+++ /dev/null
-/*
- * Copyright (C) 2005-2008 Team XBMC
- * http://www.xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- */
-
-#include "system.h"
-#include "PlatformDefs.h"
-#include "XEventUtils.h"
-#include "XHandle.h"
-#include "utils/log.h"
-#include "threads/SingleLock.h"
-
-using namespace std;
-
-HANDLE WINAPI CreateEvent(void *pDummySec, bool bManualReset, bool bInitialState, char *szDummyName)
-{
- CXHandle *pHandle = new CXHandle(CXHandle::HND_EVENT);
- pHandle->m_bManualEvent = bManualReset;
- pHandle->m_hCond = new XbmcThreads::ConditionVariable();
- pHandle->m_hMutex = new CCriticalSection();
- pHandle->m_bEventSet = false;
-
- if (bInitialState)
- SetEvent(pHandle);
-
- return pHandle;
-}
-
-//
-// The state of a manual-reset event object remains signaled until it is set explicitly to the nonsignaled
-// state by the ResetEvent function. Any number of waiting threads, or threads that subsequently begin wait
-// operations for the specified event object by calling one of the wait functions, can be released while the
-// object's state is signaled.
-//
-// The state of an auto-reset event object remains signaled until a single waiting thread is released, at
-// which time the system automatically sets the state to nonsignaled. If no threads are waiting, the event
-// object's state remains signaled.
-//
-bool WINAPI SetEvent(HANDLE hEvent)
-{
- if (hEvent == NULL || hEvent->m_hCond == NULL || hEvent->m_hMutex == NULL)
- return false;
-
- CSingleLock lock(*(hEvent->m_hMutex));
- hEvent->m_bEventSet = true;
-
- // we must guarantee that these handle's won't be deleted, until we are done
- list<CXHandle*> events = hEvent->m_hParents;
- for(list<CXHandle*>::iterator it = events.begin();it != events.end();it++)
- DuplicateHandle(GetCurrentProcess(), *it, GetCurrentProcess(), NULL, 0, FALSE, DUPLICATE_SAME_ACCESS);
-
- lock.Leave();
-
- for(list<CXHandle*>::iterator it = events.begin();it != events.end();it++)
- {
- SetEvent(*it);
- CloseHandle(*it);
- }
-
- DuplicateHandle(GetCurrentProcess(), hEvent, GetCurrentProcess(), NULL, 0, FALSE, DUPLICATE_SAME_ACCESS);
-
- if (hEvent->m_bManualEvent == true)
- hEvent->m_hCond->notifyAll();
- else
- hEvent->m_hCond->notify();
-
- CloseHandle(hEvent);
-
- return true;
-}
-
-bool WINAPI ResetEvent(HANDLE hEvent)
-{
- if (hEvent == NULL || hEvent->m_hCond == NULL || hEvent->m_hMutex == NULL)
- return false;
-
- CSingleLock lock(*(hEvent->m_hMutex));
- hEvent->m_bEventSet = false;
-
- return true;
-}
-
-bool WINAPI PulseEvent(HANDLE hEvent)
-{
- if (hEvent == NULL || hEvent->m_hCond == NULL || hEvent->m_hMutex == NULL)
- return false;
-
- CSingleLock lock(*(hEvent->m_hMutex));
- // we must guarantee that these handle's won't be deleted, until we are done
- list<CXHandle*> events = hEvent->m_hParents;
- for(list<CXHandle*>::iterator it = events.begin();it != events.end();it++)
- DuplicateHandle(GetCurrentProcess(), *it, GetCurrentProcess(), NULL, 0, FALSE, DUPLICATE_SAME_ACCESS);
-
- if(events.size())
- {
- CLog::Log(LOGWARNING,"PulseEvent - ineffecient multiwait detected");
- hEvent->m_bEventSet = true;
- }
-
- lock.Leave();
-
- for(list<CXHandle*>::iterator it = events.begin();it != events.end();it++)
- {
- SetEvent(*it);
- CloseHandle(*it);
-
- if (hEvent->m_bManualEvent == false)
- break;
- }
-
- // for multiwaits, we must yield some time to get the multiwaits to notice it was signaled
- if(events.size())
- Sleep(10);
-
- // we should always unset the event on pulse
- {
- CSingleLock lock2(*(hEvent->m_hMutex));
- hEvent->m_bEventSet = false;
- }
-
- if (hEvent->m_bManualEvent == true)
- hEvent->m_hCond->notifyAll();
- else
- hEvent->m_hCond->notify();
-
- return true;
-}
-
+++ /dev/null
-#ifndef __X_EVENT_UTIL_H__
-#define __X_EVENT_UTIL_H__
-
-/*
- * Copyright (C) 2005-2008 Team XBMC
- * http://www.xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- */
-
-#include "XHandlePublic.h"
-
-#ifdef _LINUX
-
-HANDLE WINAPI CreateEvent(void *pDummySec, bool bManualReset, bool bInitialState, char *szDummyName);
-bool WINAPI SetEvent(HANDLE hEvent);
-bool WINAPI ResetEvent(HANDLE hEvent);
-bool WINAPI PulseEvent(HANDLE hEvent);
-
-#endif
-
-
-#endif
-
*/
#include "XHandle.h"
-#include "XThreadUtils.h"
#include "utils/log.h"
#include "threads/SingleLock.h"
int CXHandle::m_objectTracker[10] = {0};
+HANDLE WINAPI GetCurrentProcess(void) {
+ return (HANDLE)-1; // -1 a special value - pseudo handle
+}
+
CXHandle::CXHandle()
{
Init();
Init();
- if (m_threadValid)
- {
- CLog::Log(LOGERROR, "%s - thread handle copied instead of passed!", __FUNCTION__);
- }
-
if (src.m_hMutex)
m_hMutex = new CCriticalSection();
CLog::Log(LOGERROR,"%s, destroying handle with ref count %d", __FUNCTION__, m_nRefCount);
assert(false);
}
-
+
if (m_hMutex) {
delete m_hMutex;
}
delete m_hCond;
}
- if (m_threadValid) {
- pthread_join(m_hThread, NULL);
- }
-
if ( fd != 0 ) {
close(fd);
}
{
fd=0;
m_hMutex=NULL;
- m_threadValid=false;
m_hCond=NULL;
m_type = HND_NULL;
RecursionCount=0;
- OwningThread=0;
m_bManualEvent=FALSE;
m_bEventSet=FALSE;
m_nFindFileIterator=0 ;
#ifndef _WIN32
#include <list>
-#include <pthread.h>
#include "PlatformDefs.h"
#include "XHandlePublic.h"
struct CXHandle {
public:
- typedef enum { HND_NULL = 0, HND_FILE, HND_EVENT, HND_MUTEX, HND_THREAD, HND_FIND_FILE } HandleType;
+ typedef enum { HND_NULL = 0, HND_FILE, HND_EVENT, HND_MUTEX, HND_FIND_FILE } HandleType;
CXHandle();
CXHandle(HandleType nType);
inline HandleType GetType() { return m_type; }
void ChangeType(HandleType newType);
- ThreadIdentifier m_hThread;
- bool m_threadValid;
XbmcThreads::ConditionVariable *m_hCond;
std::list<CXHandle*> m_hParents;
// simulate mutex and critical section
CCriticalSection *m_hMutex;
int RecursionCount; // for mutex - for compatibility with WIN32 critical section
- pthread_t OwningThread;
int fd;
bool m_bManualEvent;
time_t m_tmCreation;
#include "XMemUtils.h"
+#ifdef __APPLE__
+#include <mach/mach.h>
+#endif
+
#undef ALIGN
#define ALIGN(value, alignment) (((value)+(alignment-1))&~(alignment-1))
free(pFull);
}
+#ifndef _WIN32
+
+#if defined(_LINUX) && !defined(__APPLE__) && !defined(__FreeBSD__)
+static FILE* procMeminfoFP = NULL;
+#endif
+
+void GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)
+{
+ if (!lpBuffer)
+ return;
+
+ memset(lpBuffer, 0, sizeof(MEMORYSTATUSEX));
+ lpBuffer->dwLength = sizeof(MEMORYSTATUSEX);
+
+#ifdef __APPLE__
+ uint64_t physmem;
+ size_t len = sizeof physmem;
+ int mib[2] = { CTL_HW, HW_MEMSIZE };
+ size_t miblen = sizeof(mib) / sizeof(mib[0]);
+
+ // Total physical memory.
+ if (sysctl(mib, miblen, &physmem, &len, NULL, 0) == 0 && len == sizeof (physmem))
+ lpBuffer->ullTotalPhys = physmem;
+
+ // Virtual memory.
+ mib[0] = CTL_VM; mib[1] = VM_SWAPUSAGE;
+ struct xsw_usage swap;
+ len = sizeof(struct xsw_usage);
+ if (sysctl(mib, miblen, &swap, &len, NULL, 0) == 0)
+ {
+ lpBuffer->ullAvailPageFile = swap.xsu_avail;
+ lpBuffer->ullTotalVirtual = lpBuffer->ullTotalPhys + swap.xsu_total;
+ }
+
+ // In use.
+ mach_port_t stat_port = mach_host_self();
+ vm_statistics_data_t vm_stat;
+ mach_msg_type_number_t count = sizeof(vm_stat) / sizeof(natural_t);
+ if (host_statistics(stat_port, HOST_VM_INFO, (host_info_t)&vm_stat, &count) == 0)
+ {
+ // Find page size.
+ int pageSize;
+ mib[0] = CTL_HW; mib[1] = HW_PAGESIZE;
+ len = sizeof(int);
+ if (sysctl(mib, miblen, &pageSize, &len, NULL, 0) == 0)
+ {
+ uint64_t used = (vm_stat.active_count + vm_stat.inactive_count + vm_stat.wire_count) * pageSize;
+
+ lpBuffer->ullAvailPhys = lpBuffer->ullTotalPhys - used;
+ lpBuffer->ullAvailVirtual = lpBuffer->ullAvailPhys; // FIXME.
+ }
+ }
+#elif defined(__FreeBSD__)
+ /* sysctl hw.physmem */
+ size_t physmem = 0, mem_free = 0, pagesize = 0, swap_free = 0;
+ size_t mem_avail = 0, mem_inactive = 0, mem_cache = 0, len = 0;
+
+ /* physmem */
+ len = sizeof(physmem);
+ if (sysctlbyname("hw.physmem", &physmem, &len, NULL, 0) == 0) {
+ lpBuffer->ullTotalPhys = physmem;
+ lpBuffer->ullTotalVirtual = physmem;
+ }
+ /* pagesize */
+ len = sizeof(pagesize);
+ if (sysctlbyname("hw.pagesize", &pagesize, &len, NULL, 0) != 0)
+ pagesize = 4096;
+ /* mem_inactive */
+ len = sizeof(mem_inactive);
+ if (sysctlbyname("vm.stats.vm.v_inactive_count", &mem_inactive, &len, NULL, 0) == 0)
+ mem_inactive *= pagesize;
+ /* mem_cache */
+ len = sizeof(mem_cache);
+ if (sysctlbyname("vm.stats.vm.v_cache_count", &mem_cache, &len, NULL, 0) == 0)
+ mem_cache *= pagesize;
+ /* mem_free */
+ len = sizeof(mem_free);
+ if (sysctlbyname("vm.stats.vm.v_free_count", &mem_free, &len, NULL, 0) == 0)
+ mem_free *= pagesize;
+
+ /* mem_avail = mem_inactive + mem_cache + mem_free */
+ lpBuffer->ullAvailPhys = mem_inactive + mem_cache + mem_free;
+ lpBuffer->ullAvailVirtual = mem_inactive + mem_cache + mem_free;
+
+ if (sysctlbyname("vm.stats.vm.v_swappgsout", &swap_free, &len, NULL, 0) == 0)
+ lpBuffer->ullAvailPageFile = swap_free * pagesize;
+#else
+ struct sysinfo info;
+ char name[32];
+ unsigned val;
+ if (!procMeminfoFP && (procMeminfoFP = fopen("/proc/meminfo", "r")) == NULL)
+ sysinfo(&info);
+ else
+ {
+ memset(&info, 0, sizeof(struct sysinfo));
+ info.mem_unit = 4096;
+ while (fscanf(procMeminfoFP, "%31s %u%*[^\n]\n", name, &val) != EOF)
+ {
+ if (strncmp("MemTotal:", name, 9) == 0)
+ info.totalram = val/4;
+ else if (strncmp("MemFree:", name, 8) == 0)
+ info.freeram = val/4;
+ else if (strncmp("Buffers:", name, 8) == 0)
+ info.bufferram += val/4;
+ else if (strncmp("Cached:", name, 7) == 0)
+ info.bufferram += val/4;
+ else if (strncmp("SwapTotal:", name, 10) == 0)
+ info.totalswap = val/4;
+ else if (strncmp("SwapFree:", name, 9) == 0)
+ info.freeswap = val/4;
+ else if (strncmp("HighTotal:", name, 10) == 0)
+ info.totalhigh = val/4;
+ else if (strncmp("HighFree:", name, 9) == 0)
+ info.freehigh = val/4;
+ }
+ rewind(procMeminfoFP);
+ fflush(procMeminfoFP);
+ }
+ lpBuffer->dwLength = sizeof(MEMORYSTATUSEX);
+ lpBuffer->ullAvailPageFile = (info.freeswap * info.mem_unit);
+ lpBuffer->ullAvailPhys = ((info.freeram + info.bufferram) * info.mem_unit);
+ lpBuffer->ullAvailVirtual = ((info.freeram + info.bufferram) * info.mem_unit);
+ lpBuffer->ullTotalPhys = (info.totalram * info.mem_unit);
+ lpBuffer->ullTotalVirtual = (info.totalram * info.mem_unit);
+#endif
+}
+
+#endif
*
*/
+#include "linux/PlatformDefs.h"
+
// aligned memory allocation and free. memory returned will be aligned to "alignTo" bytes.
// this is a linux (actually platfom free) implementation of the win32 CRT methods _aligned_malloc and _aligned_free.
void *_aligned_malloc(size_t s, size_t alignTo);
void _aligned_free(void *p) ;
+void GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer);
+
#endif
+++ /dev/null
-#ifndef __X_SYNC_UTILS_
-#define __X_SYNC_UTILS_
-
-/*
- * Copyright (C) 2005-2008 Team XBMC
- * http://www.xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- */
-
-#include "PlatformDefs.h"
-#include "XHandlePublic.h"
-
-#ifdef _LINUX
-
-#define STATUS_WAIT_0 ((DWORD )0x00000000L)
-#define WAIT_FAILED ((DWORD)0xFFFFFFFF)
-#define WAIT_OBJECT_0 ((STATUS_WAIT_0 ) + 0 )
-#define WAIT_TIMEOUT 258L
-#define INFINITE 0xFFFFFFFF
-#define STATUS_ABANDONED_WAIT_0 0x00000080
-#define WAIT_ABANDONED ((STATUS_ABANDONED_WAIT_0 ) + 0 )
-#define WAIT_ABANDONED_0 ((STATUS_ABANDONED_WAIT_0 ) + 0 )
-
-void GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer);
-
-#endif
-
-#endif
-
+++ /dev/null
-/*
- * Copyright (C) 2005-2009 Team XBMC
- * http://www.xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- */
-
-#include "PlatformDefs.h"
-#include "XHandle.h"
-#include "XThreadUtils.h"
-#include "XTimeUtils.h"
-#include "XEventUtils.h"
-#include "system.h"
-#include "utils/log.h"
-
-#ifdef _LINUX
-#include <signal.h>
-#include <pthread.h>
-#include <limits.h>
-
-HANDLE WINAPI CreateThread(
- LPSECURITY_ATTRIBUTES lpThreadAttributes,
- SIZE_T dwStackSize,
- LPTHREAD_START_ROUTINE lpStartAddress,
- LPVOID lpParameter,
- DWORD dwCreationFlags,
- LPDWORD lpThreadId
- ) {
-
- // a thread handle would actually contain an event
- // the event would mark if the thread is running or not. it will be used in the Wait functions.
- HANDLE h = CreateEvent(NULL, TRUE, FALSE, NULL);
- h->ChangeType(CXHandle::HND_THREAD);
-#ifdef __APPLE__
- h->m_machThreadPort = MACH_PORT_NULL;
-#endif
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- if (dwStackSize > PTHREAD_STACK_MIN)
- pthread_attr_setstacksize(&attr, dwStackSize);
- if (pthread_create(&(h->m_hThread), &attr, (void*(*)(void*))lpStartAddress, lpParameter) == 0)
- h->m_threadValid = true;
- else
- {
- CloseHandle(h);
- h = NULL;
- }
- pthread_attr_destroy(&attr);
-
- if (h && lpThreadId)
- // WARNING: This can truncate thread IDs on x86_64.
- *lpThreadId = (DWORD)h->m_hThread;
- return h;
-}
-
-
-#if 0 // Deprecated, use CThread::GetCurrentThreadId() instead
-DWORD WINAPI GetCurrentThreadId(void) {
- // WARNING: This can truncate thread IDs on x86_64.
- return (DWORD)pthread_self();
-}
-#endif
-
-HANDLE WINAPI GetCurrentThread(void) {
- return (HANDLE)-1; // -1 a special value - pseudo handle
-}
-
-HANDLE WINAPI GetCurrentProcess(void) {
- return (HANDLE)-1; // -1 a special value - pseudo handle
-}
-
-HANDLE _beginthreadex(
- void *security,
- unsigned stack_size,
- int ( *start_address )( void * ),
- void *arglist,
- unsigned initflag,
- unsigned *thrdaddr
-) {
-
- HANDLE h = CreateThread(NULL, stack_size, start_address, arglist, initflag, (LPDWORD)thrdaddr);
- return h;
-
-}
-
-uintptr_t _beginthread(
- void( *start_address )( void * ),
- unsigned stack_size,
- void *arglist
-) {
- HANDLE h = CreateThread(NULL, stack_size, (LPTHREAD_START_ROUTINE)start_address, arglist, 0, NULL);
- return (uintptr_t)h;
-}
-
-BOOL WINAPI GetThreadTimes (
- HANDLE hThread,
- LPFILETIME lpCreationTime,
- LPFILETIME lpExitTime,
- LPFILETIME lpKernelTime,
- LPFILETIME lpUserTime
-) {
- if (!hThread)
- return false;
- if (!hThread->m_threadValid)
- return false;
-
- if (hThread == (HANDLE)-1) {
- if (lpCreationTime)
- TimeTToFileTime(0,lpCreationTime);
- if (lpExitTime)
- TimeTToFileTime(time(NULL),lpExitTime);
- if (lpKernelTime)
- TimeTToFileTime(0,lpKernelTime);
- if (lpUserTime)
- TimeTToFileTime(0,lpUserTime);
-
- return true;
- }
-
- if (lpCreationTime)
- TimeTToFileTime(hThread->m_tmCreation,lpCreationTime);
- if (lpExitTime)
- TimeTToFileTime(time(NULL),lpExitTime);
- if (lpKernelTime)
- TimeTToFileTime(0,lpKernelTime);
-
-#ifdef __APPLE__
- thread_info_data_t threadInfo;
- mach_msg_type_number_t threadInfoCount = THREAD_INFO_MAX;
-
- if (hThread->m_machThreadPort == MACH_PORT_NULL)
- hThread->m_machThreadPort = pthread_mach_thread_np(hThread->m_hThread);
-
- kern_return_t ret = thread_info(hThread->m_machThreadPort, THREAD_BASIC_INFO, (thread_info_t)threadInfo, &threadInfoCount);
- if (ret == KERN_SUCCESS)
- {
- thread_basic_info_t threadBasicInfo = (thread_basic_info_t)threadInfo;
-
- if (lpUserTime)
- {
- // User time.
- unsigned long long time = ((__int64)threadBasicInfo->user_time.seconds * 10000000L) + threadBasicInfo->user_time.microseconds*10L;
- lpUserTime->dwLowDateTime = (time & 0xFFFFFFFF);
- lpUserTime->dwHighDateTime = (time >> 32);
- }
-
- if (lpKernelTime)
- {
- // System time.
- unsigned long long time = ((__int64)threadBasicInfo->system_time.seconds * 10000000L) + threadBasicInfo->system_time.microseconds*10L;
- lpKernelTime->dwLowDateTime = (time & 0xFFFFFFFF);
- lpKernelTime->dwHighDateTime = (time >> 32);
- }
- }
- else
- {
- if (lpUserTime)
- lpUserTime->dwLowDateTime = lpUserTime->dwHighDateTime = 0;
-
- if (lpKernelTime)
- lpKernelTime->dwLowDateTime = lpKernelTime->dwHighDateTime = 0;
- }
-#elif _POSIX_THREAD_CPUTIME != -1
- if(lpUserTime)
- {
- lpUserTime->dwLowDateTime = 0;
- lpUserTime->dwHighDateTime = 0;
- clockid_t clock;
- if (pthread_getcpuclockid(hThread->m_hThread, &clock) == 0)
- {
- struct timespec tp = {};
- clock_gettime(clock, &tp);
- unsigned long long time = (unsigned long long)tp.tv_sec * 10000000 + (unsigned long long)tp.tv_nsec/100;
- lpUserTime->dwLowDateTime = (time & 0xFFFFFFFF);
- lpUserTime->dwHighDateTime = (time >> 32);
- }
- }
-#else
- if (lpUserTime)
- TimeTToFileTime(0,lpUserTime);
-#endif
- return true;
-}
-
-BOOL WINAPI SetThreadPriority(HANDLE hThread, int nPriority)
-{
- return true;
-}
-
-int GetThreadPriority(HANDLE hThread)
-{
- return 0;
-}
-
-#endif
-
+++ /dev/null
-#ifndef __XTHREAD_UTILS__H__
-#define __XTHREAD_UTILS__H__
-
-/*
- * Copyright (C) 2005-2009 Team XBMC
- * http://www.xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- */
-
-#include <stdlib.h>
-
-HANDLE WINAPI CreateThread(
- LPSECURITY_ATTRIBUTES lpThreadAttributes,
- SIZE_T dwStackSize,
- LPTHREAD_START_ROUTINE lpStartAddress,
- LPVOID lpParameter,
- DWORD dwCreationFlags,
- LPDWORD lpThreadId
- );
-
-HANDLE _beginthreadex(
- void *security,
- unsigned stack_size,
- int ( *start_address )( void * ),
- void *arglist,
- unsigned initflag,
- unsigned *thrdaddr
-);
-
-uintptr_t _beginthread(
- void( *start_address )( void * ),
- unsigned stack_size,
- void *arglist
-);
-
-#if 0 // Deprecated, use CThread::GetCurrentThreadId() instead
-DWORD WINAPI GetCurrentThreadId(void);
-#endif
-
-HANDLE WINAPI GetCurrentThread(void);
-HANDLE WINAPI GetCurrentProcess(void);
-
-BOOL WINAPI GetThreadTimes (
- HANDLE hThread,
- LPFILETIME lpCreationTime,
- LPFILETIME lpExitTime,
- LPFILETIME lpKernelTime,
- LPFILETIME lpUserTime
-);
-
-int GetThreadPriority(
- HANDLE hThread
-);
-
-BOOL WINAPI SetThreadPriority(
- HANDLE hThread,
- int nPriority
-);
-
-// helper class for TLS handling
-class TLS
-{
-public:
- TLS()
- {
- pthread_key_create(&m_key, free);
- }
-
- ~TLS()
- {
- pthread_key_delete(m_key);
- }
-
- void *Get()
- {
- if (pthread_getspecific(m_key) == NULL)
- pthread_setspecific(m_key, calloc(8, 1));
-
- return pthread_getspecific(m_key);
- }
-
- pthread_key_t m_key;
-};
-
-#endif
CLastFmManager* CLastFmManager::m_pInstance=NULL;
-CLastFmManager::CLastFmManager()
+CLastFmManager::CLastFmManager() : CThread("CLastFmManager")
{
m_RadioTrackQueue = new CPlayList;
}
if (iNrCachedTracks == 0)
{
//get more tracks
- if (ThreadHandle() != NULL)
+ if (IsRunning())
{
m_hWorkerEvent.Set();
}
{
m_RadioSession = "";
}
- if (m_ThreadHandle)
+ if (IsRunning())
{
m_bStop = true;
m_hWorkerEvent.Set();
using namespace XFILE;
using namespace MUSIC_GRABBER;
-CMusicInfoScanner::CMusicInfoScanner()
+CMusicInfoScanner::CMusicInfoScanner() : CThread("CMusicInfoScanner")
{
m_bRunning = false;
m_pObserver = NULL;
// Create the thread to count all files to be scanned
SetPriority( GetMinPriority() );
- CThread fileCountReader(this);
+ CThread fileCountReader(this, "CMusicInfoScanner");
if (m_pObserver)
fileCountReader.Create();
using namespace ADDON;
using namespace std;
-CMusicInfoScraper::CMusicInfoScraper(const ADDON::ScraperPtr &scraper)
+CMusicInfoScraper::CMusicInfoScraper(const ADDON::ScraperPtr &scraper) : CThread("CMusicInfoScraper")
{
m_bSucceeded=false;
m_bCanceled=false;
}
}
-CAirPlayServer::CAirPlayServer(int port, bool nonlocal)
+CAirPlayServer::CAirPlayServer(int port, bool nonlocal) : CThread("AirPlayServer")
{
m_port = port;
m_nonlocal = nonlocal;
#include <vector>
#include "utils/StdString.h"
+#include "system.h"
enum EncMode { ENC_NONE = 0, ENC_WEP = 1, ENC_WPA = 2, ENC_WPA2 = 3 };
enum NetworkAssignment { NETWORK_DASH = 0, NETWORK_DHCP = 1, NETWORK_STATIC = 2, NETWORK_DISABLED = 3 };
}
}
-CTCPServer::CTCPServer(int port, bool nonlocal)
+CTCPServer::CTCPServer(int port, bool nonlocal) : CThread("CTCPServer")
{
m_port = port;
m_nonlocal = nonlocal;
#define UDPCLIENT_DEBUG_LEVEL LOGDEBUG
-CUdpClient::CUdpClient(void) : CThread()
+CUdpClient::CUdpClient(void) : CThread("CUdpClient")
{}
CUdpClient::~CUdpClient(void)
#include "threads/CriticalSection.h"
#include <sys/socket.h>
#include <netinet/in.h>
+#include "system.h"
class CUdpClient : CThread
{
#define SCROBBLER_ACTION_NOWPLAYING 2
CScrobbler::CScrobbler(const CStdString &strHandshakeURL, const CStdString &strLogPrefix)
- : CThread()
+ : CThread("CScrobbler")
{
m_bBanned = false;
m_bBadAuth = false;
ResetState();
LoadCredentials();
LoadJournal();
- if (!ThreadHandle())
+ if (!IsRunning())
Create();
}
return bHasButton;
CLog::Log(LOGDEBUG, "%s - received key %2x", __FUNCTION__, key.keycode);
- WORD iButton = 0;
+ int iButton = 0;
bHasButton = true;
switch (key.keycode)
return m_bHasButton;
}
-WORD CPeripheralCecAdapter::GetButton(void)
+int CPeripheralCecAdapter::GetButton(void)
{
CSingleLock lock(m_critSection);
if (!m_bHasButton)
bool IsMuted(void) { return false; }
void ScheduleMute(void) {}
- WORD GetButton(void) { return 0; }
+ int GetButton(void) { return 0; }
unsigned int GetHoldTime(void) { return 0; }
void ResetButton(void) {}
};
typedef struct
{
- WORD iButton;
+ int iButton;
unsigned int iDuration;
} CecButtonPress;
virtual void OnSettingChanged(const CStdString &strChangedSetting);
- virtual WORD GetButton(void);
+ virtual int GetButton(void);
virtual unsigned int GetHoldTime(void);
virtual void ResetButton(void);
virtual CStdString GetComPort(void);
static float zoomamount[10] = { 1.0f, 1.2f, 1.5f, 2.0f, 2.8f, 4.0f, 6.0f, 9.0f, 13.5f, 20.0f };
-CBackgroundPicLoader::CBackgroundPicLoader()
+CBackgroundPicLoader::CBackgroundPicLoader() : CThread("CBackgroundPicLoader")
{
m_pCallback = NULL;
m_isLoading = false;
//CVideoReferenceClock polls GetRasterStatus too,
//polling it from two threads at the same time is bad
- if (g_advancedSettings.m_sleepBeforeFlip > 0 && g_VideoReferenceClock.ThreadHandle() == NULL)
+ if (g_advancedSettings.m_sleepBeforeFlip > 0 && !g_VideoReferenceClock.IsRunning())
{
//save current thread priority and set thread priority to THREAD_PRIORITY_TIME_CRITICAL
int priority = GetThreadPriority(GetCurrentThread());
#include "threads/SystemClock.h"
#include "Thread.h"
-#ifndef _LINUX
-#include <process.h>
-#include "utils/win32exception.h"
-#ifndef _MT
-#pragma message( "Please compile using multithreaded run-time libraries" )
-#endif
-typedef unsigned (WINAPI *PBEGINTHREADEX_THREADFUNC)(LPVOID lpThreadParameter);
-#else
-#include "PlatformInclude.h"
-#include "XHandle.h"
-#include <signal.h>
-typedef int (*PBEGINTHREADEX_THREADFUNC)(LPVOID lpThreadParameter);
-#endif
-
-#if defined(__GNUC__) && !defined(__clang__)
-#include <cxxabi.h>
-using namespace __cxxabiv1;
-#endif
-
#include "utils/log.h"
#include "utils/TimeUtils.h"
#include "threads/ThreadLocal.h"
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+
static XbmcThreads::ThreadLocal<CThread> currentThread;
+#include "threads/platform/ThreadImpl.cpp"
+
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
-CThread::CThread(const char* ThreadName) : m_StopEvent(true,true)
+CThread::CThread(const char* ThreadName)
+: m_StopEvent(true,true), m_TermEvent(true), m_StartEvent(true)
{
m_bStop = false;
m_bAutoDelete = false;
- m_ThreadHandle = NULL;
m_ThreadId = 0;
m_iLastTime = 0;
m_iLastUsage = 0;
m_ThreadName = ThreadName;
}
-CThread::CThread(IRunnable* pRunnable, const char* ThreadName) : m_StopEvent(true,true)
+CThread::CThread(IRunnable* pRunnable, const char* ThreadName)
+: m_StopEvent(true,true), m_TermEvent(true), m_StartEvent(true)
{
m_bStop = false;
m_bAutoDelete = false;
- m_ThreadHandle = NULL;
m_ThreadId = 0;
m_iLastTime = 0;
m_iLastUsage = 0;
CThread::~CThread()
{
- if (m_ThreadHandle != NULL)
- {
- CloseHandle(m_ThreadHandle);
- }
- m_ThreadHandle = NULL;
-
+ StopThread();
}
-#ifndef _WIN32
-void CThread::term_handler (int signum)
+bool CThread::IsRunning()
{
- CLog::Log(LOGERROR,"thread 0x%lx (%lu) got signal %d. calling OnException and terminating thread abnormally.", (long unsigned int)pthread_self(), (long unsigned int)pthread_self(), signum);
-
- CThread* curThread = currentThread.get();
- if (curThread)
- {
- curThread->m_bStop = TRUE;
- curThread->m_StopEvent.Set();
-
- curThread->OnException();
- if( curThread->IsAutoDelete() )
- delete curThread;
- }
-
- pthread_exit(NULL);
+ return m_ThreadId ? true : false;
}
-int CThread::staticThread(void* data)
-#else
-DWORD WINAPI CThread::staticThread(LPVOID* data)
-#endif
+THREADFUNC CThread::staticThread(void* data)
{
CThread* pThread = (CThread*)(data);
+ std::string name;
+ ThreadIdentifier id;
+ bool autodelete;
+
if (!pThread) {
CLog::Log(LOGERROR,"%s, sanity failed. thread is NULL.",__FUNCTION__);
return 1;
}
- if (pThread->m_ThreadName.empty())
- pThread->m_ThreadName = pThread->GetTypeName();
- pThread->SetDebugCallStackName(pThread->m_ThreadName.c_str());
+ name = pThread->m_ThreadName;
+ id = pThread->m_ThreadId;
+ autodelete = pThread->m_bAutoDelete;
- CLog::Log(LOGDEBUG,"Thread %s start, auto delete: %d", pThread->m_ThreadName.c_str(), pThread->IsAutoDelete());
+ pThread->SetThreadInfo();
+
+ CLog::Log(LOGNOTICE,"Thread %s start, auto delete: %s", name.c_str(), (autodelete ? "true" : "false"));
currentThread.set(pThread);
-#ifndef _LINUX
- /* install win32 exception translator */
- win32_exception::install_handler();
-#else
- struct sigaction action;
- action.sa_handler = term_handler;
- sigemptyset (&action.sa_mask);
- action.sa_flags = 0;
- //sigaction (SIGABRT, &action, NULL);
- //sigaction (SIGSEGV, &action, NULL);
-#endif
-
-
- try
- {
- pThread->OnStartup();
- }
-#ifndef _LINUX
- catch (const access_violation &e)
- {
- e.writelog(__FUNCTION__);
- if( pThread->IsAutoDelete() )
- {
- delete pThread;
- _endthreadex(123);
- return 0;
- }
- }
- catch (const win32_exception &e)
- {
- e.writelog(__FUNCTION__);
- if( pThread->IsAutoDelete() )
- {
- delete pThread;
- _endthreadex(123);
- return 0;
- }
- }
-#endif
- catch(...)
- {
- CLog::Log(LOGERROR, "%s - thread %s, Unhandled exception caught in thread startup, aborting. auto delete: %d", __FUNCTION__, pThread->m_ThreadName.c_str(), pThread->IsAutoDelete());
- if( pThread->IsAutoDelete() )
- {
- delete pThread;
-#ifndef _LINUX
- _endthreadex(123);
-#endif
- return 0;
- }
- }
+ pThread->m_StartEvent.Set();
- try
- {
- pThread->Process();
- }
-#ifndef _LINUX
- catch (const access_violation &e)
- {
- e.writelog(__FUNCTION__);
- }
- catch (const win32_exception &e)
- {
- e.writelog(__FUNCTION__);
- }
-#endif
- catch(...)
- {
- CLog::Log(LOGERROR, "%s - thread %s, Unhandled exception caught in thread process, attemping cleanup in OnExit", __FUNCTION__, pThread->m_ThreadName.c_str());
- }
+ pThread->OnStartup();
+ pThread->Process();
+ pThread->OnExit();
- try
- {
- pThread->OnExit();
- }
-#ifndef _LINUX
- catch (const access_violation &e)
- {
- e.writelog(__FUNCTION__);
- }
- catch (const win32_exception &e)
- {
- e.writelog(__FUNCTION__);
- }
-#endif
- catch(...)
- {
- CLog::Log(LOGERROR, "%s - thread %s, Unhandled exception caught in thread exit", __FUNCTION__, pThread->m_ThreadName.c_str());
- }
+ // lock during termination
+ CSingleLock lock(pThread->m_CriticalSection);
- if ( pThread->IsAutoDelete() )
+ pThread->m_ThreadId = 0;
+ pThread->m_TermEvent.Set();
+ pThread->TermHandler();
+
+ lock.Leave();
+
+ if (autodelete)
{
- CLog::Log(LOGDEBUG,"Thread %s %"PRIu64" terminating (autodelete)", pThread->m_ThreadName.c_str(), (uint64_t)CThread::GetCurrentThreadId());
+ CLog::Log(LOGDEBUG,"Thread %s %"PRIu64" terminating (autodelete)", name.c_str(), (uint64_t)id);
delete pThread;
pThread = NULL;
}
else
- CLog::Log(LOGDEBUG,"Thread %s %"PRIu64" terminating", pThread->m_ThreadName.c_str(), (uint64_t)CThread::GetCurrentThreadId());
+ CLog::Log(LOGDEBUG,"Thread %s %"PRIu64" terminating", name.c_str(), (uint64_t)id);
-// DXMERGE - this looks like it might have used to have been useful for something...
-// g_graphicsContext.DeleteThreadContext();
-
-#ifndef _LINUX
- _endthreadex(123);
-#endif
return 0;
}
-void CThread::Create(bool bAutoDelete, unsigned stacksize)
-{
- if (m_ThreadHandle != NULL)
- {
- throw 1; //ERROR should not b possible!!!
- }
- m_iLastTime = XbmcThreads::SystemClockMillis() * 10000;
- m_iLastUsage = 0;
- m_fLastUsage = 0.0f;
- m_bAutoDelete = bAutoDelete;
- m_bStop = false;
- m_StopEvent.Reset();
-
- m_ThreadHandle = (HANDLE)_beginthreadex(NULL, stacksize, (PBEGINTHREADEX_THREADFUNC)staticThread, (void*)this, 0, &m_ThreadId);
-
-#ifdef _LINUX
- if (m_ThreadHandle && m_ThreadHandle->m_threadValid && m_bAutoDelete)
- // FIXME: WinAPI can truncate 64bit pthread ids
- pthread_detach(m_ThreadHandle->m_hThread);
-#endif
-}
-
bool CThread::IsAutoDelete() const
{
return m_bAutoDelete;
{
m_bStop = true;
m_StopEvent.Set();
- if (m_ThreadHandle && bWait)
+ if (m_ThreadId && bWait)
{
- WaitForThreadExit(INFINITE);
- CloseHandle(m_ThreadHandle);
- m_ThreadHandle = NULL;
+ WaitForThreadExit(0xFFFFFFFF);
}
}
ThreadIdentifier CThread::ThreadId() const
{
-#ifdef _LINUX
- if (m_ThreadHandle && m_ThreadHandle->m_threadValid)
- return m_ThreadHandle->m_hThread;
- else
- return 0;
-#else
return m_ThreadId;
-#endif
-}
-
-
-CThread::operator HANDLE()
-{
- return m_ThreadHandle;
-}
-
-CThread::operator HANDLE() const
-{
- return m_ThreadHandle;
-}
-
-bool CThread::SetPriority(const int iPriority)
-// Set thread priority
-// Return true for success
-{
- bool rtn = false;
-
- if (m_ThreadHandle)
- {
- rtn = SetThreadPriority( m_ThreadHandle, iPriority ) == TRUE;
- }
-
- return(rtn);
-}
-
-void CThread::SetPrioritySched_RR(void)
-{
-#ifdef __APPLE__
- // Changing to SCHED_RR is safe under OSX, you don't need elevated privileges and the
- // OSX scheduler will monitor SCHED_RR threads and drop to SCHED_OTHER if it detects
- // the thread running away. OSX automatically does this with the CoreAudio audio
- // device handler thread.
- int32_t result;
- thread_extended_policy_data_t theFixedPolicy;
-
- // make thread fixed, set to 'true' for a non-fixed thread
- theFixedPolicy.timeshare = false;
- result = thread_policy_set(pthread_mach_thread_np(ThreadId()), THREAD_EXTENDED_POLICY,
- (thread_policy_t)&theFixedPolicy, THREAD_EXTENDED_POLICY_COUNT);
-
- int policy;
- struct sched_param param;
- result = pthread_getschedparam(ThreadId(), &policy, ¶m );
- // change from default SCHED_OTHER to SCHED_RR
- policy = SCHED_RR;
- result = pthread_setschedparam(ThreadId(), policy, ¶m );
-#endif
-}
-
-int CThread::GetMinPriority(void)
-{
-#if 0
-//#if defined(__APPLE__)
- struct sched_param sched;
- int rtn, policy;
-
- rtn = pthread_getschedparam(ThreadId(), &policy, &sched);
- int min = sched_get_priority_min(policy);
-
- return(min);
-#else
- return(THREAD_PRIORITY_IDLE);
-#endif
-}
-
-int CThread::GetMaxPriority(void)
-{
-#if 0
-//#if defined(__APPLE__)
- struct sched_param sched;
- int rtn, policy;
-
- rtn = pthread_getschedparam(ThreadId(), &policy, &sched);
- int max = sched_get_priority_max(policy);
-
- return(max);
-#else
- return(THREAD_PRIORITY_HIGHEST);
-#endif
-}
-
-int CThread::GetNormalPriority(void)
-{
-#if 0
-//#if defined(__APPLE__)
- struct sched_param sched;
- int rtn, policy;
-
- rtn = pthread_getschedparam(ThreadId(), &policy, &sched);
- int min = sched_get_priority_min(policy);
- int max = sched_get_priority_max(policy);
-
- return( min + ((max-min) / 2) );
-#else
- return(THREAD_PRIORITY_NORMAL);
-#endif
-}
-
-
-void CThread::SetDebugCallStackName( const char *name )
-{
-#ifdef _WIN32
- const unsigned int MS_VC_EXCEPTION = 0x406d1388;
- struct THREADNAME_INFO
- {
- DWORD dwType; // must be 0x1000
- LPCSTR szName; // pointer to name (in same addr space)
- DWORD dwThreadID; // thread ID (-1 caller thread)
- DWORD dwFlags; // reserved for future use, most be zero
- } info;
-
- info.dwType = 0x1000;
- info.szName = name;
- info.dwThreadID = m_ThreadId;
- info.dwFlags = 0;
-
- try
- {
- RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR *)&info);
- }
- catch(...)
- {
- }
-#endif
-}
-
-// Get the thread name using the implementation dependant typeid() class
-// and attempt to clean it.
-std::string CThread::GetTypeName(void)
-{
- std::string name = typeid(*this).name();
-
-#if defined(_MSC_VER)
- // Visual Studio 2010 returns the name as "class CThread" etc
- if (name.substr(0, 6) == "class ")
- name = name.substr(6, name.length() - 6);
-#elif defined(__GNUC__) && !defined(__clang__)
- // gcc provides __cxa_demangle to demangle the name
- char* demangled = NULL;
- int status;
-
- demangled = __cxa_demangle(name.c_str(), NULL, 0, &status);
- if (status == 0)
- name = demangled;
- else
- CLog::Log(LOGDEBUG,"%s, __cxa_demangle(%s) failed with status %d", __FUNCTION__, name.c_str(), status);
-
- if (demangled)
- free(demangled);
-#endif
-
- return name;
-}
-
-bool CThread::WaitForThreadExit(unsigned int milliseconds)
-// Waits for thread to exit, timeout in given number of msec.
-// Returns true when thread ended
-{
- if (!m_ThreadHandle) return true;
-
-#ifndef _LINUX
- // boost priority of thread we are waiting on to same as caller
- int callee = GetThreadPriority(m_ThreadHandle);
- int caller = GetThreadPriority(GetCurrentThread());
- if(caller > callee)
- SetThreadPriority(m_ThreadHandle, caller);
-
- if (::WaitForSingleObject(m_ThreadHandle, milliseconds) != WAIT_TIMEOUT)
- return true;
-
- // restore thread priority if thread hasn't exited
- if(caller > callee)
- SetThreadPriority(m_ThreadHandle, callee);
-#else
- if (!(m_ThreadHandle->m_threadValid) || pthread_join(m_ThreadHandle->m_hThread, NULL) == 0)
- {
- m_ThreadHandle->m_threadValid = false;
- return true;
- }
-#endif
-
- return false;
-}
-
-HANDLE CThread::ThreadHandle()
-{
- return m_ThreadHandle;
}
void CThread::Process()
m_pRunnable->Run();
}
-float CThread::GetRelativeUsage()
-{
- unsigned __int64 iTime = XbmcThreads::SystemClockMillis();
- iTime *= 10000; // convert into 100ns tics
-
- // only update every 1 second
- if( iTime < m_iLastTime + 1000*10000 ) return m_fLastUsage;
-
- FILETIME CreationTime, ExitTime, UserTime, KernelTime;
- if( GetThreadTimes( m_ThreadHandle, &CreationTime, &ExitTime, &KernelTime, &UserTime ) )
- {
- unsigned __int64 iUsage = 0;
- iUsage += (((unsigned __int64)UserTime.dwHighDateTime) << 32) + ((unsigned __int64)UserTime.dwLowDateTime);
- iUsage += (((unsigned __int64)KernelTime.dwHighDateTime) << 32) + ((unsigned __int64)KernelTime.dwLowDateTime);
-
- if(m_iLastUsage > 0 && m_iLastTime > 0)
- m_fLastUsage = (float)( iUsage - m_iLastUsage ) / (float)( iTime - m_iLastTime );
-
- m_iLastUsage = iUsage;
- m_iLastTime = iTime;
-
- return m_fLastUsage;
- }
- return 0.0f;
-}
-
bool CThread::IsCurrentThread() const
{
return IsCurrentThread(ThreadId());
}
-
-ThreadIdentifier CThread::GetCurrentThreadId()
-{
-#ifdef _LINUX
- return pthread_self();
-#else
- return ::GetCurrentThreadId();
-#endif
-}
-
-bool CThread::IsCurrentThread(const ThreadIdentifier tid)
+CThread* CThread::GetCurrentThread()
{
-#ifdef _LINUX
- return pthread_equal(pthread_self(), tid);
-#else
- return (::GetCurrentThreadId() == tid);
-#endif
+ return currentThread.get();
}
void CThread::Sleep(unsigned int milliseconds)
if(milliseconds > 10 && IsCurrentThread())
m_StopEvent.WaitMSec(milliseconds);
else
- ::Sleep(milliseconds);
+ XbmcThreads::ThreadSleep(milliseconds);
}
//
//////////////////////////////////////////////////////////////////////
-#if !defined(AFX_THREAD_H__ACFB7357_B961_4AC1_9FB2_779526219817__INCLUDED_) && !defined(AFX_THREAD_H__67621B15_8724_4B5D_9343_7667075C89F2__INCLUDED_)
-#define AFX_THREAD_H__ACFB7357_B961_4AC1_9FB2_779526219817__INCLUDED_
-
-#if _MSC_VER > 1000
#pragma once
-#endif // _MSC_VER > 1000
#include <string>
-#include "system.h" // for HANDLE
-#ifdef _LINUX
-#include "PlatformInclude.h"
-#endif
+#include <stdint.h>
#include "Event.h"
+#include "threads/ThreadImpl.h"
+#include "threads/ThreadLocal.h"
class IRunnable
{
virtual ~IRunnable() {}
};
-#ifdef CTHREAD
-#undef CTHREAD
-#endif
-
// minimum as mandated by XTL
#define THREAD_MINSTACKSIZE 0x10000
class CThread
{
public:
- CThread(const char* ThreadName = NULL);
- CThread(IRunnable* pRunnable, const char* ThreadName = NULL);
+ CThread(const char* ThreadName);
+ CThread(IRunnable* pRunnable, const char* ThreadName);
virtual ~CThread();
void Create(bool bAutoDelete = false, unsigned stacksize = 0);
bool WaitForThreadExit(unsigned int milliseconds);
void Sleep(unsigned int milliseconds);
bool SetPriority(const int iPriority);
- void SetPrioritySched_RR(void);
+ int GetPriority(void);
int GetMinPriority(void);
int GetMaxPriority(void);
int GetNormalPriority(void);
- HANDLE ThreadHandle();
- operator HANDLE();
- operator HANDLE() const;
+ int GetSchedRRPriority(void);
+ bool SetPrioritySched_RR(int iPriority);
bool IsAutoDelete() const;
virtual void StopThread(bool bWait = true);
float GetRelativeUsage(); // returns the relative cpu usage of this thread since last call
+ int64_t GetAbsoluteUsage();
bool IsCurrentThread() const;
+ bool IsRunning();
static bool IsCurrentThread(const ThreadIdentifier tid);
static ThreadIdentifier GetCurrentThreadId();
+ static CThread* GetCurrentThread();
+ static int64_t GetCurrentThreadUsage();
protected:
virtual void OnStartup(){};
virtual void OnExit(){};
virtual void Process();
volatile bool m_bStop;
- HANDLE m_ThreadHandle;
enum WaitResponse { WAIT_INTERRUPTED = -1, WAIT_SIGNALED = 0, WAIT_TIMEDOUT = 1 };
}
private:
- /*! \brief set the threadname for the debugger/callstack, implementation dependent.
- */
- void SetDebugCallStackName( const char *threadName );
- std::string GetTypeName(void);
-
-private:
+ static THREADFUNC staticThread(void *data);
ThreadIdentifier ThreadId() const;
+ void SetThreadInfo();
+ void TermHandler();
+
+ ThreadIdentifier m_ThreadId;
+ ThreadOpaque m_ThreadOpaque;
bool m_bAutoDelete;
CEvent m_StopEvent;
- unsigned m_ThreadId; // This value is unreliable on platforms using pthreads
- // Use m_ThreadHandle->m_hThread instead
+ CEvent m_TermEvent;
+ CEvent m_StartEvent;
+ CCriticalSection m_CriticalSection;
IRunnable* m_pRunnable;
-
- unsigned __int64 m_iLastUsage;
- unsigned __int64 m_iLastTime;
+ uint64_t m_iLastUsage;
+ uint64_t m_iLastTime;
float m_fLastUsage;
std::string m_ThreadName;
-
-#ifdef _LINUX
- static void term_handler (int signum);
-#endif
-
-#ifndef _WIN32
- static int staticThread(void* data);
-#else
- static DWORD WINAPI staticThread(LPVOID* data);
-#endif
-
-private:
};
-
-#endif // !defined(AFX_THREAD_H__ACFB7357_B961_4AC1_9FB2_779526219817__INCLUDED_)
--- /dev/null
+/*
+ * Copyright (C) 2005-2011 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#pragma once
+
+#include "threads/platform/ThreadImpl.h"
+
--- /dev/null
+/*
+ * Copyright (C) 2005-2011 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#pragma once
+
+#if (defined TARGET_POSIX)
+#include "threads/platform/pthreads/ThreadImpl.cpp"
+#if defined(TARGET_DARWIN_IOS)
+#include "threads/platform/darwin/ThreadSchedImpl.cpp"
+#else
+#include "threads/platform/linux/ThreadSchedImpl.cpp"
+#endif
+#elif (defined TARGET_WINDOWS)
+#include "threads/platform/win/ThreadImpl.cpp"
+#endif
+
--- /dev/null
+/*
+ * Copyright (C) 2005-2011 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#pragma once
+
+#if (defined TARGET_POSIX)
+#include "threads/platform/pthreads/ThreadImpl.h"
+#elif (defined TARGET_WINDOWS)
+#include "threads/platform/win/ThreadImpl.h"
+#endif
--- /dev/null
+/*
+ * Copyright (C) 2005-2011 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+int CThread::GetSchedRRPriority(void)
+{
+ return 96;
+}
+
+bool CThread::SetPrioritySched_RR(int iPriority)
+{
+ // Changing to SCHED_RR is safe under OSX, you don't need elevated privileges and the
+ // OSX scheduler will monitor SCHED_RR threads and drop to SCHED_OTHER if it detects
+ // the thread running away. OSX automatically does this with the CoreAudio audio
+ // device handler thread.
+ int32_t result;
+ thread_extended_policy_data_t theFixedPolicy;
+
+ // make thread fixed, set to 'true' for a non-fixed thread
+ theFixedPolicy.timeshare = false;
+ result = thread_policy_set(pthread_mach_thread_np(ThreadId()), THREAD_EXTENDED_POLICY,
+ (thread_policy_t)&theFixedPolicy, THREAD_EXTENDED_POLICY_COUNT);
+
+ int policy;
+ struct sched_param param;
+ result = pthread_getschedparam(ThreadId(), &policy, ¶m );
+ // change from default SCHED_OTHER to SCHED_RR
+ policy = SCHED_RR;
+ result = pthread_setschedparam(ThreadId(), policy, ¶m );
+}
--- /dev/null
+/*
+ * Copyright (C) 2005-2011 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+int CThread::GetSchedRRPriority(void)
+{
+ return GetNormalPriority();
+}
+
+bool CThread::SetPrioritySched_RR(int iPriority)
+{
+ return false;
+}
--- /dev/null
+/*
+ * Copyright (C) 2005-2011 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include <limits.h>
+#include <sys/syscall.h>
+#include <sys/resource.h>
+#include <string.h>
+
+void CThread::Create(bool bAutoDelete, unsigned stacksize)
+{
+ if (m_ThreadId != 0)
+ {
+ CLog::Log(LOGERROR, "%s - fatal error creating thread- old thread id not null", __FUNCTION__);
+ exit(1);
+ }
+ m_iLastTime = XbmcThreads::SystemClockMillis() * 10000;
+ m_iLastUsage = 0;
+ m_fLastUsage = 0.0f;
+ m_bAutoDelete = bAutoDelete;
+ m_bStop = false;
+ m_StopEvent.Reset();
+ m_TermEvent.Reset();
+ m_StartEvent.Reset();
+
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ if (stacksize > PTHREAD_STACK_MIN)
+ pthread_attr_setstacksize(&attr, stacksize);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ if (pthread_create(&m_ThreadId, &attr, (void*(*)(void*))staticThread, this) != 0)
+ {
+ CLog::Log(LOGNOTICE, "%s - fatal error creating thread",__FUNCTION__);
+ }
+ pthread_attr_destroy(&attr);
+}
+
+void CThread::TermHandler()
+{
+
+}
+
+void CThread::SetThreadInfo()
+{
+ m_ThreadOpaque.LwpId = syscall(SYS_gettid);
+
+ // start thread with nice level of appication
+ int appNice = getpriority(PRIO_PROCESS, getpid());
+ if (setpriority(PRIO_PROCESS, m_ThreadOpaque.LwpId, appNice) != 0)
+ CLog::Log(LOGERROR, "%s: error %s", __FUNCTION__, strerror(errno));
+}
+
+ThreadIdentifier CThread::GetCurrentThreadId()
+{
+ return pthread_self();
+}
+
+bool CThread::IsCurrentThread(const ThreadIdentifier tid)
+{
+ return pthread_equal(pthread_self(), tid);
+}
+
+int CThread::GetMinPriority(void)
+{
+ // one level lower than application
+ return -1;
+}
+
+int CThread::GetMaxPriority(void)
+{
+ // one level higher than application
+ return 1;
+}
+
+int CThread::GetNormalPriority(void)
+{
+ // same level as application
+ return 0;
+}
+
+bool CThread::SetPriority(const int iPriority)
+{
+ bool bReturn = false;
+
+ // wait until thread is running, it needs to get its lwp id
+ m_StartEvent.Wait();
+
+ CSingleLock lock(m_CriticalSection);
+
+ // get min prio for SCHED_RR
+ int minRR = GetMaxPriority() + 1;
+
+ if (!m_ThreadId)
+ bReturn = false;
+ else if (iPriority >= minRR)
+ bReturn = SetPrioritySched_RR(iPriority);
+ else
+ {
+ // get user max prio
+ struct rlimit limit;
+ int userMaxPrio;
+ if (getrlimit(RLIMIT_NICE, &limit) == 0)
+ {
+ userMaxPrio = limit.rlim_cur - 20;
+ }
+ else
+ userMaxPrio = 0;
+
+ // keep priority in bounds
+ int prio = iPriority;
+ if (prio >= GetMaxPriority())
+ prio = std::min(GetMaxPriority(), userMaxPrio);
+ if (prio < GetMinPriority())
+ prio = GetMinPriority();
+
+ // nice level of application
+ int appNice = getpriority(PRIO_PROCESS, getpid());
+ if (prio)
+ prio = prio > 0 ? appNice-1 : appNice+1;
+
+ if (setpriority(PRIO_PROCESS, m_ThreadOpaque.LwpId, prio) == 0)
+ bReturn = true;
+ else
+ CLog::Log(LOGERROR, "%s: error %s", __FUNCTION__, strerror(errno));
+ }
+
+ return bReturn;
+}
+
+int CThread::GetPriority()
+{
+ int iReturn;
+
+ // lwp id is valid after start signel has fired
+ m_StartEvent.Wait();
+
+ CSingleLock lock(m_CriticalSection);
+
+ int appNice = getpriority(PRIO_PROCESS, getpid());
+ int prio = getpriority(PRIO_PROCESS, m_ThreadOpaque.LwpId);
+ iReturn = appNice - prio;
+
+ return iReturn;
+}
+
+bool CThread::WaitForThreadExit(unsigned int milliseconds)
+{
+ bool bReturn = m_TermEvent.WaitMSec(milliseconds);
+
+ return bReturn;
+}
+
+int64_t CThread::GetAbsoluteUsage()
+{
+ CSingleLock lock(m_CriticalSection);
+
+ if (!m_ThreadId)
+ return 0;
+
+ clockid_t clock;
+ int64_t time = 0;
+ if (pthread_getcpuclockid(m_ThreadId, &clock) == 0)
+ {
+ struct timespec tp;
+ clock_gettime(clock, &tp);
+ time = (int64_t)tp.tv_sec * 10000000 + tp.tv_nsec/100;
+ }
+ return time;
+}
+
+float CThread::GetRelativeUsage()
+{
+ unsigned int iTime = XbmcThreads::SystemClockMillis();
+ iTime *= 10000; // convert into 100ns tics
+
+ // only update every 1 second
+ if( iTime < m_iLastTime + 1000*10000 ) return m_fLastUsage;
+
+ int64_t iUsage = GetAbsoluteUsage();
+
+ if (m_iLastUsage > 0 && m_iLastTime > 0)
+ m_fLastUsage = (float)( iUsage - m_iLastUsage ) / (float)( iTime - m_iLastTime );
+
+ m_iLastUsage = iUsage;
+ m_iLastTime = iTime;
+
+ return m_fLastUsage;
+}
+
+int64_t CThread::GetCurrentThreadUsage()
+{
+ pthread_t tid = pthread_self();
+ clockid_t clock;
+ int64_t time = 0;
+ if (pthread_getcpuclockid(tid, &clock) == 0)
+ {
+ struct timespec tp;
+ clock_gettime(clock, &tp);
+ time = (int64_t)tp.tv_sec * 10000000 + tp.tv_nsec/100;
+ }
+ return time;
+}
+
--- /dev/null
+/*
+* Copyright (C) 2005-2011 Team XBMC
+* http://www.xbmc.org
+*
+* This Program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2, or (at your option)
+* any later version.
+*
+* This Program 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 General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with XBMC; see the file COPYING. If not, write to
+* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+* http://www.gnu.org/copyleft/gpl.html
+*
+*/
+
+#pragma once
+
+#include <pthread.h>
+
+struct threadOpaque
+{
+ pid_t LwpId;
+};
+
+typedef pthread_t ThreadIdentifier;
+typedef threadOpaque ThreadOpaque;
+typedef int THREADFUNC;
+
+namespace XbmcThreads
+{
+ inline static void ThreadSleep(unsigned int millis) { usleep(millis*1000); }
+}
+
--- /dev/null
+/*
+ * Copyright (C) 2005-2011 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include <windows.h>
+
+
+void CThread::Create(bool bAutoDelete, unsigned stacksize)
+{
+ if (m_ThreadId != 0)
+ {
+ CLog::Log(LOGERROR, "%s - fatal error creating thread- old thread id not null", __FUNCTION__);
+ exit(1);
+ }
+ m_iLastTime = XbmcThreads::SystemClockMillis() * 10000;
+ m_iLastUsage = 0;
+ m_fLastUsage = 0.0f;
+ m_bAutoDelete = bAutoDelete;
+ m_bStop = false;
+ m_StopEvent.Reset();
+ m_TermEvent.Reset();
+ m_StartEvent.Reset();
+
+ m_ThreadOpaque.handle = CreateThread(NULL,stacksize, (LPTHREAD_START_ROUTINE)&staticThread, this, 0, &m_ThreadId);
+ if (m_ThreadOpaque.handle == NULL)
+ {
+ CLog::Log(LOGERROR, "%s - fatal error creating thread", __FUNCTION__);
+ }
+}
+
+void CThread::TermHandler()
+{
+ CloseHandle(m_ThreadOpaque.handle);
+ m_ThreadOpaque.handle = NULL;
+}
+
+void CThread::SetThreadInfo()
+{
+ const unsigned int MS_VC_EXCEPTION = 0x406d1388;
+ struct THREADNAME_INFO
+ {
+ DWORD dwType; // must be 0x1000
+ LPCSTR szName; // pointer to name (in same addr space)
+ DWORD dwThreadID; // thread ID (-1 caller thread)
+ DWORD dwFlags; // reserved for future use, most be zero
+ } info;
+
+ info.dwType = 0x1000;
+ info.szName = m_ThreadName.c_str();
+ info.dwThreadID = m_ThreadId;
+ info.dwFlags = 0;
+
+ try
+ {
+ RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR *)&info);
+ }
+ catch(...)
+ {
+ }
+}
+
+ThreadIdentifier CThread::GetCurrentThreadId()
+{
+ return ::GetCurrentThreadId();
+}
+
+bool CThread::IsCurrentThread(const ThreadIdentifier tid)
+{
+ return (::GetCurrentThreadId() == tid);
+}
+
+int CThread::GetMinPriority(void)
+{
+ return(THREAD_PRIORITY_IDLE);
+}
+
+int CThread::GetMaxPriority(void)
+{
+ return(THREAD_PRIORITY_HIGHEST);
+}
+
+int CThread::GetNormalPriority(void)
+{
+ return(THREAD_PRIORITY_NORMAL);
+}
+
+int CThread::GetSchedRRPriority(void)
+{
+ return GetNormalPriority();
+}
+
+bool CThread::SetPriority(const int iPriority)
+{
+ bool bReturn = false;
+
+ CSingleLock lock(m_CriticalSection);
+ if (m_ThreadOpaque.handle)
+ {
+ bReturn = SetThreadPriority(m_ThreadOpaque.handle, iPriority) == TRUE;
+ }
+
+ return bReturn;
+}
+
+int CThread::GetPriority()
+{
+ CSingleLock lock(m_CriticalSection);
+
+ int iReturn = THREAD_PRIORITY_NORMAL;
+ if (m_ThreadOpaque.handle)
+ {
+ iReturn = GetThreadPriority(m_ThreadOpaque.handle);
+ }
+ return iReturn;
+}
+
+bool CThread::WaitForThreadExit(unsigned int milliseconds)
+{
+ bool bReturn = true;
+
+ CSingleLock lock(m_CriticalSection);
+ if (m_ThreadId && m_ThreadOpaque.handle != NULL)
+ {
+ // boost priority of thread we are waiting on to same as caller
+ int callee = GetThreadPriority(m_ThreadOpaque.handle);
+ int caller = GetThreadPriority(GetCurrentThread());
+ if(caller > callee)
+ SetThreadPriority(m_ThreadOpaque.handle, caller);
+
+ lock.Leave();
+ bReturn = m_TermEvent.WaitMSec(milliseconds);
+ lock.Enter();
+
+ // restore thread priority if thread hasn't exited
+ if(caller > callee && m_ThreadOpaque.handle)
+ SetThreadPriority(m_ThreadOpaque.handle, callee);
+ }
+ return bReturn;
+}
+
+int64_t CThread::GetAbsoluteUsage()
+{
+ CSingleLock lock(m_CriticalSection);
+
+ if (!m_ThreadOpaque.handle)
+ return 0;
+
+ uint64_t time = 0;
+ FILETIME CreationTime, ExitTime, UserTime, KernelTime;
+ if( GetThreadTimes(m_ThreadOpaque.handle, &CreationTime, &ExitTime, &KernelTime, &UserTime ) )
+ {
+ time = (((uint64_t)UserTime.dwHighDateTime) << 32) + ((uint64_t)UserTime.dwLowDateTime);
+ time += (((uint64_t)KernelTime.dwHighDateTime) << 32) + ((uint64_t)KernelTime.dwLowDateTime);
+ }
+ return time;
+}
+
+float CThread::GetRelativeUsage()
+{
+ unsigned int iTime = XbmcThreads::SystemClockMillis();
+ iTime *= 10000; // convert into 100ns tics
+
+ // only update every 1 second
+ if( iTime < m_iLastTime + 1000*10000 ) return m_fLastUsage;
+
+ int64_t iUsage = GetAbsoluteUsage();
+
+ if (m_iLastUsage > 0 && m_iLastTime > 0)
+ m_fLastUsage = (float)( iUsage - m_iLastUsage ) / (float)( iTime - m_iLastTime );
+
+ m_iLastUsage = iUsage;
+ m_iLastTime = iTime;
+
+ return m_fLastUsage;
+}
+
+int64_t CThread::GetCurrentThreadUsage()
+{
+ HANDLE h = GetCurrentThread();
+
+ uint64_t time = 0;
+ FILETIME CreationTime, ExitTime, UserTime, KernelTime;
+ if( GetThreadTimes(h, &CreationTime, &ExitTime, &KernelTime, &UserTime ) )
+ {
+ time = (((uint64_t)UserTime.dwHighDateTime) << 32) + ((uint64_t)UserTime.dwLowDateTime);
+ time += (((uint64_t)KernelTime.dwHighDateTime) << 32) + ((uint64_t)KernelTime.dwLowDateTime);
+ }
+ return time;
+}
+
--- /dev/null
+/*
+* Copyright (C) 2005-2011 Team XBMC
+* http://www.xbmc.org
+*
+* This Program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2, or (at your option)
+* any later version.
+*
+* This Program 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 General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with XBMC; see the file COPYING. If not, write to
+* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+* http://www.gnu.org/copyleft/gpl.html
+*
+*/
+
+#pragma once
+
+#include <windows.h>
+
+
+struct threadOpaque
+{
+ HANDLE handle;
+};
+
+typedef DWORD ThreadIdentifier;
+typedef threadOpaque ThreadOpaque;
+typedef DWORD THREADFUNC;
+
+namespace XbmcThreads
+{
+ inline static void ThreadSleep(unsigned int millis) { Sleep(millis); }
+}
+
using namespace std;
-CAlarmClock::CAlarmClock() : m_bIsRunning(false)
+CAlarmClock::CAlarmClock() : CThread("CAlarmClock"), m_bIsRunning(false)
{
}
#include "log.h"
#include "utils/TimeUtils.h"
-CAsyncFileCopy::CAsyncFileCopy()
+CAsyncFileCopy::CAsyncFileCopy() : CThread("CAsyncFileCopy")
{
m_cancelled = false;
m_succeeded = false;
WORD CDownloadQueue::m_wNextQueueId = 0;
-CDownloadQueue::CDownloadQueue(void) : CThread()
+CDownloadQueue::CDownloadQueue(void) : CThread("CDownloadQueue")
{
m_bStop = false;
m_wQueueId = m_wNextQueueId++;
#include "threads/CriticalSection.h"
#include "StdString.h"
+#include "system.h"
+
struct TICKET
{
TICKET(WORD aQueueId, DWORD aItemId)
*/
#include "DownloadQueue.h"
+#include "system.h"
#define MAX_DOWNLOAD_QUEUES 3
#include "threads/SingleLock.h"
#include "utils/log.h"
+#include "system.h"
+
+
using namespace std;
bool CJob::ShouldCancel(unsigned int progress, unsigned int total) const
void LoadSkin(const CStdString &xmlFile);
void Reset();
void Render(LCD_MODE mode);
- ILCD() : m_disableOnPlay(DISABLE_ON_PLAY_NONE),
- m_eCurrentCharset(CUSTOM_CHARSET_DEFAULT) {}
+ ILCD() : CThread("ILCD"),
+ m_disableOnPlay(DISABLE_ON_PLAY_NONE),
+ m_eCurrentCharset(CUSTOM_CHARSET_DEFAULT) {}
protected:
virtual void Process() = 0;
void StringToLCDCharSet(CStdString& strText);
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
-CRssReader::CRssReader() : CThread()
+CRssReader::CRssReader() : CThread("CRssReader")
{
m_pObserver = NULL;
m_spacesBetweenFeeds = 0;
#include "tinyXML/tinyxml.h"
+#include "system.h"
+
+
#define RSS_COLOR_BODY 0
#define RSS_COLOR_HEADLINE 1
#define RSS_COLOR_CHANNEL 2
using namespace XFILE;
-CSplash::CSplash(const CStdString& imageName)
+CSplash::CSplash(const CStdString& imageName) : CThread("CSplash")
{
m_ImageName = imageName;
fade = 0.5;
bool CSplash::IsRunning()
{
- return (m_ThreadHandle != NULL);
+ return (IsRunning());
}
CTuxBoxUtil g_tuxbox;
CTuxBoxService g_tuxboxService;
-CTuxBoxService::CTuxBoxService()
+CTuxBoxService::CTuxBoxService() : CThread("CTuxBoxService")
{
}
CTuxBoxService::~CTuxBoxService()
m_state = FIND_MOVIE;
m_strMovie = strMovie;
m_found = 0;
- if (ThreadHandle())
+ if (IsRunning())
StopThread();
Create();
while (m_state != DO_NOTHING)
{ // threaded version
m_state = GET_DETAILS;
m_found = 0;
- if (ThreadHandle())
+ if (IsRunning())
StopThread();
Create();
while (!m_found)
{ // threaded version
m_state = GET_EPISODE_DETAILS;
m_found = 0;
- if (ThreadHandle())
+ if (IsRunning())
StopThread();
Create();
while (!m_found)
{ // threaded version
m_state = GET_EPISODE_LIST;
m_found = 0;
- if (ThreadHandle())
+ if (IsRunning())
StopThread();
Create();
while (!m_found)
class CVideoInfoDownloader : public CThread
{
public:
- CVideoInfoDownloader(const ADDON::ScraperPtr &scraper) : m_info(scraper) {}
+ CVideoInfoDownloader(const ADDON::ScraperPtr &scraper) : CThread("CVideoInfoDownloader"), m_info(scraper) {}
virtual ~CVideoInfoDownloader() {}
// threaded lookup functions
namespace VIDEO
{
- CVideoInfoScanner::CVideoInfoScanner()
+ CVideoInfoScanner::CVideoInfoScanner() : CThread("CVideoInfoScanner")
{
m_bRunning = false;
m_pObserver = NULL;
#endif
-CVideoReferenceClock::CVideoReferenceClock()
+CVideoReferenceClock::CVideoReferenceClock() : CThread("CVideoReferenceClock")
{
m_SystemFrequency = CurrentHostFrequency();
m_ClockSpeed = 1.0;
typedef __int64 fpos64_t;
typedef __int64 __off64_t;
typedef long __off_t;
-typedef unsigned long ThreadIdentifier;
#define ssize_t int
CWHelper g_windowHelper;
-CWHelper::CWHelper(void)
+CWHelper::CWHelper(void) : CThread("CWHelper")
{
m_hwnd = NULL;
m_hProcess = NULL;