Skip to content

Commit 64427d4

Browse files
FernetMentaJim Carroll
authored andcommitted
threads: remove WINAPI, implement priority for pthreads
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.
1 parent 8d73c5d commit 64427d4

85 files changed

Lines changed: 966 additions & 1114 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/UnrarXLib/extract.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#include "rar.hpp"
22
#include "Util.h"
3-
#ifdef _LINUX
4-
#include "XSyncUtils.h"
5-
#include "XEventUtils.h"
6-
#endif
73

84
// a cautious wrapper around strncpy
95
char *strncpy_null_terminated(char *dest, const char *src, size_t n)

lib/UnrarXLib/unpack.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
#include "unpack20.cpp"
99
#endif
1010

11-
#ifdef _LINUX
12-
#include "XSyncUtils.h"
13-
#include "XEventUtils.h"
14-
#endif
15-
1611
Unpack::Unpack(ComprDataIO *DataIO)
1712
{
1813
UnpIO=DataIO;

lib/UnrarXLib/unpack15.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
#ifdef _LINUX
2-
#include "XSyncUtils.h"
3-
#endif
4-
51
#define STARTL1 2
62
static unsigned int DecL1[]={0x8000,0xa000,0xc000,0xd000,0xe000,0xea00,
73
0xee00,0xf000,0xf200,0xf200,0xffff};

xbmc/ApplicationMessenger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
using namespace std;
7575

76-
CDelayedMessage::CDelayedMessage(ThreadMessage& msg, unsigned int delay)
76+
CDelayedMessage::CDelayedMessage(ThreadMessage& msg, unsigned int delay) : CThread("CDelayedMessage")
7777
{
7878
m_msg.dwMessage = msg.dwMessage;
7979
m_msg.dwParam1 = msg.dwParam1;

xbmc/cdrip/CDDAReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
#define SECTOR_COUNT 52
3131

32-
CCDDAReader::CCDDAReader()
32+
CCDDAReader::CCDDAReader() : CThread("CCDDAReader")
3333
{
3434
m_sRipBuffer[0].pbtStream = NULL;
3535
m_sRipBuffer[1].pbtStream = NULL;

xbmc/cores/DllLoader/exports/emu_kernel32.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,6 @@ extern "C" DWORD WINAPI dllGetCurrentProcessId(void)
240240
#endif
241241
}
242242

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-
252243
extern "C" int WINAPI dllDuplicateHandle(HANDLE hSourceProcessHandle, // handle to source process
253244
HANDLE hSourceHandle, // handle to duplicate
254245
HANDLE hTargetProcessHandle, // handle to target process

xbmc/cores/DllLoader/exports/emu_kernel32.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,6 @@ extern "C" BOOL WINAPI dllGetProcessAffinityMask(HANDLE hProcess, LPDWORD lpProc
686686

687687
extern "C" HGLOBAL WINAPI dllLoadResource(HMODULE module, HRSRC res);
688688
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);
690689
extern "C" int WINAPI dllGetLocaleInfoA(LCID Locale, LCTYPE LCType, LPTSTR lpLCData, int cchData);
691690
extern "C" UINT WINAPI dllGetConsoleCP();
692691
extern "C" UINT WINAPI dllGetConsoleOutputCP();

xbmc/cores/DummyVideoPlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
CDummyVideoPlayer::CDummyVideoPlayer(IPlayerCallback& callback)
3535
: IPlayer(callback),
36-
CThread()
36+
CThread("CDummyVideoPlayer")
3737
{
3838
m_paused = false;
3939
m_clock = 0;

xbmc/cores/dvdplayer/DVDCodecs/Video/CrystalHD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ CPictureBuffer::~CPictureBuffer()
325325
#pragma mark -
326326
#endif
327327
CMPCOutputThread::CMPCOutputThread(void *device, DllLibCrystalHD *dll, bool has_bcm70015) :
328-
CThread(),
328+
CThread("CMPCOutputThread"),
329329
m_dll(dll),
330330
m_device(device),
331331
m_has_bcm70015(has_bcm70015),

xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*
2020
*/
2121

22-
#include "threads/SystemClock.h"
2322
#include "system.h"
2423
#ifndef __STDC_CONSTANT_MACROS
2524
#define __STDC_CONSTANT_MACROS
@@ -45,6 +44,7 @@
4544
#include "filesystem/Directory.h"
4645
#include "utils/log.h"
4746
#include "threads/Thread.h"
47+
#include "threads/SystemClock.h"
4848
#include "utils/TimeUtils.h"
4949

5050
void CDemuxStreamAudioFFmpeg::GetStreamInfo(std::string& strInfo)
@@ -155,16 +155,12 @@ static void ff_flush_avutil_log_buffers(void)
155155
++it;
156156
}
157157

158-
#ifdef _MSC_VER
159-
static __declspec(thread) CDVDDemuxFFmpeg* g_demuxer = 0;
160-
#else
161-
static TLS g_tls;
162-
#define g_demuxer (*((CDVDDemuxFFmpeg**)g_tls.Get()))
163-
#endif
158+
static XbmcThreads::ThreadLocal<CDVDDemuxFFmpeg> g_demuxer;
164159

165160
static int interrupt_cb(void* unused)
166161
{
167-
if(g_demuxer && g_demuxer->Aborted())
162+
CDVDDemuxFFmpeg* demuxer = g_demuxer.get();
163+
if(demuxer && demuxer->Aborted())
168164
return 1;
169165
return 0;
170166
}
@@ -236,7 +232,7 @@ bool CDVDDemuxFFmpeg::Open(CDVDInputStream* pInput)
236232
std::string strFile;
237233
m_iCurrentPts = DVD_NOPTS_VALUE;
238234
m_speed = DVD_PLAYSPEED_NORMAL;
239-
g_demuxer = this;
235+
g_demuxer.set(this);
240236
m_program = UINT_MAX;
241237
const AVIOInterruptCB int_cb = { interrupt_cb, NULL };
242238

@@ -500,7 +496,7 @@ bool CDVDDemuxFFmpeg::Open(CDVDInputStream* pInput)
500496

501497
void CDVDDemuxFFmpeg::Dispose()
502498
{
503-
g_demuxer = this;
499+
g_demuxer.set(this);
504500

505501
if (m_pFormatContext)
506502
{
@@ -541,7 +537,7 @@ void CDVDDemuxFFmpeg::Reset()
541537

542538
void CDVDDemuxFFmpeg::Flush()
543539
{
544-
g_demuxer = this;
540+
g_demuxer.set(this);
545541

546542
// naughty usage of an internal ffmpeg function
547543
if (m_pFormatContext)
@@ -557,7 +553,7 @@ void CDVDDemuxFFmpeg::Abort()
557553

558554
void CDVDDemuxFFmpeg::SetSpeed(int iSpeed)
559555
{
560-
g_demuxer = this;
556+
g_demuxer.set(this);
561557

562558
if(!m_pFormatContext)
563559
return;
@@ -619,7 +615,7 @@ double CDVDDemuxFFmpeg::ConvertTimestamp(int64_t pts, int den, int num)
619615

620616
DemuxPacket* CDVDDemuxFFmpeg::Read()
621617
{
622-
g_demuxer = this;
618+
g_demuxer.set(this);
623619

624620
AVPacket pkt;
625621
DemuxPacket* pPacket = NULL;
@@ -811,7 +807,7 @@ DemuxPacket* CDVDDemuxFFmpeg::Read()
811807

812808
bool CDVDDemuxFFmpeg::SeekTime(int time, bool backwords, double *startpts)
813809
{
814-
g_demuxer = this;
810+
g_demuxer.set(this);
815811

816812
if(time < 0)
817813
time = 0;
@@ -871,7 +867,7 @@ bool CDVDDemuxFFmpeg::SeekTime(int time, bool backwords, double *startpts)
871867

872868
bool CDVDDemuxFFmpeg::SeekByte(__int64 pos)
873869
{
874-
g_demuxer = this;
870+
g_demuxer.set(this);
875871

876872
CSingleLock lock(m_critSection);
877873
int ret = m_dllAvFormat.av_seek_frame(m_pFormatContext, -1, pos, AVSEEK_FLAG_BYTE);

0 commit comments

Comments
 (0)