threads: remove WINAPI, implement priority for pthreads
authorFernetMenta <fernetmenta@online.de>
Sun, 31 Jul 2011 12:12:53 +0000 (14:12 +0200)
committerJim Carroll <thecarrolls@jiminger.com>
Sat, 21 Apr 2012 11:53:55 +0000 (07:53 -0400)
Also:
[fix] threads: fix race condition when stopping thread - cherry pick merge

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.
[cleanup] PAPlayer warning due to constructor initialization list order.

87 files changed:
lib/UnrarXLib/extract.cpp
lib/UnrarXLib/unpack.cpp
lib/UnrarXLib/unpack15.cpp
xbmc/ApplicationMessenger.cpp
xbmc/cdrip/CDDAReader.cpp
xbmc/cores/DllLoader/exports/emu_kernel32.cpp
xbmc/cores/DllLoader/exports/emu_kernel32.h
xbmc/cores/DummyVideoPlayer.cpp
xbmc/cores/dvdplayer/DVDCodecs/Video/CrystalHD.cpp
xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp
xbmc/cores/dvdplayer/DVDPerformanceCounter.h
xbmc/cores/dvdplayer/DVDPlayer.cpp
xbmc/cores/dvdplayer/DVDPlayerAudio.cpp
xbmc/cores/dvdplayer/DVDPlayerVideo.cpp
xbmc/cores/paplayer/PAPlayer.cpp
xbmc/dialogs/GUIDialogCache.cpp
xbmc/filesystem/FileCache.cpp
xbmc/filesystem/HTSPDirectory.cpp
xbmc/filesystem/LastFMDirectory.cpp
xbmc/filesystem/MythSession.cpp
xbmc/filesystem/PipeFile.cpp
xbmc/filesystem/PipesManager.cpp
xbmc/filesystem/PipesManager.h
xbmc/filesystem/RarFile.cpp
xbmc/filesystem/RarManager.h
xbmc/filesystem/SAPDirectory.cpp
xbmc/interfaces/python/XBPython.cpp
xbmc/interfaces/python/XBPython.h
xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.cpp
xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.h
xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.cpp
xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.h
xbmc/interfaces/python/xbmcmodule/window.cpp
xbmc/linux/Makefile.in
xbmc/linux/PlatformDefs.h
xbmc/linux/PlatformInclude.h
xbmc/linux/XEventUtils.cpp [deleted file]
xbmc/linux/XEventUtils.h [deleted file]
xbmc/linux/XHandle.cpp
xbmc/linux/XHandle.h
xbmc/linux/XMemUtils.cpp
xbmc/linux/XMemUtils.h
xbmc/linux/XSyncUtils.h [deleted file]
xbmc/linux/XThreadUtils.cpp [deleted file]
xbmc/linux/XThreadUtils.h [deleted file]
xbmc/music/LastFmManager.cpp
xbmc/music/infoscanner/MusicInfoScanner.cpp
xbmc/music/infoscanner/MusicInfoScraper.cpp
xbmc/network/AirPlayServer.cpp
xbmc/network/Network.h
xbmc/network/TCPServer.cpp
xbmc/network/UdpClient.cpp
xbmc/network/UdpClient.h
xbmc/network/libscrobbler/scrobbler.cpp
xbmc/peripherals/devices/PeripheralCecAdapter.cpp
xbmc/peripherals/devices/PeripheralCecAdapter.h
xbmc/pictures/GUIWindowSlideShow.cpp
xbmc/rendering/dx/RenderSystemDX.cpp
xbmc/threads/Thread.cpp
xbmc/threads/Thread.h
xbmc/threads/ThreadImpl.h [new file with mode: 0644]
xbmc/threads/platform/ThreadImpl.cpp [new file with mode: 0644]
xbmc/threads/platform/ThreadImpl.h [new file with mode: 0644]
xbmc/threads/platform/darwin/ThreadSchedImpl.cpp [new file with mode: 0644]
xbmc/threads/platform/linux/ThreadSchedImpl.cpp [new file with mode: 0644]
xbmc/threads/platform/pthreads/ThreadImpl.cpp [new file with mode: 0644]
xbmc/threads/platform/pthreads/ThreadImpl.h [new file with mode: 0644]
xbmc/threads/platform/win/ThreadImpl.cpp [new file with mode: 0644]
xbmc/threads/platform/win/ThreadImpl.h [new file with mode: 0644]
xbmc/utils/AlarmClock.cpp
xbmc/utils/AsyncFileCopy.cpp
xbmc/utils/DownloadQueue.cpp
xbmc/utils/DownloadQueue.h
xbmc/utils/DownloadQueueManager.h
xbmc/utils/JobManager.cpp
xbmc/utils/LCD.h
xbmc/utils/RssReader.cpp
xbmc/utils/RssReader.h
xbmc/utils/Splash.cpp
xbmc/utils/TuxBoxUtil.cpp
xbmc/video/VideoInfoDownloader.cpp
xbmc/video/VideoInfoDownloader.h
xbmc/video/VideoInfoScanner.cpp
xbmc/video/VideoReferenceClock.cpp
xbmc/win32/PlatformDefs.h
xbmc/win32/WindowHelper.cpp

index b4a8091..da60857 100644 (file)
@@ -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)
index 265b54f..bc2f220 100644 (file)
@@ -8,11 +8,6 @@
 #include "unpack20.cpp"
 #endif
 
-#ifdef _LINUX
-#include "XSyncUtils.h"
-#include "XEventUtils.h"
-#endif
-
 Unpack::Unpack(ComprDataIO *DataIO)
 {
   UnpIO=DataIO;
index e1b5f10..725e2be 100644 (file)
@@ -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};
index 54e6c98..1b7e097 100644 (file)
@@ -73,7 +73,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;
index 16fa7b6..6c242d8 100644 (file)
@@ -29,7 +29,7 @@
 
 #define SECTOR_COUNT 52
 
-CCDDAReader::CCDDAReader()
+CCDDAReader::CCDDAReader() : CThread("CCDDAReader")
 {
   m_sRipBuffer[0].pbtStream = NULL;
   m_sRipBuffer[1].pbtStream = NULL;
index 0493bb7..e0b863e 100644 (file)
@@ -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
index 2e637a7..9cc2f0b 100644 (file)
@@ -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();
index f0b4aeb..47d25e4 100644 (file)
@@ -33,7 +33,7 @@
 
 CDummyVideoPlayer::CDummyVideoPlayer(IPlayerCallback& callback)
     : IPlayer(callback),
-      CThread()
+      CThread("CDummyVideoPlayer")
 {
   m_paused = false;
   m_clock = 0;
index 2a6d958..d82e180 100644 (file)
@@ -325,7 +325,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),
index 17cbd48..13924cf 100644 (file)
@@ -19,7 +19,6 @@
  *
  */
 
-#include "threads/SystemClock.h"
 #include "system.h"
 #ifndef __STDC_CONSTANT_MACROS
 #define __STDC_CONSTANT_MACROS
@@ -45,6 +44,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)
@@ -155,16 +155,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* unused)
 {
-  if(g_demuxer && g_demuxer->Aborted())
+  CDVDDemuxFFmpeg* demuxer = g_demuxer.get();
+  if(demuxer && demuxer->Aborted())
     return 1;
   return 0;
 }
@@ -236,7 +232,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;
   const AVIOInterruptCB int_cb = { interrupt_cb, NULL };
 
@@ -500,7 +496,7 @@ bool CDVDDemuxFFmpeg::Open(CDVDInputStream* pInput)
 
 void CDVDDemuxFFmpeg::Dispose()
 {
-  g_demuxer = this;
+  g_demuxer.set(this);
 
   if (m_pFormatContext)
   {
@@ -541,7 +537,7 @@ void CDVDDemuxFFmpeg::Reset()
 
 void CDVDDemuxFFmpeg::Flush()
 {
-  g_demuxer = this;
+  g_demuxer.set(this);
 
   // naughty usage of an internal ffmpeg function
   if (m_pFormatContext)
@@ -557,7 +553,7 @@ void CDVDDemuxFFmpeg::Abort()
 
 void CDVDDemuxFFmpeg::SetSpeed(int iSpeed)
 {
-  g_demuxer = this;
+  g_demuxer.set(this);
 
   if(!m_pFormatContext)
     return;
@@ -619,7 +615,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;
@@ -811,7 +807,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;
@@ -871,7 +867,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);
index 23c5e3e..129674a 100644 (file)
@@ -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);
index 2f0b5ac..e97a14c 100644 (file)
@@ -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 @@ public:
   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;
index a9c7dca..4b691fe 100644 (file)
@@ -341,7 +341,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;
@@ -433,8 +433,7 @@ void CDVDPlayer::OnStartup()
 
   m_messenger.Init();
 
-  g_dvdPerformanceCounter.EnableMainPerformance(ThreadHandle());
-
+  g_dvdPerformanceCounter.EnableMainPerformance(this);
   CUtil::ClearTempFonts();
 }
 
@@ -2726,7 +2725,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;
 }
@@ -2794,11 +2793,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;
 
index 41fbaaf..9f2128c 100644 (file)
@@ -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);
index 64f08df..1ebfdbc 100644 (file)
@@ -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()
index 43b57d3..9a8b63f 100644 (file)
@@ -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) : IPlayer(callback), CThread("PAPlayer")
 {
   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();
index 1114cc6..85548e4 100644 (file)
@@ -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);
 
index 9e94ce5..0e3fa3a 100644 (file)
@@ -79,7 +79,7 @@ private:
 };
 
 
-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;
index 83a1fca..152754d 100644 (file)
@@ -76,7 +76,7 @@ static SSessions         g_sessions;
 static CCriticalSection  g_section;
 
 
-CHTSPDirectorySession::CHTSPDirectorySession()
+CHTSPDirectorySession::CHTSPDirectorySession() : CThread("CHTSPDirectorySession")
 {
 }
 
index 2b81346..aecfe0f 100644 (file)
@@ -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();
index 6e29b00..73ef639 100644 (file)
@@ -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;
index 7fb39ab..8bc52af 100644 (file)
@@ -82,7 +82,7 @@ unsigned int CPipeFile::Read(void* lpBuf, int64_t uiBufSize)
   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)
@@ -90,7 +90,7 @@ 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()
index 73f4aa2..771d18b 100644 (file)
@@ -186,7 +186,7 @@ bool Pipe::Write(const char *buf, int nSize, int nWaitMillis)
       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)
       {
@@ -194,8 +194,9 @@ bool Pipe::Write(const char *buf, int nSize, int nWaitMillis)
         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;
     }
   }
index 5e34a4a..f224da0 100644 (file)
@@ -57,8 +57,24 @@ class Pipe
     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();
     
index 3fca340..408ddef 100644 (file)
@@ -43,7 +43,7 @@ using namespace std;
 #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;
index dd4b2f0..6f93f79 100644 (file)
@@ -71,7 +71,7 @@ public:
   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 = "");
index d8931b8..b997c12 100644 (file)
@@ -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
index ffe37f0..2a1d9fb 100644 (file)
@@ -780,11 +780,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();
 }
 
index 5abe6fb..28672d3 100644 (file)
@@ -73,7 +73,7 @@ public:
   void Process();
 
   void PulseGlobalEvent();
-  void WaitForEvent(CEvent& hEvent, unsigned int timeout);
+  void WaitForEvent(CEvent& hEvent);
 
   int ScriptsSize();
   int GetPythonScriptId(int scriptPosition);
index 4ec7e23..d44fc23 100644 (file)
@@ -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();
 }
 
index c776187..09c0d42 100644 (file)
@@ -51,7 +51,7 @@ public:
   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:
index 2db79f1..9644351 100644 (file)
@@ -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();
 }
 
index 27bc3a2..340be8b 100644 (file)
@@ -40,7 +40,7 @@ public:
   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);
index 9788686..69780c4 100644 (file)
@@ -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);
index c3a5877..43f552b 100644 (file)
@@ -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
 
index d04830c..dabc680 100644 (file)
 #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;
 
index 1f7e7e9..4e44ed8 100644 (file)
 #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"
 
diff --git a/xbmc/linux/XEventUtils.cpp b/xbmc/linux/XEventUtils.cpp
deleted file mode 100644 (file)
index 639b7b9..0000000
+++ /dev/null
@@ -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;
-}
-
diff --git a/xbmc/linux/XEventUtils.h b/xbmc/linux/XEventUtils.h
deleted file mode 100644 (file)
index a77f843..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-#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
-
index 61520b2..52f540a 100644 (file)
  */
 
 #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 ;
index 0e119bc..dd7f37d 100644 (file)
@@ -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 @@ public:
   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 @@ public:
   // 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;
index 906fe4e..fd466bb 100644 (file)
 
 #include "XMemUtils.h"
 
+#ifdef __APPLE__
+#include <mach/mach.h>
+#endif
+
 #undef ALIGN
 #define ALIGN(value, alignment) (((value)+(alignment-1))&~(alignment-1))
 
@@ -49,4 +53,132 @@ 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));
+  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
 
index d6d314a..83fc95d 100644 (file)
  *
  */
 
+#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
 
diff --git a/xbmc/linux/XSyncUtils.h b/xbmc/linux/XSyncUtils.h
deleted file mode 100644 (file)
index f3ad36f..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-#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
-
diff --git a/xbmc/linux/XThreadUtils.cpp b/xbmc/linux/XThreadUtils.cpp
deleted file mode 100644 (file)
index 9d68481..0000000
+++ /dev/null
@@ -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
-
diff --git a/xbmc/linux/XThreadUtils.h b/xbmc/linux/XThreadUtils.h
deleted file mode 100644 (file)
index fe8fafb..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-#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
index f3054e9..e596cf8 100644 (file)
@@ -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();
index 90c60ab..d2b7248 100644 (file)
@@ -58,7 +58,7 @@ using namespace MUSIC_INFO;
 using namespace XFILE;
 using namespace MUSIC_GRABBER;
 
-CMusicInfoScanner::CMusicInfoScanner()
+CMusicInfoScanner::CMusicInfoScanner() : CThread("CMusicInfoScanner")
 {
   m_bRunning = false;
   m_pObserver = NULL;
@@ -100,7 +100,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();
 
index dc9c883..9564e21 100644 (file)
@@ -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;
index ea8bb24..3be2a37 100644 (file)
@@ -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;
index cb0ea52..e514e05 100644 (file)
@@ -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 };
index 3094583..e061ce1 100644 (file)
@@ -86,7 +86,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;
index 8e1ef2e..8f49ce8 100644 (file)
@@ -35,7 +35,7 @@
 
 #define UDPCLIENT_DEBUG_LEVEL LOGDEBUG
 
-CUdpClient::CUdpClient(void) : CThread()
+CUdpClient::CUdpClient(void) : CThread("CUdpClient")
 {}
 
 CUdpClient::~CUdpClient(void)
index 97acb28..a1aa597 100644 (file)
@@ -25,6 +25,7 @@
 #include "threads/CriticalSection.h"
 #include <sys/socket.h>
 #include <netinet/in.h>
+#include "system.h"
 
 class CUdpClient : CThread
 {
index 4daad0b..10c2c9d 100644 (file)
@@ -48,7 +48,7 @@
 #define SCROBBLER_ACTION_NOWPLAYING   2
 
 CScrobbler::CScrobbler(const CStdString &strHandshakeURL, const CStdString &strLogPrefix)
-  : CThread()
+  : CThread("CScrobbler")
 { 
   m_bBanned         = false;
   m_bBadAuth        = false;
@@ -69,7 +69,7 @@ void CScrobbler::Init()
   ResetState();
   LoadCredentials();
   LoadJournal();
-  if (!ThreadHandle())
+  if (!IsRunning())
     Create();
 }
 
index a898a16..6a6bc89 100644 (file)
@@ -671,7 +671,7 @@ bool CPeripheralCecAdapter::GetNextKey(void)
     return bHasButton;
 
   CLog::Log(LOGDEBUG, "%s - received key %2x", __FUNCTION__, key.keycode);
-  WORD iButton = 0;
+  int iButton = 0;
   bHasButton = true;
 
   switch (key.keycode)
@@ -860,7 +860,7 @@ bool CPeripheralCecAdapter::GetNextKey(void)
   return m_bHasButton;
 }
 
-WORD CPeripheralCecAdapter::GetButton(void)
+int CPeripheralCecAdapter::GetButton(void)
 {
   CSingleLock lock(m_critSection);
   if (!m_bHasButton)
index 2ad8772..33206e1 100644 (file)
@@ -35,7 +35,7 @@ namespace PERIPHERALS
     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) {}
   };
@@ -68,7 +68,7 @@ namespace PERIPHERALS
 
   typedef struct
   {
-    WORD         iButton;
+    int         iButton;
     unsigned int iDuration;
   } CecButtonPress;
 
@@ -101,7 +101,7 @@ namespace PERIPHERALS
 
     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);
index a01f3d8..a325c63 100644 (file)
@@ -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;
index 938cb36..ed92a41 100644 (file)
@@ -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());
index 9b38643..becc594 100644 (file)
 
 #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,181 +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 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;
@@ -269,213 +136,15 @@ void CThread::StopThread(bool bWait /*= true*/)
 {
   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, &param );
-  // change from default SCHED_OTHER to SCHED_RR
-  policy = SCHED_RR;
-  result = pthread_setschedparam(ThreadId(), policy, &param );
-#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()
@@ -484,54 +153,14 @@ 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)
@@ -539,7 +168,7 @@ void CThread::Sleep(unsigned int milliseconds)
   if(milliseconds > 10 && IsCurrentThread())
     m_StopEvent.WaitMSec(milliseconds);
   else
-    ::Sleep(milliseconds);
+    XbmcThreads::ThreadSleep(milliseconds);
 }
 
 
index 768d6f8..bebd9ee 100644 (file)
 //
 //////////////////////////////////////////////////////////////////////
 
-#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
 {
@@ -44,37 +38,36 @@ public:
   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(){};
@@ -82,7 +75,6 @@ protected:
   virtual void Process();
 
   volatile bool m_bStop;
-  HANDLE m_ThreadHandle;
 
   enum WaitResponse { WAIT_INTERRUPTED = -1, WAIT_SIGNALED = 0, WAIT_TIMEDOUT = 1 };
 
@@ -108,36 +100,22 @@ protected:
   }
 
 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_)
diff --git a/xbmc/threads/ThreadImpl.h b/xbmc/threads/ThreadImpl.h
new file mode 100644 (file)
index 0000000..ad10e3b
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ *      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"
+
diff --git a/xbmc/threads/platform/ThreadImpl.cpp b/xbmc/threads/platform/ThreadImpl.cpp
new file mode 100644 (file)
index 0000000..7f0213b
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ *      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
+
diff --git a/xbmc/threads/platform/ThreadImpl.h b/xbmc/threads/platform/ThreadImpl.h
new file mode 100644 (file)
index 0000000..f37709e
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ *      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
diff --git a/xbmc/threads/platform/darwin/ThreadSchedImpl.cpp b/xbmc/threads/platform/darwin/ThreadSchedImpl.cpp
new file mode 100644 (file)
index 0000000..7612fe7
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ *      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, &param );
+  // change from default SCHED_OTHER to SCHED_RR
+  policy = SCHED_RR;
+  result = pthread_setschedparam(ThreadId(), policy, &param );
+}
diff --git a/xbmc/threads/platform/linux/ThreadSchedImpl.cpp b/xbmc/threads/platform/linux/ThreadSchedImpl.cpp
new file mode 100644 (file)
index 0000000..034a100
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ *      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;
+}
diff --git a/xbmc/threads/platform/pthreads/ThreadImpl.cpp b/xbmc/threads/platform/pthreads/ThreadImpl.cpp
new file mode 100644 (file)
index 0000000..58b602c
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ *      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;
+}
+
diff --git a/xbmc/threads/platform/pthreads/ThreadImpl.h b/xbmc/threads/platform/pthreads/ThreadImpl.h
new file mode 100644 (file)
index 0000000..3f4dd39
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+* 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); }
+}
+
diff --git a/xbmc/threads/platform/win/ThreadImpl.cpp b/xbmc/threads/platform/win/ThreadImpl.cpp
new file mode 100644 (file)
index 0000000..6650ee6
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+ *      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;
+}
+
diff --git a/xbmc/threads/platform/win/ThreadImpl.h b/xbmc/threads/platform/win/ThreadImpl.h
new file mode 100644 (file)
index 0000000..ea9a0db
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+* 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); }
+}
+
index 09c9619..6ca327f 100644 (file)
@@ -28,7 +28,7 @@
 
 using namespace std;
 
-CAlarmClock::CAlarmClock() : m_bIsRunning(false)
+CAlarmClock::CAlarmClock() : CThread("CAlarmClock"), m_bIsRunning(false)
 {
 }
 
index e9b7bc0..44e7043 100644 (file)
@@ -26,7 +26,7 @@
 #include "log.h"
 #include "utils/TimeUtils.h"
 
-CAsyncFileCopy::CAsyncFileCopy()
+CAsyncFileCopy::CAsyncFileCopy() : CThread("CAsyncFileCopy")
 {
   m_cancelled = false;
   m_succeeded = false;
index 56dd751..544b173 100644 (file)
@@ -32,7 +32,7 @@ using namespace XFILE;
 
 WORD CDownloadQueue::m_wNextQueueId = 0;
 
-CDownloadQueue::CDownloadQueue(void) : CThread()
+CDownloadQueue::CDownloadQueue(void) : CThread("CDownloadQueue")
 {
   m_bStop = false;
   m_wQueueId = m_wNextQueueId++;
index c314792..543a825 100644 (file)
@@ -26,6 +26,8 @@
 #include "threads/CriticalSection.h"
 #include "StdString.h"
 
+#include "system.h"
+
 struct TICKET
 {
   TICKET(WORD aQueueId, DWORD aItemId)
index 3fb0d9f..9bda3ea 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include "DownloadQueue.h"
+#include "system.h"
 
 #define MAX_DOWNLOAD_QUEUES  3
 
index a7559b7..94aeb74 100644 (file)
@@ -24,6 +24,9 @@
 #include "threads/SingleLock.h"
 #include "utils/log.h"
 
+#include "system.h"
+
+
 using namespace std;
 
 bool CJob::ShouldCancel(unsigned int progress, unsigned int total) const
index b60bcf2..888e5ac 100644 (file)
@@ -68,8 +68,9 @@ public:
   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);
index 808a8fb..41f468e 100644 (file)
@@ -44,7 +44,7 @@ using namespace XFILE;
 // Construction/Destruction
 //////////////////////////////////////////////////////////////////////
 
-CRssReader::CRssReader() : CThread()
+CRssReader::CRssReader() : CThread("CRssReader")
 {
   m_pObserver = NULL;
   m_spacesBetweenFeeds = 0;
index f94e2be..d202b37 100644 (file)
@@ -39,6 +39,9 @@
 
 #include "tinyXML/tinyxml.h"
 
+#include "system.h"
+
+
 #define RSS_COLOR_BODY  0
 #define RSS_COLOR_HEADLINE 1
 #define RSS_COLOR_CHANNEL 2
index 58093b0..a53c90e 100644 (file)
@@ -31,7 +31,7 @@
 
 using namespace XFILE;
 
-CSplash::CSplash(const CStdString& imageName)
+CSplash::CSplash(const CStdString& imageName) : CThread("CSplash")
 {
   m_ImageName = imageName;
   fade = 0.5;
@@ -139,5 +139,5 @@ void CSplash::Stop()
 
 bool CSplash::IsRunning()
 {
-  return (m_ThreadHandle != NULL);
+  return (IsRunning());
 }
index c9fcaf1..38b4895 100644 (file)
@@ -48,7 +48,7 @@ using namespace std;
 CTuxBoxUtil g_tuxbox;
 CTuxBoxService g_tuxboxService;
 
-CTuxBoxService::CTuxBoxService()
+CTuxBoxService::CTuxBoxService() : CThread("CTuxBoxService")
 {
 }
 CTuxBoxService::~CTuxBoxService()
index 3185d2b..5a46034 100644 (file)
@@ -116,7 +116,7 @@ int CVideoInfoDownloader::FindMovie(const CStdString &strMovie,
     m_state = FIND_MOVIE;
     m_strMovie = strMovie;
     m_found = 0;
-    if (ThreadHandle())
+    if (IsRunning())
       StopThread();
     Create();
     while (m_state != DO_NOTHING)
@@ -160,7 +160,7 @@ bool CVideoInfoDownloader::GetDetails(const CScraperUrl &url,
   { // threaded version
     m_state = GET_DETAILS;
     m_found = 0;
-    if (ThreadHandle())
+    if (IsRunning())
       StopThread();
     Create();
     while (!m_found)
@@ -195,7 +195,7 @@ bool CVideoInfoDownloader::GetEpisodeDetails(const CScraperUrl &url,
   { // threaded version
     m_state = GET_EPISODE_DETAILS;
     m_found = 0;
-    if (ThreadHandle())
+    if (IsRunning())
       StopThread();
     Create();
     while (!m_found)
@@ -230,7 +230,7 @@ bool CVideoInfoDownloader::GetEpisodeList(const CScraperUrl& url,
   { // threaded version
     m_state = GET_EPISODE_LIST;
     m_found = 0;
-    if (ThreadHandle())
+    if (IsRunning())
       StopThread();
     Create();
     while (!m_found)
index b9ce9fd..63d5276 100644 (file)
@@ -42,7 +42,7 @@ typedef std::vector<CScraperUrl> MOVIELIST;
 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
index 45c0991..35a0e5c 100644 (file)
@@ -54,7 +54,7 @@ using namespace ADDON;
 namespace VIDEO
 {
 
-  CVideoInfoScanner::CVideoInfoScanner()
+  CVideoInfoScanner::CVideoInfoScanner() : CThread("CVideoInfoScanner")
   {
     m_bRunning = false;
     m_pObserver = NULL;
index bec6e14..015d84e 100644 (file)
@@ -107,7 +107,7 @@ using namespace std;
 
 #endif
 
-CVideoReferenceClock::CVideoReferenceClock()
+CVideoReferenceClock::CVideoReferenceClock() : CThread("CVideoReferenceClock")
 {
   m_SystemFrequency = CurrentHostFrequency();
   m_ClockSpeed = 1.0;
index 57cab8f..74e3d53 100644 (file)
@@ -33,7 +33,6 @@ typedef __int64       off64_t;
 typedef __int64       fpos64_t;
 typedef __int64       __off64_t;
 typedef long          __off_t;
-typedef unsigned long ThreadIdentifier;
 
 #define ssize_t int
 
index 56856ac..8aa7da9 100644 (file)
@@ -28,7 +28,7 @@ using namespace std;
 
 CWHelper g_windowHelper;
 
-CWHelper::CWHelper(void)
+CWHelper::CWHelper(void) : CThread("CWHelper")
 {
   m_hwnd = NULL;
   m_hProcess = NULL;