Skip to content
This repository
Browse code

threads: remove WINAPI, implement priority for pthreads

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

Also, from jimfcarroll:
[fixed] AirPlayServer now complies with the new CThread constructor requirements (that is, you must supply a thread name).
replace custom thread local storage with the XbmcThreads::ThreadLocal template.
[cosmetic] removed incorrect hungarian notation.
[cleanup] Removed XSyncUtils. Moved the GlobalMemoryStatus call to XMemUtil. Cleaned up code that used the #define INFINITE from XSyncUtils.h
[cleanup] Some miscellaneous cleanup. Fixed initialization warning in LCD. Removed some unused functions and members.
  • Loading branch information...
commit 80f05515c2b3976c7e101fc766d3298c67c3d8e1 1 parent 7ed3a94
Rainer Hochecker authored

Showing 82 changed files with 939 additions and 1,161 deletions. Show diff stats Hide diff stats

  1. +0 4 lib/UnrarXLib/extract.cpp
  2. +0 5 lib/UnrarXLib/unpack.cpp
  3. +0 4 lib/UnrarXLib/unpack15.cpp
  4. +1 1  xbmc/ApplicationMessenger.cpp
  5. +1 1  xbmc/cdrip/CDDAReader.cpp
  6. +0 9 xbmc/cores/DllLoader/exports/emu_kernel32.cpp
  7. +0 1  xbmc/cores/DllLoader/exports/emu_kernel32.h
  8. +1 1  xbmc/cores/DummyVideoPlayer.cpp
  9. +1 1  xbmc/cores/dvdplayer/DVDCodecs/Video/CrystalHD.cpp
  10. +11 15 xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
  11. +4 9 xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp
  12. +12 12 xbmc/cores/dvdplayer/DVDPerformanceCounter.h
  13. +5 6 xbmc/cores/dvdplayer/DVDPlayer.cpp
  14. +1 1  xbmc/cores/dvdplayer/DVDPlayerAudio.cpp
  15. +2 2 xbmc/cores/dvdplayer/DVDPlayerVideo.cpp
  16. +2 2 xbmc/cores/paplayer/PAPlayer.cpp
  17. +1 1  xbmc/dialogs/GUIDialogCache.cpp
  18. +2 2 xbmc/filesystem/FileCache.cpp
  19. +2 0  xbmc/filesystem/FilePipe.cpp
  20. +1 1  xbmc/filesystem/FileRar.cpp
  21. +1 1  xbmc/filesystem/HTSPDirectory.cpp
  22. +1 1  xbmc/filesystem/LastFMDirectory.cpp
  23. +1 1  xbmc/filesystem/MythSession.cpp
  24. +2 0  xbmc/filesystem/PipesManager.cpp
  25. +1 1  xbmc/filesystem/RarManager.h
  26. +2 2 xbmc/filesystem/SAPDirectory.cpp
  27. +2 2 xbmc/interfaces/python/XBPython.cpp
  28. +1 1  xbmc/interfaces/python/XBPython.h
  29. +2 2 xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.cpp
  30. +1 1  xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.h
  31. +2 2 xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.cpp
  32. +1 1  xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.h
  33. +3 3 xbmc/interfaces/python/xbmcmodule/window.cpp
  34. +0 3  xbmc/linux/Makefile.in
  35. +0 2  xbmc/linux/PlatformDefs.h
  36. +0 3  xbmc/linux/PlatformInclude.h
  37. +0 144 xbmc/linux/XEventUtils.cpp
  38. +5 13 xbmc/linux/XHandle.cpp
  39. +1 5 xbmc/linux/XHandle.h
  40. +130 0 xbmc/linux/XMemUtils.cpp
  41. +4 0 xbmc/linux/XMemUtils.h
  42. +0 169 xbmc/linux/XSyncUtils.cpp
  43. +0 210 xbmc/linux/XThreadUtils.cpp
  44. +3 3 xbmc/music/LastFmManager.cpp
  45. +2 2 xbmc/music/infoscanner/MusicInfoScanner.cpp
  46. +1 1  xbmc/music/infoscanner/MusicInfoScraper.cpp
  47. +1 1  xbmc/network/AirPlayServer.cpp
  48. +1 0  xbmc/network/Network.h
  49. +1 1  xbmc/network/TCPServer.cpp
  50. +1 1  xbmc/network/UdpClient.cpp
  51. +1 0  xbmc/network/UdpClient.h
  52. +2 2 xbmc/network/libscrobbler/scrobbler.cpp
  53. +1 1  xbmc/pictures/GUIWindowSlideShow.cpp
  54. +1 1  xbmc/rendering/dx/RenderSystemDX.cpp
  55. +43 404 xbmc/threads/Thread.cpp
  56. +23 45 xbmc/threads/Thread.h
  57. +25 0 xbmc/threads/ThreadImpl.h
  58. +10 14 xbmc/{linux/XEventUtils.h → threads/platform/ThreadImpl.cpp}
  59. +6 22 xbmc/{linux/XSyncUtils.h → threads/platform/ThreadImpl.h}
  60. +47 0 xbmc/threads/platform/darwin/ThreadSchedImpl.cpp
  61. +30 0 xbmc/threads/platform/linux/ThreadSchedImpl.cpp
  62. +220 0 xbmc/threads/platform/pthreads/ThreadImpl.cpp
  63. +39 0 xbmc/threads/platform/pthreads/ThreadImpl.h
  64. +207 0 xbmc/threads/platform/win/ThreadImpl.cpp
  65. +40 0 xbmc/threads/platform/win/ThreadImpl.h
  66. +1 1  xbmc/utils/AlarmClock.cpp
  67. +1 1  xbmc/utils/AsyncFileCopy.cpp
  68. +1 1  xbmc/utils/DownloadQueue.cpp
  69. +2 0  xbmc/utils/DownloadQueue.h
  70. +1 0  xbmc/utils/DownloadQueueManager.h
  71. +3 0  xbmc/utils/JobManager.cpp
  72. +3 2 xbmc/utils/LCD.h
  73. +1 1  xbmc/utils/RssReader.cpp
  74. +3 0  xbmc/utils/RssReader.h
  75. +2 2 xbmc/utils/Splash.cpp
  76. +1 1  xbmc/utils/TuxBoxUtil.cpp
  77. +4 4 xbmc/video/VideoInfoDownloader.cpp
  78. +1 1  xbmc/video/VideoInfoDownloader.h
  79. +1 1  xbmc/video/VideoInfoScanner.cpp
  80. +1 1  xbmc/video/VideoReferenceClock.cpp
  81. +0 1  xbmc/win32/PlatformDefs.h
  82. +1 1  xbmc/win32/WindowHelper.cpp
4 lib/UnrarXLib/extract.cpp
... ... @@ -1,9 +1,5 @@
1 1 #include "rar.hpp"
2 2 #include "Util.h"
3   -#ifdef _LINUX
4   -#include "XSyncUtils.h"
5   -#include "XEventUtils.h"
6   -#endif
7 3
8 4 // a cautious wrapper around strncpy
9 5 char *strncpy_null_terminated(char *dest, const char *src, size_t n)
5 lib/UnrarXLib/unpack.cpp
@@ -8,11 +8,6 @@
8 8 #include "unpack20.cpp"
9 9 #endif
10 10
11   -#ifdef _LINUX
12   -#include "XSyncUtils.h"
13   -#include "XEventUtils.h"
14   -#endif
15   -
16 11 Unpack::Unpack(ComprDataIO *DataIO)
17 12 {
18 13 UnpIO=DataIO;
4 lib/UnrarXLib/unpack15.cpp
... ... @@ -1,7 +1,3 @@
1   -#ifdef _LINUX
2   -#include "XSyncUtils.h"
3   -#endif
4   -
5 1 #define STARTL1 2
6 2 static unsigned int DecL1[]={0x8000,0xa000,0xc000,0xd000,0xe000,0xea00,
7 3 0xee00,0xf000,0xf200,0xf200,0xffff};
2  xbmc/ApplicationMessenger.cpp
@@ -75,7 +75,7 @@
75 75
76 76 using namespace std;
77 77
78   -CDelayedMessage::CDelayedMessage(ThreadMessage& msg, unsigned int delay)
  78 +CDelayedMessage::CDelayedMessage(ThreadMessage& msg, unsigned int delay) : CThread("CDelayedMessage")
79 79 {
80 80 m_msg.dwMessage = msg.dwMessage;
81 81 m_msg.dwParam1 = msg.dwParam1;
2  xbmc/cdrip/CDDAReader.cpp
@@ -29,7 +29,7 @@
29 29
30 30 #define SECTOR_COUNT 52
31 31
32   -CCDDAReader::CCDDAReader()
  32 +CCDDAReader::CCDDAReader() : CThread("CCDDAReader")
33 33 {
34 34 m_sRipBuffer[0].pbtStream = NULL;
35 35 m_sRipBuffer[1].pbtStream = NULL;
9 xbmc/cores/DllLoader/exports/emu_kernel32.cpp
@@ -240,15 +240,6 @@ extern "C" DWORD WINAPI dllGetCurrentProcessId(void)
240 240 #endif
241 241 }
242 242
243   -extern "C" BOOL WINAPI dllGetProcessTimes(HANDLE hProcess, LPFILETIME lpCreationTime, LPFILETIME lpExitTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime)
244   -{
245   - // since the xbox has only one process, we just take the current thread
246   - HANDLE h = GetCurrentThread();
247   - BOOL res = GetThreadTimes(h, lpCreationTime, lpExitTime, lpKernelTime, lpUserTime);
248   -
249   - return res;
250   -}
251   -
252 243 extern "C" int WINAPI dllDuplicateHandle(HANDLE hSourceProcessHandle, // handle to source process
253 244 HANDLE hSourceHandle, // handle to duplicate
254 245 HANDLE hTargetProcessHandle, // handle to target process
1  xbmc/cores/DllLoader/exports/emu_kernel32.h
@@ -686,7 +686,6 @@ extern "C" BOOL WINAPI dllGetProcessAffinityMask(HANDLE hProcess, LPDWORD lpProc
686 686
687 687 extern "C" HGLOBAL WINAPI dllLoadResource(HMODULE module, HRSRC res);
688 688 extern "C" HRSRC WINAPI dllFindResourceA(HMODULE module, LPCTSTR name, LPCTSTR type);
689   -extern "C" BOOL WINAPI dllGetProcessTimes(HANDLE hProcess, LPFILETIME lpCreationTime, LPFILETIME lpExitTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime);
690 689 extern "C" int WINAPI dllGetLocaleInfoA(LCID Locale, LCTYPE LCType, LPTSTR lpLCData, int cchData);
691 690 extern "C" UINT WINAPI dllGetConsoleCP();
692 691 extern "C" UINT WINAPI dllGetConsoleOutputCP();
2  xbmc/cores/DummyVideoPlayer.cpp
@@ -33,7 +33,7 @@
33 33
34 34 CDummyVideoPlayer::CDummyVideoPlayer(IPlayerCallback& callback)
35 35 : IPlayer(callback),
36   - CThread()
  36 + CThread("CDummyVideoPlayer")
37 37 {
38 38 m_paused = false;
39 39 m_clock = 0;
2  xbmc/cores/dvdplayer/DVDCodecs/Video/CrystalHD.cpp
@@ -323,7 +323,7 @@ CPictureBuffer::~CPictureBuffer()
323 323 #pragma mark -
324 324 #endif
325 325 CMPCOutputThread::CMPCOutputThread(void *device, DllLibCrystalHD *dll, bool has_bcm70015) :
326   - CThread(),
  326 + CThread("CMPCOutputThread"),
327 327 m_dll(dll),
328 328 m_device(device),
329 329 m_has_bcm70015(has_bcm70015),
26 xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
@@ -19,7 +19,6 @@
19 19 *
20 20 */
21 21
22   -#include "threads/SystemClock.h"
23 22 #include "system.h"
24 23 #ifndef __STDC_CONSTANT_MACROS
25 24 #define __STDC_CONSTANT_MACROS
@@ -44,6 +43,7 @@
44 43 #include "filesystem/Directory.h"
45 44 #include "utils/log.h"
46 45 #include "threads/Thread.h"
  46 +#include "threads/SystemClock.h"
47 47 #include "utils/TimeUtils.h"
48 48
49 49 void CDemuxStreamAudioFFmpeg::GetStreamInfo(std::string& strInfo)
@@ -154,16 +154,12 @@ static void ff_flush_avutil_log_buffers(void)
154 154 ++it;
155 155 }
156 156
157   -#ifdef _MSC_VER
158   -static __declspec(thread) CDVDDemuxFFmpeg* g_demuxer = 0;
159   -#else
160   -static TLS g_tls;
161   -#define g_demuxer (*((CDVDDemuxFFmpeg**)g_tls.Get()))
162   -#endif
  157 +static XbmcThreads::ThreadLocal<CDVDDemuxFFmpeg> g_demuxer;
163 158
164 159 static int interrupt_cb(void)
165 160 {
166   - if(g_demuxer && g_demuxer->Aborted())
  161 + CDVDDemuxFFmpeg* demuxer = g_demuxer.get();
  162 + if(demuxer && demuxer->Aborted())
167 163 return 1;
168 164 return 0;
169 165 }
@@ -235,7 +231,7 @@ bool CDVDDemuxFFmpeg::Open(CDVDInputStream* pInput)
235 231 std::string strFile;
236 232 m_iCurrentPts = DVD_NOPTS_VALUE;
237 233 m_speed = DVD_PLAYSPEED_NORMAL;
238   - g_demuxer = this;
  234 + g_demuxer.set(this);
239 235 m_program = UINT_MAX;
240 236
241 237 if (!pInput) return false;
@@ -507,7 +503,7 @@ bool CDVDDemuxFFmpeg::Open(CDVDInputStream* pInput)
507 503
508 504 void CDVDDemuxFFmpeg::Dispose()
509 505 {
510   - g_demuxer = this;
  506 + g_demuxer.set(this);
511 507
512 508 if (m_pFormatContext)
513 509 {
@@ -556,7 +552,7 @@ void CDVDDemuxFFmpeg::Reset()
556 552
557 553 void CDVDDemuxFFmpeg::Flush()
558 554 {
559   - g_demuxer = this;
  555 + g_demuxer.set(this);
560 556
561 557 // naughty usage of an internal ffmpeg function
562 558 if (m_pFormatContext)
@@ -572,7 +568,7 @@ void CDVDDemuxFFmpeg::Abort()
572 568
573 569 void CDVDDemuxFFmpeg::SetSpeed(int iSpeed)
574 570 {
575   - g_demuxer = this;
  571 + g_demuxer.set(this);
576 572
577 573 if(!m_pFormatContext)
578 574 return;
@@ -634,7 +630,7 @@ double CDVDDemuxFFmpeg::ConvertTimestamp(int64_t pts, int den, int num)
634 630
635 631 DemuxPacket* CDVDDemuxFFmpeg::Read()
636 632 {
637   - g_demuxer = this;
  633 + g_demuxer.set(this);
638 634
639 635 AVPacket pkt;
640 636 DemuxPacket* pPacket = NULL;
@@ -833,7 +829,7 @@ DemuxPacket* CDVDDemuxFFmpeg::Read()
833 829
834 830 bool CDVDDemuxFFmpeg::SeekTime(int time, bool backwords, double *startpts)
835 831 {
836   - g_demuxer = this;
  832 + g_demuxer.set(this);
837 833
838 834 if(time < 0)
839 835 time = 0;
@@ -893,7 +889,7 @@ bool CDVDDemuxFFmpeg::SeekTime(int time, bool backwords, double *startpts)
893 889
894 890 bool CDVDDemuxFFmpeg::SeekByte(__int64 pos)
895 891 {
896   - g_demuxer = this;
  892 + g_demuxer.set(this);
897 893
898 894 CSingleLock lock(m_critSection);
899 895 int ret = m_dllAvFormat.av_seek_frame(m_pFormatContext, -1, pos, AVSEEK_FLAG_BYTE);
13 xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp
@@ -21,6 +21,7 @@
21 21
22 22 #include "DVDPerformanceCounter.h"
23 23 #include "DVDMessageQueue.h"
  24 +#include "utils/TimeUtils.h"
24 25
25 26 #include "dvd_config.h"
26 27
@@ -68,22 +69,16 @@ HRESULT __stdcall DVDPerformanceCounterVideoQueue(PLARGE_INTEGER numerator, PLAR
68 69
69 70 inline __int64 get_thread_cpu_usage(ProcessPerformance* p)
70 71 {
71   - if (p->hThread)
  72 + if (p->thread)
72 73 {
73   - FILETIME dummy;
74   - FILETIME current_time_thread;
75   - FILETIME current_time_system;
76 74 ULARGE_INTEGER old_time_thread;
77 75 ULARGE_INTEGER old_time_system;
78 76
79 77 old_time_thread.QuadPart = p->timer_thread.QuadPart;
80 78 old_time_system.QuadPart = p->timer_system.QuadPart;
81 79
82   - GetThreadTimes(p->hThread, &dummy, &dummy, &current_time_thread, &dummy);
83   - GetSystemTimeAsFileTime(&current_time_system);
84   -
85   - FILETIME_TO_ULARGE_INTEGER(p->timer_thread, current_time_thread);
86   - FILETIME_TO_ULARGE_INTEGER(p->timer_system, current_time_system);
  80 + p->timer_thread.QuadPart = p->thread->GetAbsoluteUsage();
  81 + p->timer_system.QuadPart = CurrentHostCounter();
87 82
88 83 __int64 threadTime = (p->timer_thread.QuadPart - old_time_thread.QuadPart);
89 84 __int64 systemTime = (p->timer_system.QuadPart - old_time_system.QuadPart);
24 xbmc/cores/dvdplayer/DVDPerformanceCounter.h
@@ -24,7 +24,7 @@
24 24 #define FILETIME_TO_ULARGE_INTEGER(ularge, filetime) { ularge.u.HighPart = filetime.dwHighDateTime; ularge.u.LowPart = filetime.dwLowDateTime; }
25 25
26 26 #include "system.h"
27   -
  27 +#include "threads/Thread.h"
28 28 #include "threads/SingleLock.h"
29 29
30 30 class CDVDMessageQueue;
@@ -33,7 +33,7 @@ typedef struct stProcessPerformance
33 33 {
34 34 ULARGE_INTEGER timer_thread;
35 35 ULARGE_INTEGER timer_system;
36   - HANDLE hThread;
  36 + CThread* thread;
37 37 } ProcessPerformance;
38 38
39 39 class CDVDPerformanceCounter
@@ -45,20 +45,20 @@ class CDVDPerformanceCounter
45 45 bool Initialize();
46 46 void DeInitialize();
47 47
48   - void EnableAudioQueue(CDVDMessageQueue* pQueue) { CSingleLock lock(m_critSection); m_pAudioQueue = pQueue; }
49   - void DisableAudioQueue() { CSingleLock lock(m_critSection); m_pAudioQueue = NULL; }
  48 + void EnableAudioQueue(CDVDMessageQueue* pQueue) { CSingleLock lock(m_critSection); m_pAudioQueue = pQueue; }
  49 + void DisableAudioQueue() { CSingleLock lock(m_critSection); m_pAudioQueue = NULL; }
50 50
51   - void EnableVideoQueue(CDVDMessageQueue* pQueue) { CSingleLock lock(m_critSection); m_pVideoQueue = pQueue; }
52   - void DisableVideoQueue() { CSingleLock lock(m_critSection); m_pVideoQueue = NULL; }
  51 + void EnableVideoQueue(CDVDMessageQueue* pQueue) { CSingleLock lock(m_critSection); m_pVideoQueue = pQueue; }
  52 + void DisableVideoQueue() { CSingleLock lock(m_critSection); m_pVideoQueue = NULL; }
53 53
54   - void EnableVideoDecodePerformance(HANDLE hThread) { CSingleLock lock(m_critSection); m_videoDecodePerformance.hThread = hThread; }
55   - void DisableVideoDecodePerformance() { CSingleLock lock(m_critSection); m_videoDecodePerformance.hThread = NULL; }
  54 + void EnableVideoDecodePerformance(CThread *thread) { CSingleLock lock(m_critSection); m_videoDecodePerformance.thread = thread; }
  55 + void DisableVideoDecodePerformance() { CSingleLock lock(m_critSection); m_videoDecodePerformance.thread = NULL; }
56 56
57   - void EnableAudioDecodePerformance(HANDLE hThread) { CSingleLock lock(m_critSection); m_audioDecodePerformance.hThread = hThread; }
58   - void DisableAudioDecodePerformance() { CSingleLock lock(m_critSection); m_audioDecodePerformance.hThread = NULL; }
  57 + void EnableAudioDecodePerformance(CThread *thread) { CSingleLock lock(m_critSection); m_audioDecodePerformance.thread = thread; }
  58 + void DisableAudioDecodePerformance() { CSingleLock lock(m_critSection); m_audioDecodePerformance.thread = NULL; }
59 59
60   - void EnableMainPerformance(HANDLE hThread) { CSingleLock lock(m_critSection); m_mainPerformance.hThread = hThread; }
61   - void DisableMainPerformance() { CSingleLock lock(m_critSection); m_mainPerformance.hThread = NULL; }
  60 + void EnableMainPerformance(CThread *thread) { CSingleLock lock(m_critSection); m_mainPerformance.thread = thread; }
  61 + void DisableMainPerformance() { CSingleLock lock(m_critSection); m_mainPerformance.thread = NULL; }
62 62
63 63 CDVDMessageQueue* m_pAudioQueue;
64 64 CDVDMessageQueue* m_pVideoQueue;
11 xbmc/cores/dvdplayer/DVDPlayer.cpp
@@ -348,7 +348,7 @@ bool CDVDPlayer::OpenFile(const CFileItem& file, const CPlayerOptions &options)
348 348
349 349 // if playing a file close it first
350 350 // this has to be changed so we won't have to close it.
351   - if(ThreadHandle())
  351 + if(IsRunning())
352 352 CloseFile();
353 353
354 354 m_bAbortRequest = false;
@@ -440,9 +440,8 @@ void CDVDPlayer::OnStartup()
440 440
441 441 m_messenger.Init();
442 442
443   - g_dvdPerformanceCounter.EnableMainPerformance(ThreadHandle());
444   -
445 443 CUtil::ClearTempFonts();
  444 + g_dvdPerformanceCounter.EnableMainPerformance(this);
446 445 }
447 446
448 447 bool CDVDPlayer::OpenInputStream()
@@ -2897,7 +2896,7 @@ bool CDVDPlayer::OpenAudioStream(int iStream, int source)
2897 2896 m_dvdPlayerAudio.SendMessage(new CDVDMsg(CDVDMsg::PLAYER_STARTED), 1);
2898 2897
2899 2898 /* audio normally won't consume full cpu, so let it have prio */
2900   - m_dvdPlayerAudio.SetPriority(GetThreadPriority(*this)+1);
  2899 + m_dvdPlayerAudio.SetPriority(GetPriority()+1);
2901 2900
2902 2901 return true;
2903 2902 }
@@ -2962,11 +2961,11 @@ bool CDVDPlayer::OpenVideoStream(int iStream, int source)
2962 2961 // the CoreAudio audio device handler thread. We do the same for
2963 2962 // the DVDPlayerVideo thread so it can run to sleep without getting
2964 2963 // swapped out by a busy OS.
2965   - m_dvdPlayerVideo.SetPrioritySched_RR();
  2964 + m_dvdPlayerVideo.SetPriority(GetSchedRRPriority());
2966 2965 #else
2967 2966 /* use same priority for video thread as demuxing thread, as */
2968 2967 /* otherwise demuxer will starve if video consumes the full cpu */
2969   - m_dvdPlayerVideo.SetPriority(GetThreadPriority(*this));
  2968 + m_dvdPlayerVideo.SetPriority(GetPriority());
2970 2969 #endif
2971 2970 return true;
2972 2971
2  xbmc/cores/dvdplayer/DVDPlayerAudio.cpp
@@ -518,7 +518,7 @@ void CDVDPlayerAudio::OnStartup()
518 518 m_decode.msg = NULL;
519 519 m_decode.Release();
520 520
521   - g_dvdPerformanceCounter.EnableAudioDecodePerformance(ThreadHandle());
  521 + g_dvdPerformanceCounter.EnableAudioDecodePerformance(this);
522 522
523 523 #ifdef _WIN32
524 524 CoInitializeEx(NULL, COINIT_MULTITHREADED);
4 xbmc/cores/dvdplayer/DVDPlayerVideo.cpp
@@ -189,7 +189,7 @@ bool CDVDPlayerVideo::OpenStream( CDVDStreamInfo &hint )
189 189 return false;
190 190 }
191 191
192   - if(g_guiSettings.GetBool("videoplayer.usedisplayasclock") && g_VideoReferenceClock.ThreadHandle() == NULL)
  192 + if(g_guiSettings.GetBool("videoplayer.usedisplayasclock") && !g_VideoReferenceClock.IsRunning())
193 193 {
194 194 g_VideoReferenceClock.Create();
195 195 //we have to wait for the clock to start otherwise alsa can cause trouble
@@ -291,7 +291,7 @@ void CDVDPlayerVideo::OnStartup()
291 291 m_iCurrentPts = DVD_NOPTS_VALUE;
292 292 m_FlipTimeStamp = m_pClock->GetAbsoluteClock();
293 293
294   - g_dvdPerformanceCounter.EnableVideoDecodePerformance(ThreadHandle());
  294 + g_dvdPerformanceCounter.EnableVideoDecodePerformance(this);
295 295 }
296 296
297 297 void CDVDPlayerVideo::Process()
4 xbmc/cores/paplayer/PAPlayer.cpp
@@ -52,7 +52,7 @@
52 52 // Supporting all open audio codec standards.
53 53 // First one being nullsoft's nsv audio decoder format
54 54
55   -PAPlayer::PAPlayer(IPlayerCallback& callback) : IPlayer(callback)
  55 +PAPlayer::PAPlayer(IPlayerCallback& callback) : CThread("PAPlayer"), IPlayer(callback)
56 56 {
57 57 m_bIsPlaying = false;
58 58 m_bPaused = false;
@@ -168,7 +168,7 @@ bool PAPlayer::OpenFile(const CFileItem& file, const CPlayerOptions &options)
168 168
169 169 *m_currentFile = file;
170 170
171   - if (ThreadHandle() == NULL)
  171 + if (!IsRunning())
172 172 Create();
173 173
174 174 m_startEvent.Set();
2  xbmc/dialogs/GUIDialogCache.cpp
@@ -29,7 +29,7 @@
29 29 #include "threads/SingleLock.h"
30 30 #include "utils/TimeUtils.h"
31 31
32   -CGUIDialogCache::CGUIDialogCache(DWORD dwDelay, const CStdString& strHeader, const CStdString& strMsg)
  32 +CGUIDialogCache::CGUIDialogCache(DWORD dwDelay, const CStdString& strHeader, const CStdString& strMsg) : CThread("CGUIDialogCache")
33 33 {
34 34 m_pDlg = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
35 35
4 xbmc/filesystem/FileCache.cpp
@@ -79,7 +79,7 @@ class CWriteRate
79 79 };
80 80
81 81
82   -CFileCache::CFileCache()
  82 +CFileCache::CFileCache() : CThread("CFileCache")
83 83 {
84 84 m_bDeleteCache = true;
85 85 m_nSeekResult = 0;
@@ -95,7 +95,7 @@ CFileCache::CFileCache()
95 95 m_cacheFull = false;
96 96 }
97 97
98   -CFileCache::CFileCache(CCacheStrategy *pCache, bool bDeleteCache)
  98 +CFileCache::CFileCache(CCacheStrategy *pCache, bool bDeleteCache) : CThread("CFileCache")
99 99 {
100 100 m_pCache = pCache;
101 101 m_bDeleteCache = bDeleteCache;
2  xbmc/filesystem/FilePipe.cpp
@@ -24,6 +24,8 @@
24 24 #include "PipesManager.h"
25 25 #include "utils/StringUtils.h"
26 26
  27 +#define INFINITE 0xFFFFFFFF
  28 +
27 29 using namespace XFILE;
28 30
29 31 CFilePipe::CFilePipe() : m_pos(0), m_length(-1), m_pipe(NULL)
2  xbmc/filesystem/FileRar.cpp
@@ -43,7 +43,7 @@ using namespace std;
43 43 #define SEEKTIMOUT 30000
44 44
45 45 #ifdef HAS_FILESYSTEM_RAR
46   -CFileRarExtractThread::CFileRarExtractThread() : hRunning(true), hQuit(true)
  46 +CFileRarExtractThread::CFileRarExtractThread() : CThread("CFileRarExtractThread"), hRunning(true), hQuit(true)
47 47 {
48 48 m_pArc = NULL;
49 49 m_pCmd = NULL;
2  xbmc/filesystem/HTSPDirectory.cpp
@@ -76,7 +76,7 @@ static SSessions g_sessions;
76 76 static CCriticalSection g_section;
77 77
78 78
79   -CHTSPDirectorySession::CHTSPDirectorySession()
  79 +CHTSPDirectorySession::CHTSPDirectorySession() : CThread("CHTSPDirectorySession")
80 80 {
81 81 }
82 82
2  xbmc/filesystem/LastFMDirectory.cpp
@@ -69,7 +69,7 @@ bool CLastFMDirectory::RetrieveList(CStdString url)
69 69 m_dlgProgress->Progress();
70 70 }
71 71
72   - CThread thread(this);
  72 + CThread thread(this, "CLastFMDirectory");
73 73 m_strSource = url;
74 74 m_strDestination = "special://temp/lastfm.xml";
75 75 thread.Create();
2  xbmc/filesystem/MythSession.cpp
@@ -359,7 +359,7 @@ void CMythSession::SetSeasonAndEpisode(const cmyth_proginfo_t &program, int *sea
359 359 return;
360 360 }
361 361
362   -CMythSession::CMythSession(const CURL& url)
  362 +CMythSession::CMythSession(const CURL& url) : CThread("CMythSession")
363 363 {
364 364 m_control = NULL;
365 365 m_event = NULL;
2  xbmc/filesystem/PipesManager.cpp
@@ -23,6 +23,8 @@
23 23 #include "threads/SingleLock.h"
24 24 #include "Application.h"
25 25
  26 +#define INFINITE 0xFFFFFFFF
  27 +
26 28 #ifndef min
27 29 #define min(a,b) ((a) < (b) ? (a) : (b))
28 30 #endif
2  xbmc/filesystem/RarManager.h
@@ -71,7 +71,7 @@ class CRarManager
71 71 CRarManager();
72 72 ~CRarManager();
73 73 bool CacheRarredFile(CStdString& strPathInCache, const CStdString& strRarPath,
74   - const CStdString& strPathInRar, BYTE bOptions = EXFILE_AUTODELETE,
  74 + const CStdString& strPathInRar, uint8_t bOptions = EXFILE_AUTODELETE,
75 75 const CStdString& strDir =RAR_DEFAULT_CACHE, const int64_t iSize=-1);
76 76 bool GetPathInCache(CStdString& strPathInCache, const CStdString& strRarPath,
77 77 const CStdString& strPathInRar = "");
4 xbmc/filesystem/SAPDirectory.cpp
@@ -272,7 +272,7 @@ namespace SDP
272 272 using namespace SDP;
273 273
274 274
275   -CSAPSessions::CSAPSessions()
  275 +CSAPSessions::CSAPSessions() : CThread("CSAPSessions")
276 276 {
277 277 m_socket = INVALID_SOCKET;
278 278 }
@@ -486,7 +486,7 @@ namespace XFILE
486 486
487 487 CSingleLock lock(g_sapsessions.m_section);
488 488
489   - if(g_sapsessions.ThreadHandle() == NULL)
  489 + if(!g_sapsessions.IsRunning())
490 490 g_sapsessions.Create();
491 491
492 492 // check if we can find this session in our cache
4 xbmc/interfaces/python/XBPython.cpp
@@ -676,11 +676,11 @@ void XBPython::PulseGlobalEvent()
676 676 m_globalEvent.Set();
677 677 }
678 678
679   -void XBPython::WaitForEvent(CEvent& hEvent, unsigned int timeout)
  679 +void XBPython::WaitForEvent(CEvent& hEvent)
680 680 {
681 681 // wait for either this event our our global event
682 682 XbmcThreads::CEventGroup eventGroup(&hEvent, &m_globalEvent, NULL);
683   - eventGroup.wait(timeout);
  683 + eventGroup.wait();
684 684 m_globalEvent.Reset();
685 685 }
686 686
2  xbmc/interfaces/python/XBPython.h
@@ -61,7 +61,7 @@ class XBPython : public IPlayerCallback
61 61 void Process();
62 62
63 63 void PulseGlobalEvent();
64   - void WaitForEvent(CEvent& hEvent, unsigned int timeout);
  64 + void WaitForEvent(CEvent& hEvent);
65 65
66 66 int ScriptsSize();
67 67 int GetPythonScriptId(int scriptPosition);
4 xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.cpp
@@ -181,9 +181,9 @@ void CGUIPythonWindow::SetCallbackWindow(void *state, void *object)
181 181 m_threadState = state;
182 182 }
183 183
184   -void CGUIPythonWindow::WaitForActionEvent(unsigned int timeout)
  184 +void CGUIPythonWindow::WaitForActionEvent()
185 185 {
186   - g_pythonParser.WaitForEvent(m_actionEvent, timeout);
  186 + g_pythonParser.WaitForEvent(m_actionEvent);
187 187 m_actionEvent.Reset();
188 188 }
189 189
2  xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.h
@@ -51,7 +51,7 @@ class CGUIPythonWindow : public CGUIWindow
51 51 virtual bool OnAction(const CAction &action);
52 52 virtual bool OnBack(int actionID);
53 53 void SetCallbackWindow(void* state, void *object);
54   - void WaitForActionEvent(unsigned int timeout);
  54 + void WaitForActionEvent();
55 55 void PulseActionEvent();
56 56 void SetDestroyAfterDeinit(bool destroy = true);
57 57 protected:
4 xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.cpp
@@ -279,9 +279,9 @@ void CGUIPythonWindowXML::ClearList()
279 279 UpdateButtons();
280 280 }
281 281
282   -void CGUIPythonWindowXML::WaitForActionEvent(unsigned int timeout)
  282 +void CGUIPythonWindowXML::WaitForActionEvent()
283 283 {
284   - g_pythonParser.WaitForEvent(m_actionEvent, timeout);
  284 + g_pythonParser.WaitForEvent(m_actionEvent);
285 285 m_actionEvent.Reset();
286 286 }
287 287
2  xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.h
@@ -40,7 +40,7 @@ class CGUIPythonWindowXML : public CGUIMediaWindow
40 40 virtual void AllocResources(bool forceLoad = false);
41 41 virtual void FreeResources(bool forceUnLoad = false);
42 42 void Process(unsigned int currentTime, CDirtyRegionList &regions);
43   - void WaitForActionEvent(unsigned int timeout);
  43 + void WaitForActionEvent();
44 44 void PulseActionEvent();
45 45 void AddItem(CFileItemPtr fileItem,int itemPosition);
46 46 void RemoveItem(int itemPosition);
6 xbmc/interfaces/python/xbmcmodule/window.cpp
@@ -540,11 +540,11 @@ namespace PYXBMC
540 540
541 541 CPyThreadState pyState;
542 542 if (WindowXML_Check(self))
543   - ((CGUIPythonWindowXML*)self->pWindow)->WaitForActionEvent(INFINITE);
  543 + ((CGUIPythonWindowXML*)self->pWindow)->WaitForActionEvent();
544 544 else if (WindowXMLDialog_Check(self))
545   - ((CGUIPythonWindowXMLDialog*)self->pWindow)->WaitForActionEvent(INFINITE);
  545 + ((CGUIPythonWindowXMLDialog*)self->pWindow)->WaitForActionEvent();
546 546 else
547   - ((CGUIPythonWindow*)self->pWindow)->WaitForActionEvent(INFINITE);
  547 + ((CGUIPythonWindow*)self->pWindow)->WaitForActionEvent();
548 548 }
549 549 }
550 550 Py_INCREF(Py_None);
3  xbmc/linux/Makefile.in
@@ -10,14 +10,11 @@ SRCS=ConvUtils.cpp \
10 10 LinuxResourceCounter.cpp \
11 11 LinuxTimezone.cpp \
12 12 PosixMountProvider.cpp \
13   - XEventUtils.cpp \
14 13 XFileUtils.cpp \
15 14 XHandle.cpp \
16 15 XLCDproc.cpp \
17 16 XMemUtils.cpp \
18   - XSyncUtils.cpp \
19 17 XTimeUtils.cpp \
20   - XThreadUtils.cpp \
21 18
22 19 LIB=linux.a
23 20
2  xbmc/linux/PlatformDefs.h
@@ -182,8 +182,6 @@
182 182 #define EXCEPTION_EXECUTE_HANDLER ...
183 183 //NOTE: dont try to define __except because it breaks g++ (already uses it).
184 184
185   -typedef pthread_t ThreadIdentifier;
186   -
187 185 struct CXHandle; // forward declaration
188 186 typedef CXHandle* HANDLE;
189 187
3  xbmc/linux/PlatformInclude.h
@@ -25,10 +25,7 @@
25 25 #include "PlatformDefs.h"
26 26 #include "XHandlePublic.h"
27 27 #include "XFileUtils.h"
28   -#include "XSyncUtils.h"
29   -#include "XEventUtils.h"
30 28 #include "XTimeUtils.h"
31   -#include "XThreadUtils.h"
32 29 #include "XMemUtils.h"
33 30 #include "ConvUtils.h"
34 31
144 xbmc/linux/XEventUtils.cpp
... ... @@ -1,144 +0,0 @@
1   -/*
2   - * Copyright (C) 2005-2008 Team XBMC
3   - * http://www.xbmc.org
4   - *
5   - * This Program is free software; you can redistribute it and/or modify
6   - * it under the terms of the GNU General Public License as published by
7   - * the Free Software Foundation; either version 2, or (at your option)
8   - * any later version.
9   - *
10   - * This Program is distributed in the hope that it will be useful,
11   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   - * GNU General Public License for more details.
14   - *
15   - * You should have received a copy of the GNU General Public License
16   - * along with XBMC; see the file COPYING. If not, write to
17   - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18   - * http://www.gnu.org/copyleft/gpl.html
19   - *
20   - */
21   -
22   -#include "system.h"
23   -#include "PlatformDefs.h"
24   -#include "XEventUtils.h"
25   -#include "XHandle.h"
26   -#include "utils/log.h"
27   -#include "threads/SingleLock.h"
28   -
29   -using namespace std;
30   -
31   -HANDLE WINAPI CreateEvent(void *pDummySec, bool bManualReset, bool bInitialState, char *szDummyName)
32   -{
33   - CXHandle *pHandle = new CXHandle(CXHandle::HND_EVENT);
34   - pHandle->m_bManualEvent = bManualReset;
35   - pHandle->m_hCond = new XbmcThreads::ConditionVariable();
36   - pHandle->m_hMutex = new CCriticalSection();
37   - pHandle->m_bEventSet = false;
38   -
39   - if (bInitialState)
40   - SetEvent(pHandle);
41   -
42   - return pHandle;
43   -}
44   -
45   -//
46   -// The state of a manual-reset event object remains signaled until it is set explicitly to the nonsignaled
47   -// state by the ResetEvent function. Any number of waiting threads, or threads that subsequently begin wait
48   -// operations for the specified event object by calling one of the wait functions, can be released while the
49   -// object's state is signaled.
50   -//
51   -// The state of an auto-reset event object remains signaled until a single waiting thread is released, at
52   -// which time the system automatically sets the state to nonsignaled. If no threads are waiting, the event
53   -// object's state remains signaled.
54   -//
55   -bool WINAPI SetEvent(HANDLE hEvent)
56   -{
57   - if (hEvent == NULL || hEvent->m_hCond == NULL || hEvent->m_hMutex == NULL)
58   - return false;
59   -
60   - CSingleLock lock(*(hEvent->m_hMutex));
61   - hEvent->m_bEventSet = true;
62   -
63   - // we must guarantee that these handle's won't be deleted, until we are done
64   - list<CXHandle*> events = hEvent->m_hParents;
65   - for(list<CXHandle*>::iterator it = events.begin();it != events.end();it++)
66   - DuplicateHandle(GetCurrentProcess(), *it, GetCurrentProcess(), NULL, 0, FALSE, DUPLICATE_SAME_ACCESS);
67   -
68   - lock.Leave();
69   -
70   - for(list<CXHandle*>::iterator it = events.begin();it != events.end();it++)
71   - {
72   - SetEvent(*it);
73   - CloseHandle(*it);
74   - }
75   -
76   - DuplicateHandle(GetCurrentProcess(), hEvent, GetCurrentProcess(), NULL, 0, FALSE, DUPLICATE_SAME_ACCESS);
77   -
78   - if (hEvent->m_bManualEvent == true)
79   - hEvent->m_hCond->notifyAll();
80   - else
81   - hEvent->m_hCond->notify();
82   -
83   - CloseHandle(hEvent);
84   -
85   - return true;
86   -}
87   -
88   -bool WINAPI ResetEvent(HANDLE hEvent)
89   -{
90   - if (hEvent == NULL || hEvent->m_hCond == NULL || hEvent->m_hMutex == NULL)
91   - return false;
92   -
93   - CSingleLock lock(*(hEvent->m_hMutex));
94   - hEvent->m_bEventSet = false;
95   -
96   - return true;
97   -}
98   -
99   -bool WINAPI PulseEvent(HANDLE hEvent)
100   -{
101   - if (hEvent == NULL || hEvent->m_hCond == NULL || hEvent->m_hMutex == NULL)
102   - return false;
103   -
104   - CSingleLock lock(*(hEvent->m_hMutex));
105   - // we must guarantee that these handle's won't be deleted, until we are done
106   - list<CXHandle*> events = hEvent->m_hParents;
107   - for(list<CXHandle*>::iterator it = events.begin();it != events.end();it++)
108   - DuplicateHandle(GetCurrentProcess(), *it, GetCurrentProcess(), NULL, 0, FALSE, DUPLICATE_SAME_ACCESS);
109   -
110   - if(events.size())
111   - {
112   - CLog::Log(LOGWARNING,"PulseEvent - ineffecient multiwait detected");
113   - hEvent->m_bEventSet = true;
114   - }
115   -
116   - lock.Leave();
117   -
118   - for(list<CXHandle*>::iterator it = events.begin();it != events.end();it++)
119   - {
120   - SetEvent(*it);
121   - CloseHandle(*it);
122   -
123   - if (hEvent->m_bManualEvent == false)
124   - break;
125   - }
126   -
127   - // for multiwaits, we must yield some time to get the multiwaits to notice it was signaled
128   - if(events.size())
129   - Sleep(10);
130   -
131   - // we should always unset the event on pulse
132   - {
133   - CSingleLock lock2(*(hEvent->m_hMutex));
134   - hEvent->m_bEventSet = false;
135   - }
136   -
137   - if (hEvent->m_bManualEvent == true)
138   - hEvent->m_hCond->notifyAll();
139   - else
140   - hEvent->m_hCond->notify();
141   -
142   - return true;
143   -}
144   -
18 xbmc/linux/XHandle.cpp
@@ -20,12 +20,15 @@
20 20 */
21 21
22 22 #include "XHandle.h"
23   -#include "XThreadUtils.h"
24 23 #include "utils/log.h"
25 24 #include "threads/SingleLock.h"
26 25
27 26 int CXHandle::m_objectTracker[10] = {0};
28 27
  28 +HANDLE WINAPI GetCurrentProcess(void) {
  29 + return (HANDLE)-1; // -1 a special value - pseudo handle
  30 +}
  31 +
29 32 CXHandle::CXHandle()
30 33 {
31 34 Init();
@@ -47,11 +50,6 @@ CXHandle::CXHandle(const CXHandle &src)
47 50
48 51 Init();
49 52
50   - if (m_threadValid)
51   - {
52   - CLog::Log(LOGERROR, "%s - thread handle copied instead of passed!", __FUNCTION__);
53   - }
54   -
55 53 if (src.m_hMutex)
56 54 m_hMutex = new CCriticalSection();
57 55
@@ -80,7 +78,7 @@ CXHandle::~CXHandle()
80 78 CLog::Log(LOGERROR,"%s, destroying handle with ref count %d", __FUNCTION__, m_nRefCount);
81 79 assert(false);
82 80 }
83   -
  81 +
84 82 if (m_hMutex) {
85 83 delete m_hMutex;
86 84 }
@@ -93,10 +91,6 @@ CXHandle::~CXHandle()
93 91 delete m_hCond;
94 92 }
95 93
96   - if (m_threadValid) {
97   - pthread_join(m_hThread, NULL);
98   - }
99   -
100 94 if ( fd != 0 ) {
101 95 close(fd);
102 96 }
@@ -107,11 +101,9 @@ void CXHandle::Init()
107 101 {
108 102 fd=0;
109 103 m_hMutex=NULL;
110   - m_threadValid=false;
111 104 m_hCond=NULL;
112 105 m_type = HND_NULL;
113 106 RecursionCount=0;
114   - OwningThread=0;
115 107 m_bManualEvent=FALSE;
116 108 m_bEventSet=FALSE;
117 109 m_nFindFileIterator=0 ;
6 xbmc/linux/XHandle.h
@@ -25,7 +25,6 @@
25 25 #ifndef _WIN32
26 26
27 27 #include <list>
28   -#include <pthread.h>
29 28
30 29 #include "PlatformDefs.h"
31 30 #include "XHandlePublic.h"
@@ -36,7 +35,7 @@
36 35 struct CXHandle {
37 36
38 37 public:
39   - typedef enum { HND_NULL = 0, HND_FILE, HND_EVENT, HND_MUTEX, HND_THREAD, HND_FIND_FILE } HandleType;
  38 + typedef enum { HND_NULL = 0, HND_FILE, HND_EVENT, HND_MUTEX, HND_FIND_FILE } HandleType;
40 39
41 40 CXHandle();
42 41 CXHandle(HandleType nType);
@@ -47,8 +46,6 @@ struct CXHandle {
47 46 inline HandleType GetType() { return m_type; }
48 47 void ChangeType(HandleType newType);
49 48
50   - ThreadIdentifier m_hThread;
51   - bool m_threadValid;
52 49 XbmcThreads::ConditionVariable *m_hCond;
53 50 std::list<CXHandle*> m_hParents;
54 51
@@ -62,7 +59,6 @@ struct CXHandle {
62 59 // simulate mutex and critical section
63 60 CCriticalSection *m_hMutex;
64 61 int RecursionCount; // for mutex - for compatibility with WIN32 critical section
65   - pthread_t OwningThread;
66 62 int fd;
67 63 bool m_bManualEvent;
68 64 time_t m_tmCreation;
130 xbmc/linux/XMemUtils.cpp
@@ -25,6 +25,10 @@
25 25
26 26 #include "XMemUtils.h"
27 27
  28 +#ifdef __APPLE__
  29 +#include <mach/mach.h>
  30 +#endif
  31 +
28 32 #undef ALIGN
29 33 #define ALIGN(value, alignment) (((value)+(alignment-1))&~(alignment-1))
30 34
@@ -49,4 +53,130 @@ void _aligned_free(void *p) {
49 53 free(pFull);
50 54 }
51 55
  56 +#ifndef _WIN32
  57 +
  58 +#if defined(_LINUX) && !defined(__APPLE__) && !defined(__FreeBSD__)
  59 +static FILE* procMeminfoFP = NULL;
  60 +#endif
  61 +
  62 +void GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)
  63 +{
  64 + if (!lpBuffer)
  65 + return;
  66 +
  67 + memset(lpBuffer, 0, sizeof(MEMORYSTATUSEX));
  68 +
  69 +#ifdef __APPLE__
  70 + uint64_t physmem;
  71 + size_t len = sizeof physmem;
  72 + int mib[2] = { CTL_HW, HW_MEMSIZE };
  73 + size_t miblen = sizeof(mib) / sizeof(mib[0]);
  74 +
  75 + // Total physical memory.
  76 + if (sysctl(mib, miblen, &physmem, &len, NULL, 0) == 0 && len == sizeof (physmem))
  77 + lpBuffer->ullTotalPhys = physmem;
  78 +
  79 + // Virtual memory.
  80 + mib[0] = CTL_VM; mib[1] = VM_SWAPUSAGE;
  81 + struct xsw_usage swap;
  82 + len = sizeof(struct xsw_usage);
  83 + if (sysctl(mib, miblen, &swap, &len, NULL, 0) == 0)
  84 + {
  85 + lpBuffer->ullAvailPageFile = swap.xsu_avail;
  86 + lpBuffer->ullTotalVirtual = lpBuffer->ullTotalPhys + swap.xsu_total;
  87 + }
  88 +
  89 + // In use.
  90 + mach_port_t stat_port = mach_host_self();
  91 + vm_statistics_data_t vm_stat;
  92 + mach_msg_type_number_t count = sizeof(vm_stat) / sizeof(natural_t);
  93 + if (host_statistics(stat_port, HOST_VM_INFO, (host_info_t)&vm_stat, &count) == 0)
  94 + {
  95 + // Find page size.
  96 + int pageSize;
  97 + mib[0] = CTL_HW; mib[1] = HW_PAGESIZE;
  98 + len = sizeof(int);
  99 + if (sysctl(mib, miblen, &pageSize, &len, NULL, 0) == 0)
  100 + {
  101 + uint64_t used = (vm_stat.active_count + vm_stat.inactive_count + vm_stat.wire_count) * pageSize;
  102 +
  103 + lpBuffer->ullAvailPhys = lpBuffer->ullTotalPhys - used;
  104 + lpBuffer->ullAvailVirtual = lpBuffer->ullAvailPhys; // FIXME.
  105 + }
  106 + }
  107 +#elif defined(__FreeBSD__)
  108 + /* sysctl hw.physmem */
  109 + size_t physmem = 0, mem_free = 0, pagesize = 0, swap_free = 0;
  110 + size_t mem_avail = 0, mem_inactive = 0, mem_cache = 0, len = 0;
  111 +
  112 + /* physmem */
  113 + len = sizeof(physmem);
  114 + if (sysctlbyname("hw.physmem", &physmem, &len, NULL, 0) == 0) {
  115 + lpBuffer->ullTotalPhys = physmem;
  116 + lpBuffer->ullTotalVirtual = physmem;
  117 + }
  118 + /* pagesize */
  119 + len = sizeof(pagesize);
  120 + if (sysctlbyname("hw.pagesize", &pagesize, &len, NULL, 0) != 0)
  121 + pagesize = 4096;
  122 + /* mem_inactive */
  123 + len = sizeof(mem_inactive);
  124 + if (sysctlbyname("vm.stats.vm.v_inactive_count", &mem_inactive, &len, NULL, 0) == 0)
  125 + mem_inactive *= pagesize;
  126 + /* mem_cache */
  127 + len = sizeof(mem_cache);
  128 + if (sysctlbyname("vm.stats.vm.v_cache_count", &mem_cache, &len, NULL, 0) == 0)
  129 + mem_cache *= pagesize;
  130 + /* mem_free */
  131 + len = sizeof(mem_free);
  132 + if (sysctlbyname("vm.stats.vm.v_free_count", &mem_free, &len, NULL, 0) == 0)
  133 + mem_free *= pagesize;
  134 +
  135 + /* mem_avail = mem_inactive + mem_cache + mem_free */
  136 + lpBuffer->ullAvailPhys = mem_inactive + mem_cache + mem_free;
  137 + lpBuffer->ullAvailVirtual = mem_inactive + mem_cache + mem_free;
  138 +
  139 + if (sysctlbyname("vm.stats.vm.v_swappgsout", &swap_free, &len, NULL, 0) == 0)
  140 + lpBuffer->ullAvailPageFile = swap_free * pagesize;
  141 +#else
  142 + struct sysinfo info;
  143 + char name[32];
  144 + unsigned val;
  145 + if (!procMeminfoFP && (procMeminfoFP = fopen("/proc/meminfo", "r")) == NULL)
  146 + sysinfo(&info);
  147 + else
  148 + {
  149 + memset(&info, 0, sizeof(struct sysinfo));
  150 + info.mem_unit = 4096;
  151 + while (fscanf(procMeminfoFP, "%31s %u%*[^\n]\n", name, &val) != EOF)
  152 + {
  153 + if (strncmp("MemTotal:", name, 9) == 0)
  154 + info.totalram = val/4;
  155 + else if (strncmp("MemFree:", name, 8) == 0)
  156 + info.freeram = val/4;
  157 + else if (strncmp("Buffers:", name, 8) == 0)
  158 + info.bufferram += val/4;
  159 + else if (strncmp("Cached:", name, 7) == 0)
  160 + info.bufferram += val/4;
  161 + else if (strncmp("SwapTotal:", name, 10) == 0)
  162 + info.totalswap = val/4;
  163 + else if (strncmp("SwapFree:", name, 9) == 0)
  164 + info.freeswap = val/4;
  165 + else if (strncmp("HighTotal:", name, 10) == 0)
  166 + info.totalhigh = val/4;
  167 + else if (strncmp("HighFree:", name, 9) == 0)
  168 + info.freehigh = val/4;
  169 + }
  170 + rewind(procMeminfoFP);
  171 + fflush(procMeminfoFP);
  172 + }
  173 + lpBuffer->ullAvailPageFile = (info.freeswap * info.mem_unit);
  174 + lpBuffer->ullAvailPhys = ((info.freeram + info.bufferram) * info.mem_unit);
  175 + lpBuffer->ullAvailVirtual = ((info.freeram + info.bufferram) * info.mem_unit);
  176 + lpBuffer->ullTotalPhys = (info.totalram * info.mem_unit);
  177 + lpBuffer->ullTotalVirtual = (info.totalram * info.mem_unit);
  178 +#endif
  179 +}
  180 +
  181 +#endif
52 182
4 xbmc/linux/XMemUtils.h
@@ -22,10 +22,14 @@
22 22 *
23 23 */
24 24
  25 +#include "linux/PlatformDefs.h"
  26 +
25 27 // aligned memory allocation and free. memory returned will be aligned to "alignTo" bytes.
26 28 // this is a linux (actually platfom free) implementation of the win32 CRT methods _aligned_malloc and _aligned_free.
27 29 void *_aligned_malloc(size_t s, size_t alignTo);
28 30 void _aligned_free(void *p) ;
29 31
  32 +void GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer);
  33 +
30 34 #endif
31 35
169 xbmc/linux/XSyncUtils.cpp
... ... @@ -1,169 +0,0 @@
1   -/*
2   - * Copyright (C) 2005-2008 Team XBMC
3   - * http://www.xbmc.org
4   - *
5   - * This Program is free software; you can redistribute it and/or modify
6   - * it under the terms of the GNU General Public License as published by
7   - * the Free Software Foundation; either version 2, or (at your option)
8   - * any later version.
9   - *
10   - * This Program is distributed in the hope that it will be useful,
11   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   - * GNU General Public License for more details.
14   - *
15   - * You should have received a copy of the GNU General Public License
16   - * along with XBMC; see the file COPYING. If not, write to
17   - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18   - * http://www.gnu.org/copyleft/gpl.html
19   - *
20   - */
21   -
22   -#ifndef _WIN32
23   -
24   -
25   -#include <semaphore.h>
26   -#include <time.h>
27   -#include <errno.h>
28   -#include <stack>
29   -#include <functional>
30   -#ifdef __APPLE__
31   -#include <mach/mach.h>
32   -#endif
33   -
34   -#include "XSyncUtils.h"
35   -#include "XTimeUtils.h"
36   -#include "PlatformDefs.h"
37   -#include "XHandle.h"