Skip to content
Browse files

threads: remove WINAPI, implement priority for pthreads

Also:
[fix] threads: fix race condition when stopping thread - cherry pick merge
[fix] resolve merge conflicts after ee1a1e2

Also, from jimfcarroll:
[fixed] AirPlayServer now complies with the new CThread constructor requirements (that is, you must supply a thread name).
replace custom thread local storage with the XbmcThreads::ThreadLocal template.
[cosmetic] removed incorrect hungarian notation.
[cleanup] Removed XSyncUtils. Moved the GlobalMemoryStatus call to XMemUtil. Cleaned up code that used the #define INFINITE from XSyncUtils.h
[cleanup] Some miscellaneous cleanup. Fixed initialization warning in LCD. Removed some unused functions and members.
  • Loading branch information...
1 parent 7ed3a94 commit 80f05515c2b3976c7e101fc766d3298c67c3d8e1 @FernetMenta committed Jul 31, 2011
Showing with 939 additions and 1,161 deletions.
  1. +0 −4 lib/UnrarXLib/extract.cpp
  2. +0 −5 lib/UnrarXLib/unpack.cpp
  3. +0 −4 lib/UnrarXLib/unpack15.cpp
  4. +1 −1 xbmc/ApplicationMessenger.cpp
  5. +1 −1 xbmc/cdrip/CDDAReader.cpp
  6. +0 −9 xbmc/cores/DllLoader/exports/emu_kernel32.cpp
  7. +0 −1 xbmc/cores/DllLoader/exports/emu_kernel32.h
  8. +1 −1 xbmc/cores/DummyVideoPlayer.cpp
  9. +1 −1 xbmc/cores/dvdplayer/DVDCodecs/Video/CrystalHD.cpp
  10. +11 −15 xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
  11. +4 −9 xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp
  12. +12 −12 xbmc/cores/dvdplayer/DVDPerformanceCounter.h
  13. +5 −6 xbmc/cores/dvdplayer/DVDPlayer.cpp
  14. +1 −1 xbmc/cores/dvdplayer/DVDPlayerAudio.cpp
  15. +2 −2 xbmc/cores/dvdplayer/DVDPlayerVideo.cpp
  16. +2 −2 xbmc/cores/paplayer/PAPlayer.cpp
  17. +1 −1 xbmc/dialogs/GUIDialogCache.cpp
  18. +2 −2 xbmc/filesystem/FileCache.cpp
  19. +2 −0 xbmc/filesystem/FilePipe.cpp
  20. +1 −1 xbmc/filesystem/FileRar.cpp
  21. +1 −1 xbmc/filesystem/HTSPDirectory.cpp
  22. +1 −1 xbmc/filesystem/LastFMDirectory.cpp
  23. +1 −1 xbmc/filesystem/MythSession.cpp
  24. +2 −0 xbmc/filesystem/PipesManager.cpp
  25. +1 −1 xbmc/filesystem/RarManager.h
  26. +2 −2 xbmc/filesystem/SAPDirectory.cpp
  27. +2 −2 xbmc/interfaces/python/XBPython.cpp
  28. +1 −1 xbmc/interfaces/python/XBPython.h
  29. +2 −2 xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.cpp
  30. +1 −1 xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.h
  31. +2 −2 xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.cpp
  32. +1 −1 xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.h
  33. +3 −3 xbmc/interfaces/python/xbmcmodule/window.cpp
  34. +0 −3 xbmc/linux/Makefile.in
  35. +0 −2 xbmc/linux/PlatformDefs.h
  36. +0 −3 xbmc/linux/PlatformInclude.h
  37. +0 −144 xbmc/linux/XEventUtils.cpp
  38. +5 −13 xbmc/linux/XHandle.cpp
  39. +1 −5 xbmc/linux/XHandle.h
  40. +130 −0 xbmc/linux/XMemUtils.cpp
  41. +4 −0 xbmc/linux/XMemUtils.h
  42. +0 −169 xbmc/linux/XSyncUtils.cpp
  43. +0 −210 xbmc/linux/XThreadUtils.cpp
  44. +3 −3 xbmc/music/LastFmManager.cpp
  45. +2 −2 xbmc/music/infoscanner/MusicInfoScanner.cpp
  46. +1 −1 xbmc/music/infoscanner/MusicInfoScraper.cpp
  47. +1 −1 xbmc/network/AirPlayServer.cpp
  48. +1 −0 xbmc/network/Network.h
  49. +1 −1 xbmc/network/TCPServer.cpp
  50. +1 −1 xbmc/network/UdpClient.cpp
  51. +1 −0 xbmc/network/UdpClient.h
  52. +2 −2 xbmc/network/libscrobbler/scrobbler.cpp
  53. +1 −1 xbmc/pictures/GUIWindowSlideShow.cpp
  54. +1 −1 xbmc/rendering/dx/RenderSystemDX.cpp
  55. +43 −404 xbmc/threads/Thread.cpp
  56. +23 −45 xbmc/threads/Thread.h
  57. +25 −0 xbmc/threads/ThreadImpl.h
  58. +10 −14 xbmc/{linux/XEventUtils.h → threads/platform/ThreadImpl.cpp}
  59. +6 −22 xbmc/{linux/XSyncUtils.h → threads/platform/ThreadImpl.h}
  60. +47 −0 xbmc/threads/platform/darwin/ThreadSchedImpl.cpp
  61. +30 −0 xbmc/threads/platform/linux/ThreadSchedImpl.cpp
  62. +220 −0 xbmc/threads/platform/pthreads/ThreadImpl.cpp
  63. +39 −0 xbmc/threads/platform/pthreads/ThreadImpl.h
  64. +207 −0 xbmc/threads/platform/win/ThreadImpl.cpp
  65. +40 −0 xbmc/threads/platform/win/ThreadImpl.h
  66. +1 −1 xbmc/utils/AlarmClock.cpp
  67. +1 −1 xbmc/utils/AsyncFileCopy.cpp
  68. +1 −1 xbmc/utils/DownloadQueue.cpp
  69. +2 −0 xbmc/utils/DownloadQueue.h
  70. +1 −0 xbmc/utils/DownloadQueueManager.h
  71. +3 −0 xbmc/utils/JobManager.cpp
  72. +3 −2 xbmc/utils/LCD.h
  73. +1 −1 xbmc/utils/RssReader.cpp
  74. +3 −0 xbmc/utils/RssReader.h
  75. +2 −2 xbmc/utils/Splash.cpp
  76. +1 −1 xbmc/utils/TuxBoxUtil.cpp
  77. +4 −4 xbmc/video/VideoInfoDownloader.cpp
  78. +1 −1 xbmc/video/VideoInfoDownloader.h
  79. +1 −1 xbmc/video/VideoInfoScanner.cpp
  80. +1 −1 xbmc/video/VideoReferenceClock.cpp
  81. +0 −1 xbmc/win32/PlatformDefs.h
  82. +1 −1 xbmc/win32/WindowHelper.cpp
View
4 lib/UnrarXLib/extract.cpp
@@ -1,9 +1,5 @@
#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)
View
5 lib/UnrarXLib/unpack.cpp
@@ -8,11 +8,6 @@
#include "unpack20.cpp"
#endif
-#ifdef _LINUX
-#include "XSyncUtils.h"
-#include "XEventUtils.h"
-#endif
-
Unpack::Unpack(ComprDataIO *DataIO)
{
UnpIO=DataIO;
View
4 lib/UnrarXLib/unpack15.cpp
@@ -1,7 +1,3 @@
-#ifdef _LINUX
-#include "XSyncUtils.h"
-#endif
-
#define STARTL1 2
static unsigned int DecL1[]={0x8000,0xa000,0xc000,0xd000,0xe000,0xea00,
0xee00,0xf000,0xf200,0xf200,0xffff};
View
2 xbmc/ApplicationMessenger.cpp
@@ -75,7 +75,7 @@
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;
View
2 xbmc/cdrip/CDDAReader.cpp
@@ -29,7 +29,7 @@
#define SECTOR_COUNT 52
-CCDDAReader::CCDDAReader()
+CCDDAReader::CCDDAReader() : CThread("CCDDAReader")
{
m_sRipBuffer[0].pbtStream = NULL;
m_sRipBuffer[1].pbtStream = NULL;
View
9 xbmc/cores/DllLoader/exports/emu_kernel32.cpp
@@ -240,15 +240,6 @@ extern "C" DWORD WINAPI dllGetCurrentProcessId(void)
#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
View
1 xbmc/cores/DllLoader/exports/emu_kernel32.h
@@ -686,7 +686,6 @@ extern "C" BOOL WINAPI dllGetProcessAffinityMask(HANDLE hProcess, LPDWORD lpProc
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();
View
2 xbmc/cores/DummyVideoPlayer.cpp
@@ -33,7 +33,7 @@
CDummyVideoPlayer::CDummyVideoPlayer(IPlayerCallback& callback)
: IPlayer(callback),
- CThread()
+ CThread("CDummyVideoPlayer")
{
m_paused = false;
m_clock = 0;
View
2 xbmc/cores/dvdplayer/DVDCodecs/Video/CrystalHD.cpp
@@ -323,7 +323,7 @@ CPictureBuffer::~CPictureBuffer()
#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),
View
26 xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
@@ -19,7 +19,6 @@
*
*/
-#include "threads/SystemClock.h"
#include "system.h"
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
@@ -44,6 +43,7 @@
#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)
@@ -154,16 +154,12 @@ static void ff_flush_avutil_log_buffers(void)
++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)
{
- if(g_demuxer && g_demuxer->Aborted())
+ CDVDDemuxFFmpeg* demuxer = g_demuxer.get();
+ if(demuxer && demuxer->Aborted())
return 1;
return 0;
}
@@ -235,7 +231,7 @@ bool CDVDDemuxFFmpeg::Open(CDVDInputStream* pInput)
std::string strFile;
m_iCurrentPts = DVD_NOPTS_VALUE;
m_speed = DVD_PLAYSPEED_NORMAL;
- g_demuxer = this;
+ g_demuxer.set(this);
m_program = UINT_MAX;
if (!pInput) return false;
@@ -507,7 +503,7 @@ bool CDVDDemuxFFmpeg::Open(CDVDInputStream* pInput)
void CDVDDemuxFFmpeg::Dispose()
{
- g_demuxer = this;
+ g_demuxer.set(this);
if (m_pFormatContext)
{
@@ -556,7 +552,7 @@ void CDVDDemuxFFmpeg::Reset()
void CDVDDemuxFFmpeg::Flush()
{
- g_demuxer = this;
+ g_demuxer.set(this);
// naughty usage of an internal ffmpeg function
if (m_pFormatContext)
@@ -572,7 +568,7 @@ void CDVDDemuxFFmpeg::Abort()
void CDVDDemuxFFmpeg::SetSpeed(int iSpeed)
{
- g_demuxer = this;
+ g_demuxer.set(this);
if(!m_pFormatContext)
return;
@@ -634,7 +630,7 @@ double CDVDDemuxFFmpeg::ConvertTimestamp(int64_t pts, int den, int num)
DemuxPacket* CDVDDemuxFFmpeg::Read()
{
- g_demuxer = this;
+ g_demuxer.set(this);
AVPacket pkt;
DemuxPacket* pPacket = NULL;
@@ -833,7 +829,7 @@ DemuxPacket* CDVDDemuxFFmpeg::Read()
bool CDVDDemuxFFmpeg::SeekTime(int time, bool backwords, double *startpts)
{
- g_demuxer = this;
+ g_demuxer.set(this);
if(time < 0)
time = 0;
@@ -893,7 +889,7 @@ bool CDVDDemuxFFmpeg::SeekTime(int time, bool backwords, double *startpts)
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);
View
13 xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp
@@ -21,6 +21,7 @@
#include "DVDPerformanceCounter.h"
#include "DVDMessageQueue.h"
+#include "utils/TimeUtils.h"
#include "dvd_config.h"
@@ -68,22 +69,16 @@ HRESULT __stdcall DVDPerformanceCounterVideoQueue(PLARGE_INTEGER numerator, PLAR
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, &current_time_thread, &dummy);
- GetSystemTimeAsFileTime(&current_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);
View
24 xbmc/cores/dvdplayer/DVDPerformanceCounter.h
@@ -24,7 +24,7 @@
#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;
@@ -33,7 +33,7 @@ typedef struct stProcessPerformance
{
ULARGE_INTEGER timer_thread;
ULARGE_INTEGER timer_system;
- HANDLE hThread;
+ CThread* thread;
} ProcessPerformance;
class CDVDPerformanceCounter
@@ -45,20 +45,20 @@ 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;
View
11 xbmc/cores/dvdplayer/DVDPlayer.cpp
@@ -348,7 +348,7 @@ bool CDVDPlayer::OpenFile(const CFileItem& file, const CPlayerOptions &options)
// 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;
@@ -440,9 +440,8 @@ void CDVDPlayer::OnStartup()
m_messenger.Init();
- g_dvdPerformanceCounter.EnableMainPerformance(ThreadHandle());
-
CUtil::ClearTempFonts();
+ g_dvdPerformanceCounter.EnableMainPerformance(this);
}
bool CDVDPlayer::OpenInputStream()
@@ -2897,7 +2896,7 @@ bool CDVDPlayer::OpenAudioStream(int iStream, int source)
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;
}
@@ -2962,11 +2961,11 @@ bool CDVDPlayer::OpenVideoStream(int iStream, int source)
// 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;
View
2 xbmc/cores/dvdplayer/DVDPlayerAudio.cpp
@@ -518,7 +518,7 @@ void CDVDPlayerAudio::OnStartup()
m_decode.msg = NULL;
m_decode.Release();
- g_dvdPerformanceCounter.EnableAudioDecodePerformance(ThreadHandle());
+ g_dvdPerformanceCounter.EnableAudioDecodePerformance(this);
#ifdef _WIN32
CoInitializeEx(NULL, COINIT_MULTITHREADED);
View
4 xbmc/cores/dvdplayer/DVDPlayerVideo.cpp
@@ -189,7 +189,7 @@ bool CDVDPlayerVideo::OpenStream( CDVDStreamInfo &hint )
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
@@ -291,7 +291,7 @@ void CDVDPlayerVideo::OnStartup()
m_iCurrentPts = DVD_NOPTS_VALUE;
m_FlipTimeStamp = m_pClock->GetAbsoluteClock();
- g_dvdPerformanceCounter.EnableVideoDecodePerformance(ThreadHandle());
+ g_dvdPerformanceCounter.EnableVideoDecodePerformance(this);
}
void CDVDPlayerVideo::Process()
View
4 xbmc/cores/paplayer/PAPlayer.cpp
@@ -52,7 +52,7 @@
// 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) : CThread("PAPlayer"), IPlayer(callback)
{
m_bIsPlaying = false;
m_bPaused = false;
@@ -168,7 +168,7 @@ bool PAPlayer::OpenFile(const CFileItem& file, const CPlayerOptions &options)
*m_currentFile = file;
- if (ThreadHandle() == NULL)
+ if (!IsRunning())
Create();
m_startEvent.Set();
View
2 xbmc/dialogs/GUIDialogCache.cpp
@@ -29,7 +29,7 @@
#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);
View
4 xbmc/filesystem/FileCache.cpp
@@ -79,7 +79,7 @@ class CWriteRate
};
-CFileCache::CFileCache()
+CFileCache::CFileCache() : CThread("CFileCache")
{
m_bDeleteCache = true;
m_nSeekResult = 0;
@@ -95,7 +95,7 @@ CFileCache::CFileCache()
m_cacheFull = false;
}
-CFileCache::CFileCache(CCacheStrategy *pCache, bool bDeleteCache)
+CFileCache::CFileCache(CCacheStrategy *pCache, bool bDeleteCache) : CThread("CFileCache")
{
m_pCache = pCache;
m_bDeleteCache = bDeleteCache;
View
2 xbmc/filesystem/FilePipe.cpp
@@ -24,6 +24,8 @@
#include "PipesManager.h"
#include "utils/StringUtils.h"
+#define INFINITE 0xFFFFFFFF
+
using namespace XFILE;
CFilePipe::CFilePipe() : m_pos(0), m_length(-1), m_pipe(NULL)
View
2 xbmc/filesystem/FileRar.cpp
@@ -43,7 +43,7 @@ using namespace std;
#define SEEKTIMOUT 30000
#ifdef HAS_FILESYSTEM_RAR
-CFileRarExtractThread::CFileRarExtractThread() : hRunning(true), hQuit(true)
+CFileRarExtractThread::CFileRarExtractThread() : CThread("CFileRarExtractThread"), hRunning(true), hQuit(true)
{
m_pArc = NULL;
m_pCmd = NULL;
View
2 xbmc/filesystem/HTSPDirectory.cpp
@@ -76,7 +76,7 @@ static SSessions g_sessions;
static CCriticalSection g_section;
-CHTSPDirectorySession::CHTSPDirectorySession()
+CHTSPDirectorySession::CHTSPDirectorySession() : CThread("CHTSPDirectorySession")
{
}
View
2 xbmc/filesystem/LastFMDirectory.cpp
@@ -69,7 +69,7 @@ bool CLastFMDirectory::RetrieveList(CStdString url)
m_dlgProgress->Progress();
}
- CThread thread(this);
+ CThread thread(this, "CLastFMDirectory");
m_strSource = url;
m_strDestination = "special://temp/lastfm.xml";
thread.Create();
View
2 xbmc/filesystem/MythSession.cpp
@@ -359,7 +359,7 @@ void CMythSession::SetSeasonAndEpisode(const cmyth_proginfo_t &program, int *sea
return;
}
-CMythSession::CMythSession(const CURL& url)
+CMythSession::CMythSession(const CURL& url) : CThread("CMythSession")
{
m_control = NULL;
m_event = NULL;
View
2 xbmc/filesystem/PipesManager.cpp
@@ -23,6 +23,8 @@
#include "threads/SingleLock.h"
#include "Application.h"
+#define INFINITE 0xFFFFFFFF
+
#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))
#endif
View
2 xbmc/filesystem/RarManager.h
@@ -71,7 +71,7 @@ class CRarManager
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 = "");
View
4 xbmc/filesystem/SAPDirectory.cpp
@@ -272,7 +272,7 @@ namespace SDP
using namespace SDP;
-CSAPSessions::CSAPSessions()
+CSAPSessions::CSAPSessions() : CThread("CSAPSessions")
{
m_socket = INVALID_SOCKET;
}
@@ -486,7 +486,7 @@ namespace XFILE
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
View
4 xbmc/interfaces/python/XBPython.cpp
@@ -676,11 +676,11 @@ void XBPython::PulseGlobalEvent()
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();
}
View
2 xbmc/interfaces/python/XBPython.h
@@ -61,7 +61,7 @@ class XBPython : public IPlayerCallback
void Process();
void PulseGlobalEvent();
- void WaitForEvent(CEvent& hEvent, unsigned int timeout);
+ void WaitForEvent(CEvent& hEvent);
int ScriptsSize();
int GetPythonScriptId(int scriptPosition);
View
4 xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.cpp
@@ -181,9 +181,9 @@ void CGUIPythonWindow::SetCallbackWindow(void *state, void *object)
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();
}
View
2 xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.h
@@ -51,7 +51,7 @@ class CGUIPythonWindow : public CGUIWindow
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:
View
4 xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.cpp
@@ -279,9 +279,9 @@ void CGUIPythonWindowXML::ClearList()
UpdateButtons();
}
-void CGUIPythonWindowXML::WaitForActionEvent(unsigned int timeout)
+void CGUIPythonWindowXML::WaitForActionEvent()
{
- g_pythonParser.WaitForEvent(m_actionEvent, timeout);
+ g_pythonParser.WaitForEvent(m_actionEvent);
m_actionEvent.Reset();
}
View
2 xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.h
@@ -40,7 +40,7 @@ class CGUIPythonWindowXML : public CGUIMediaWindow
virtual void AllocResources(bool forceLoad = false);
virtual void FreeResources(bool forceUnLoad = false);
void Process(unsigned int currentTime, CDirtyRegionList &regions);
- void WaitForActionEvent(unsigned int timeout);
+ void WaitForActionEvent();
void PulseActionEvent();
void AddItem(CFileItemPtr fileItem,int itemPosition);
void RemoveItem(int itemPosition);
View
6 xbmc/interfaces/python/xbmcmodule/window.cpp
@@ -540,11 +540,11 @@ namespace PYXBMC
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);
View
3 xbmc/linux/Makefile.in
@@ -10,14 +10,11 @@ SRCS=ConvUtils.cpp \
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
View
2 xbmc/linux/PlatformDefs.h
@@ -182,8 +182,6 @@
#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;
View
3 xbmc/linux/PlatformInclude.h
@@ -25,10 +25,7 @@
#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"
View
144 xbmc/linux/XEventUtils.cpp
@@ -1,144 +0,0 @@
-/*
- * 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;
-}
-
View
18 xbmc/linux/XHandle.cpp
@@ -20,12 +20,15 @@
*/
#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();
@@ -47,11 +50,6 @@ CXHandle::CXHandle(const CXHandle &src)
Init();
- if (m_threadValid)
- {
- CLog::Log(LOGERROR, "%s - thread handle copied instead of passed!", __FUNCTION__);
- }
-
if (src.m_hMutex)
m_hMutex = new CCriticalSection();
@@ -80,7 +78,7 @@ CXHandle::~CXHandle()
CLog::Log(LOGERROR,"%s, destroying handle with ref count %d", __FUNCTION__, m_nRefCount);
assert(false);
}
-
+
if (m_hMutex) {
delete m_hMutex;
}
@@ -93,10 +91,6 @@ CXHandle::~CXHandle()
delete m_hCond;
}
- if (m_threadValid) {
- pthread_join(m_hThread, NULL);
- }
-
if ( fd != 0 ) {
close(fd);
}
@@ -107,11 +101,9 @@ void CXHandle::Init()
{
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 ;
View
6 xbmc/linux/XHandle.h
@@ -25,7 +25,6 @@
#ifndef _WIN32
#include <list>
-#include <pthread.h>
#include "PlatformDefs.h"
#include "XHandlePublic.h"
@@ -36,7 +35,7 @@
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);
@@ -47,8 +46,6 @@ struct CXHandle {
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;
@@ -62,7 +59,6 @@ struct CXHandle {
// 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;
View
130 xbmc/linux/XMemUtils.cpp
@@ -25,6 +25,10 @@
#include "XMemUtils.h"
+#ifdef __APPLE__
+#include <mach/mach.h>
+#endif
+
#undef ALIGN
#define ALIGN(value, alignment) (((value)+(alignment-1))&~(alignment-1))
@@ -49,4 +53,130 @@ void _aligned_free(void *p) {
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));
+
+#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->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
View
4 xbmc/linux/XMemUtils.h
@@ -22,10 +22,14 @@
*
*/
+#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
View
169 xbmc/linux/XSyncUtils.cpp
@@ -1,169 +0,0 @@
-/*
- * 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
- *
- */
-
-#ifndef _WIN32
-
-
-#include <semaphore.h>
-#include <time.h>
-#include <errno.h>
-#include <stack>
-#include <functional>
-#ifdef __APPLE__
-#include <mach/mach.h>
-#endif
-
-#include "XSyncUtils.h"
-#include "XTimeUtils.h"
-#include "PlatformDefs.h"
-#include "XHandle.h"
-#include "XEventUtils.h"
-
-using namespace std;
-using namespace XbmcThreads;
-
-#include "../utils/log.h"
-#include "../utils/TimeUtils.h"
-
-#if defined(_LINUX) && !defined(__APPLE__) && !defined(__FreeBSD__)
-static FILE* procMeminfoFP = NULL;
-#endif
-
-void GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)
-{
- if (!lpBuffer)
- return;
-
- memset(lpBuffer, 0, 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->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
View
210 xbmc/linux/XThreadUtils.cpp
@@ -1,210 +0,0 @@
-/*
- * 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
-
View
6 xbmc/music/LastFmManager.cpp
@@ -70,7 +70,7 @@ using namespace XFILE;
CLastFmManager* CLastFmManager::m_pInstance=NULL;
-CLastFmManager::CLastFmManager()
+CLastFmManager::CLastFmManager() : CThread("CLastFmManager")
{
m_RadioTrackQueue = new CPlayList;
}
@@ -534,7 +534,7 @@ void CLastFmManager::Update()
if (iNrCachedTracks == 0)
{
//get more tracks
- if (ThreadHandle() != NULL)
+ if (IsRunning())
{
m_hWorkerEvent.Set();
}
@@ -633,7 +633,7 @@ void CLastFmManager::StopRadio(bool bKillSession /*= true*/)
{
m_RadioSession = "";
}
- if (m_ThreadHandle)
+ if (IsRunning())
{
m_bStop = true;
m_hWorkerEvent.Set();
View
4 xbmc/music/infoscanner/MusicInfoScanner.cpp
@@ -57,7 +57,7 @@ using namespace MUSIC_INFO;
using namespace XFILE;
using namespace MUSIC_GRABBER;
-CMusicInfoScanner::CMusicInfoScanner()
+CMusicInfoScanner::CMusicInfoScanner() : CThread("CMusicInfoScanner")
{
m_bRunning = false;
m_pObserver = NULL;
@@ -99,7 +99,7 @@ void CMusicInfoScanner::Process()
// Create the thread to count all files to be scanned
SetPriority( GetMinPriority() );
- CThread fileCountReader(this);
+ CThread fileCountReader(this, "CMusicInfoScanner");
if (m_pObserver)
fileCountReader.Create();
View
2 xbmc/music/infoscanner/MusicInfoScraper.cpp
@@ -28,7 +28,7 @@ using namespace MUSIC_GRABBER;
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;
View
2 xbmc/network/AirPlayServer.cpp
@@ -184,7 +184,7 @@ void CAirPlayServer::StopServer(bool bWait)
}
}
-CAirPlayServer::CAirPlayServer(int port, bool nonlocal)
+CAirPlayServer::CAirPlayServer(int port, bool nonlocal) : CThread("AirPlayServer")
{
m_port = port;
m_nonlocal = nonlocal;
View
1 xbmc/network/Network.h
@@ -24,6 +24,7 @@
#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 };
View
2 xbmc/network/TCPServer.cpp
@@ -85,7 +85,7 @@ void CTCPServer::StopServer(bool bWait)
}
}
-CTCPServer::CTCPServer(int port, bool nonlocal)
+CTCPServer::CTCPServer(int port, bool nonlocal) : CThread("CTCPServer")
{
m_port = port;
m_nonlocal = nonlocal;
View
2 xbmc/network/UdpClient.cpp
@@ -35,7 +35,7 @@
#define UDPCLIENT_DEBUG_LEVEL LOGDEBUG
-CUdpClient::CUdpClient(void) : CThread()
+CUdpClient::CUdpClient(void) : CThread("CUdpClient")
{}
CUdpClient::~CUdpClient(void)
View
1 xbmc/network/UdpClient.h
@@ -25,6 +25,7 @@
#include "threads/CriticalSection.h"
#include <sys/socket.h>
#include <netinet/in.h>
+#include "system.h"
class CUdpClient : CThread
{
View
4 xbmc/network/libscrobbler/scrobbler.cpp
@@ -46,7 +46,7 @@
#define SCROBBLER_ACTION_NOWPLAYING 2
CScrobbler::CScrobbler(const CStdString &strHandshakeURL, const CStdString &strLogPrefix)
- : CThread()
+ : CThread("CScrobbler")
{
m_bBanned = false;
m_bBadAuth = false;
@@ -67,7 +67,7 @@ void CScrobbler::Init()
ResetState();
LoadCredentials();
LoadJournal();
- if (!ThreadHandle())
+ if (!IsRunning())
Create();
}
View
2 xbmc/pictures/GUIWindowSlideShow.cpp
@@ -67,7 +67,7 @@ using namespace XFILE;
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;
View
2 xbmc/rendering/dx/RenderSystemDX.cpp
@@ -569,7 +569,7 @@ bool CRenderSystemDX::PresentRenderImpl(const CDirtyRegionList &dirty)
//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());
View
447 xbmc/threads/Thread.cpp
@@ -20,41 +20,27 @@
#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;
@@ -66,12 +52,12 @@ CThread::CThread(const char* ThreadName) : m_StopEvent(true,true)
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;
@@ -85,171 +71,62 @@ CThread::CThread(IRunnable* pRunnable, const char* ThreadName) : m_StopEvent(tru
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 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);
+
+ pThread->m_ThreadId = 0;
+ pThread->m_TermEvent.Set();
+ pThread->TermHandler();
- if ( pThread->IsAutoDelete() )
+ 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());
-
-// DXMERGE - this looks like it might have used to have been useful for something...
-// g_graphicsContext.DeleteThreadContext();
+ CLog::Log(LOGDEBUG,"Thread %s %"PRIu64" terminating", name.c_str(), (uint64_t)id);
-#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;
@@ -259,213 +136,15 @@ void CThread::StopThread(bool bWait /*= true*/)