rendered paste bodydiff --git a/Makefile.in b/Makefile.inindex 87097c3..3d67c98 100644--- a/Makefile.in+++ b/Makefile.in@@ -243,6 +243,8 @@ xbmc/lib/libsquish/libsquish-@ARCH@.a: force $(MAKE) -C xbmc/lib/libsquish xbmc/linux/linux.a: force $(MAKE) -C xbmc/linux+xbmc/posix/posix.a: force+ $(MAKE) -C xbmc/posix xbmc/screensavers/screensaver.a: force $(MAKE) -C xbmc/screensavers xbmc/settings/settings.a: force@@ -388,7 +390,8 @@ OBJSXBMC= \ xbmc/lib/libsquish/libsquish-@ARCH@.a \ xbmc/screensavers/screensaver.a \ xbmc/settings/settings.a \- xbmc/visualizations/visualization.a+ xbmc/visualizations/visualization.a \+ xbmc/posix/posix.a ifeq (@HAVE_XBMC_NONFREE@,1) OBJSXBMC+= \diff --git a/xbmc/cores/paplayer/SIDCodec/Makefile.in b/xbmc/cores/paplayer/SIDCodec/Makefile.inindex fd77476..a434b95 100644--- a/xbmc/cores/paplayer/SIDCodec/Makefile.in+++ b/xbmc/cores/paplayer/SIDCodec/Makefile.in@@ -1,6 +1,6 @@ ARCH=@ARCH@ -CFLAGS +=-D_LINUX -DHAVE_UNIX -DHAVE_STRCASECMP -DHAVE_STRNCASECMP -DHAVE_IOS_OPENMODE -fPIC -Ilibsidplay/win/VC -Ibuilders/resid-builder/include/sidplay/builders -Ilibsidplay/include/sidplay -Iresid -Ilibsidplay/include -I../../../linux -I../../../ -I../../../../guilib/ -fPIC+CFLAGS +=-D_LINUX -DHAVE_UNIX -DHAVE_STRCASECMP -DHAVE_STRNCASECMP -DHAVE_IOS_OPENMODE -fPIC -Ilibsidplay/win/VC -Ibuilders/resid-builder/include/sidplay/builders -Ilibsidplay/include/sidplay -Iresid -Ilibsidplay/include -I../../../linux -I../../../utils -I../../../ -I../../../../guilib/ -fPIC CXXFLAGS += $(CFLAGS) ifeq ($(ARCH), powerpc-osx) BUNDLE1_O=-lbundle1.o -L/usr/lib/gcc/powerpc-apple-darwin8/4.0.1/ -lgccdiff --git a/xbmc/linux/XHandle.cpp b/xbmc/linux/XHandle.cppindex 5a314f6..59f7c1c 100644--- a/xbmc/linux/XHandle.cpp+++ b/xbmc/linux/XHandle.cpp@@ -47,8 +47,8 @@ CXHandle::CXHandle(const CXHandle &src) CLog::Log(LOGWARNING,"%s, copy handle.", __FUNCTION__); Init();- if (src.m_hSem)- m_hSem = SDL_CreateSemaphore(SDL_SemValue(src.m_hSem));+ if (src.m_pSem)+ m_pSem = new CSemaphore(*src.m_pSem); if (m_threadValid) {@@ -83,10 +83,8 @@ CXHandle::~CXHandle() CLog::Log(LOGERROR,"%s, destroying handle with ref count %d", __FUNCTION__, m_nRefCount); assert(false); }-- if (m_hSem) {- SDL_DestroySemaphore(m_hSem);- }+ + delete m_pSem; if (m_hMutex) { SDL_DestroyMutex(m_hMutex);@@ -113,7 +111,7 @@ CXHandle::~CXHandle() void CXHandle::Init() { fd=0;- m_hSem=NULL;+ m_pSem=NULL; m_hMutex=NULL; m_threadValid=false; m_hCond=NULL;diff --git a/xbmc/linux/XHandle.h b/xbmc/linux/XHandle.hindex db6fcc1..85799e2 100644--- a/xbmc/linux/XHandle.h+++ b/xbmc/linux/XHandle.h@@ -30,6 +30,7 @@ #include "PlatformDefs.h" #include "XHandlePublic.h"+#include "Semaphore.h" #include <list> struct CXHandle {@@ -46,7 +47,7 @@ public: inline HandleType GetType() { return m_type; } void ChangeType(HandleType newType); - SDL_sem *m_hSem;+ CSemaphore *m_pSem; ThreadIdentifier m_hThread; bool m_threadValid; SDL_cond *m_hCond;diff --git a/xbmc/linux/XSyncUtils.cpp b/xbmc/linux/XSyncUtils.cppindex cfad28c..f110eca 100644--- a/xbmc/linux/XSyncUtils.cpp+++ b/xbmc/linux/XSyncUtils.cpp@@ -53,7 +53,7 @@ bool InitializeRecursiveMutex(HANDLE hMutex, BOOL bInitialOwner) { // we use semaphores instead of the mutex because in SDL we CANT wait for a mutex // to lock with timeout.- hMutex->m_hSem = SDL_CreateSemaphore(bInitialOwner?0:1);+ hMutex->m_pSem = new CSemaphore(bInitialOwner?0:1); hMutex->m_hMutex = SDL_CreateMutex(); hMutex->ChangeType(CXHandle::HND_MUTEX); @@ -66,14 +66,14 @@ bool InitializeRecursiveMutex(HANDLE hMutex, BOOL bInitialOwner) { } bool DestroyRecursiveMutex(HANDLE hMutex) {- if (hMutex == NULL || hMutex->m_hMutex == NULL || hMutex->m_hSem == NULL)+ if (hMutex == NULL || hMutex->m_hMutex == NULL || hMutex->m_pSem == NULL) return false; - SDL_DestroySemaphore(hMutex->m_hSem);+ delete hMutex->m_pSem; SDL_DestroyMutex(hMutex->m_hMutex); hMutex->m_hMutex = NULL;- hMutex->m_hSem = NULL;+ hMutex->m_pSem = NULL; return true; }@@ -87,7 +87,7 @@ HANDLE WINAPI CreateMutex( LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInit } bool WINAPI ReleaseMutex( HANDLE hMutex ) {- if (hMutex == NULL || hMutex->m_hSem == NULL || hMutex->m_hMutex == NULL)+ if (hMutex == NULL || hMutex->m_pSem == NULL || hMutex->m_hMutex == NULL) return false; BOOL bOk = false;@@ -97,7 +97,7 @@ bool WINAPI ReleaseMutex( HANDLE hMutex ) { bOk = true; if (--hMutex->RecursionCount == 0) { hMutex->OwningThread = 0;- SDL_SemPost(hMutex->m_hSem);+ hMutex->m_pSem->Post(); } } SDL_mutexV(hMutex->m_hMutex);diff --git a/xbmc/osx/Makefile b/xbmc/osx/Makefileindex f12cd4a..dfb26f5 100644--- a/xbmc/osx/Makefile+++ b/xbmc/osx/Makefile@@ -16,6 +16,7 @@ SRCS = \ ZeroconfBrowserOSX.cpp \ WinSystemOSX.mm \ WinSystemOSXGL.mm \+ SemaphoreDarwin.cpp LIB=osx.a diff --git a/xbmc/osx/SemaphoreDarwin.cpp b/xbmc/osx/SemaphoreDarwin.cppnew file mode 100644index 0000000..d902d45--- /dev/null+++ b/xbmc/osx/SemaphoreDarwin.cpp@@ -0,0 +1,70 @@++#include "SemaphoreDarwin.h"+#include <sys/stat.h>+#include <fcntl.h>+#define __STDC_FORMAT_MACROS+#include <inttypes.h>+#include <unistd.h>+#include <cerrno>+#include <climits>+#include <cstdio>+#include <ctime>+#include <CoreVideo/CVHostTime.h>++#define SEM_NAME_LEN (NAME_MAX-4)++CSemaphoreDarwin::CSemaphoreDarwin(uint32_t initialCount)+ : ISemaphore()+{+ m_szName = new char[SEM_NAME_LEN]; ++ snprintf(m_szName, SEM_NAME_LEN, "/xbmc-sem-%d-%" PRIu64,+ getpid(), CVGetCurrentHostTime());++ m_pSem = sem_open(m_szName, O_CREAT, 0600, initialCount);+}++CSemaphoreDarwin::~CSemaphoreDarwin()+{+ sem_close(m_pSem);+ sem_unlink(m_szName);+ delete [] m_szName;+}++bool CSemaphoreDarwin::Wait()+{+ return (0 == sem_wait(m_pSem));+}++SEM_GRAB CSemaphoreDarwin::TimedWait(uint32_t millis)+{+ uint64_t end = CVGetCurrentHostTime() + (millis * 1000000LL);+ do {+ if (0 == sem_trywait(m_pSem))+ return SEM_GRAB_SUCCESS;+ if (errno != EAGAIN)+ return SEM_GRAB_FAILED;+ usleep(1000);+ } while (CVGetCurrentHostTime() < end);++ return SEM_GRAB_TIMEOUT;+}++bool CSemaphoreDarwin::TryWait()+{+ return (0 == sem_trywait(m_pSem));+}++bool CSemaphoreDarwin::Post()+{+ return (0 == sem_post(m_pSem));+}++int CSemaphoreDarwin::GetCount() const+{+ int val;+ if (0 == sem_getvalue(m_pSem, &val))+ return val;+ return -1;+}+diff --git a/xbmc/osx/SemaphoreDarwin.h b/xbmc/osx/SemaphoreDarwin.hnew file mode 100644index 0000000..4cd517e--- /dev/null+++ b/xbmc/osx/SemaphoreDarwin.h@@ -0,0 +1,23 @@++#ifndef SEMAPHORE_DARWIN_H__+#define SEMAPHORE_DARWIN_H__++#include "ISemaphore.h"+#include <Semaphore.h>++class CSemaphoreDarwin : public ISemaphore+{+ char* m_szName;+ sem_t* m_pSem;+ public:+ CSemaphoreDarwin(uint32_t initialCount);+ virtual ~CSemaphoreDarwin();+ virtual bool Wait();+ virtual SEM_GRAB TimedWait(uint32_t millis);+ virtual bool TryWait();+ virtual bool Post();+ virtual int GetCount() const;+};++#endif // SEMAPHORE_DARWIN_H__+diff --git a/xbmc/posix/Makefile b/xbmc/posix/Makefilenew file mode 100644index 0000000..365cf32--- /dev/null+++ b/xbmc/posix/Makefile@@ -0,0 +1,11 @@+INCLUDES+= -I../utils++SRCS= \+ SemaphorePOSIX.cpp++LIB=posix.a++include ../../Makefile.include+-include $(patsubst %.cpp,%.P,$(patsubst %.c,%.P,$(SRCS)))++diff --git a/xbmc/posix/SemaphorePOSIX.cpp b/xbmc/posix/SemaphorePOSIX.cppnew file mode 100644index 0000000..b71a02c--- /dev/null+++ b/xbmc/posix/SemaphorePOSIX.cpp@@ -0,0 +1,75 @@++#include "SemaphorePOSIX.h"+#include <sys/stat.h>+#include <fcntl.h>+#define __STDC_FORMAT_MACROS+#include <inttypes.h>+#include <unistd.h>+#include <cerrno>+#include <climits>+#include <cstdio>+#include <ctime>++#define SEM_NAME_LEN (NAME_MAX-4)++CSemaphorePOSIX::CSemaphorePOSIX(uint32_t initialCount)+ : ISemaphore()+{+ struct timespec now = {};+ m_szName = new char[SEM_NAME_LEN];++ clock_gettime(CLOCK_MONOTONIC, &now);++ snprintf(m_szName, SEM_NAME_LEN, "/xbmc-sem-%d-%" PRIu64 "-%" PRIu64,+ getpid(), (uint64_t)now.tv_sec, (uint64_t)now.tv_nsec);++ m_pSem = sem_open(m_szName, O_CREAT, 0600, initialCount);+}++CSemaphorePOSIX::~CSemaphorePOSIX()+{+ sem_close(m_pSem);+ sem_unlink(m_szName);+ delete [] m_szName;+}++bool CSemaphorePOSIX::Wait()+{+ return (0 == sem_wait(m_pSem));+}++SEM_GRAB CSemaphorePOSIX::TimedWait(uint32_t millis)+{+ struct timespec to =+ {+ millis / 1000,+ (millis % 1000) * 1000000+ };++ if (0 == sem_timedwait(m_pSem, &to))+ return SEM_GRAB_SUCCESS;++ if (errno == ETIMEDOUT)+ return SEM_GRAB_TIMEOUT;++ return SEM_GRAB_FAILED;+}++bool CSemaphorePOSIX::TryWait()+{+ return (0 == sem_trywait(m_pSem));+}++bool CSemaphorePOSIX::Post()+{+ return (0 == sem_post(m_pSem));+}++int CSemaphorePOSIX::GetCount() const+{+ int val;+ if (0 == sem_getvalue(m_pSem, &val))+ return val;+ return -1;+}+diff --git a/xbmc/posix/SemaphorePOSIX.h b/xbmc/posix/SemaphorePOSIX.hnew file mode 100644index 0000000..02a24ec--- /dev/null+++ b/xbmc/posix/SemaphorePOSIX.h@@ -0,0 +1,23 @@++#ifndef SEMAPHORE_POSIX_H__+#define SEMAPHORE_POSIX_H__++#include "ISemaphore.h"+#include <semaphore.h>++class CSemaphorePOSIX : public ISemaphore+{+ char* m_szName;+ sem_t* m_pSem;+ public:+ CSemaphorePOSIX(uint32_t initialCount);+ virtual ~CSemaphorePOSIX();+ virtual bool Wait();+ virtual SEM_GRAB TimedWait(uint32_t millis);+ virtual bool TryWait();+ virtual bool Post();+ virtual int GetCount() const;+};++#endif // SEMAPHORE_POSIX_H__+diff --git a/xbmc/utils/ISemaphore.h b/xbmc/utils/ISemaphore.hnew file mode 100644index 0000000..a260640--- /dev/null+++ b/xbmc/utils/ISemaphore.h@@ -0,0 +1,27 @@++#ifndef ISEMAPHORE_H__+#define ISEMAPHORE_H__++#include <stdint.h>++enum SEM_GRAB+{+ SEM_GRAB_SUCCESS,+ SEM_GRAB_FAILED,+ SEM_GRAB_TIMEOUT+};++class ISemaphore+{+ public:+ ISemaphore() {}+ virtual ~ISemaphore() {}+ virtual bool Wait() = 0;+ virtual SEM_GRAB TimedWait(uint32_t millis) = 0;+ virtual bool TryWait() = 0;+ virtual bool Post() = 0;+ virtual int GetCount() const = 0;+};++#endif // ISEMAPHORE_H__+diff --git a/xbmc/utils/Makefile b/xbmc/utils/Makefileindex d208da2..77a6090 100644--- a/xbmc/utils/Makefile+++ b/xbmc/utils/Makefile@@ -1,4 +1,4 @@-INCLUDES=-I. -I.. -I../../ -I../linux -I../cores -I../../guilib+INCLUDES=-I. -I.. -I../../ -I../linux -I../cores -I../../guilib -I../posix SRCS=AlarmClock.cpp \ Archive.cpp \@@ -59,7 +59,8 @@ SRCS=AlarmClock.cpp \ Teletext.cpp \ fastmemcpy.cpp \ PasswordManager.cpp \- AliasShortcutUtils.cpp+ AliasShortcutUtils.cpp \+ Semaphore.cpp LIB=utils.a diff --git a/xbmc/utils/Semaphore.cpp b/xbmc/utils/Semaphore.cppnew file mode 100644index 0000000..0217a60--- /dev/null+++ b/xbmc/utils/Semaphore.cpp@@ -0,0 +1,62 @@++#include "Semaphore.h"+#ifdef __linux__+#include "SemaphorePOSIX.h"+#elif defined(__APPLE__)+#include "SemaphoreDarwin.h"+#endif++CSemaphore::CSemaphore(uint32_t initialCount/*=1*/)+ : ISemaphore()+{+#ifdef _SEMAPHORE_H+ m_pSemaphore = new CSemaphorePOSIX(initialCount);+#elif defined(_BSD_SEMAPHORE_H)+ m_pSemaphore = new CSemaphoreDarwin(initialCount);+#else+#error No supported semaphore implementation available+#endif+}++CSemaphore::CSemaphore(const CSemaphore& sem)+ : ISemaphore()+{+#ifdef _SEMAPHORE_H+ m_pSemaphore = new CSemaphorePOSIX(sem.GetCount());+#elif defined(_BSD_SEMAPHORE_H)+ m_pSemaphore = new CSemaphoreDarwin(initialCount);+#else+#error No supported semaphore implementation available+#endif+}++CSemaphore::~CSemaphore()+{+ delete m_pSemaphore;+}++bool CSemaphore::Wait()+{+ return m_pSemaphore->Wait();+}++SEM_GRAB CSemaphore::TimedWait(uint32_t millis)+{+ return m_pSemaphore->TimedWait(millis);+}++bool CSemaphore::TryWait()+{+ return m_pSemaphore->TryWait();+}++bool CSemaphore::Post()+{+ return m_pSemaphore->Post();+}++int CSemaphore::GetCount() const+{+ return m_pSemaphore->GetCount();+}+diff --git a/xbmc/utils/Semaphore.hpp b/xbmc/utils/Semaphore.hppnew file mode 100644index 0000000..47214dc--- /dev/null+++ b/xbmc/utils/Semaphore.hpp@@ -0,0 +1,22 @@++#ifndef SEMAPHORE_H__+#define SEMAPHORE_H__++#include "ISemaphore.h"++class CSemaphore : public ISemaphore+{+ ISemaphore* m_pSemaphore;+ public:+ CSemaphore(uint32_t initialCount=1);+ CSemaphore(const CSemaphore& sem);+ virtual ~CSemaphore();+ virtual bool Wait();+ virtual SEM_GRAB TimedWait(uint32_t millis);+ virtual bool TryWait();+ virtual bool Post();+ virtual int GetCount() const;+};++#endif // SEMAPHORE_H__+