/*
- * Copyright (C) 2005-2008 Team XBMC
- * http://www.xbmc.org
+ * Copyright (C) 2005-2013 Team XBMC
+ * http://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
* 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
+ * along with XBMC; see the file COPYING. If not, see
+ * <http://www.gnu.org/licenses/>.
*
*/
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);
- int GetPriority(void);
- int GetMinPriority(void);
- int GetMaxPriority(void);
- int GetNormalPriority(void);
int GetSchedRRPriority(void);
bool SetPrioritySched_RR(int iPriority);
bool IsAutoDelete() const;
virtual void StopThread(bool bWait = true);
+ bool IsRunning() const;
+
+ // -----------------------------------------------------------------------------------
+ // These are platform specific and can be found in ./platform/[platform]/ThreadImpl.cpp
+ // -----------------------------------------------------------------------------------
+ bool IsCurrentThread() const;
+ int GetMinPriority(void);
+ int GetMaxPriority(void);
+ int GetNormalPriority(void);
+ int GetPriority(void);
+ bool SetPriority(const int iPriority);
+ bool WaitForThreadExit(unsigned int milliseconds);
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 inline void SetLogger(XbmcCommons::ILogger* logger_) { CThread::logger = logger_; }
+ static inline XbmcCommons::ILogger* GetLogger() { return CThread::logger; }
+
+ virtual void OnException(){} // signal termination handler
protected:
virtual void OnStartup(){};
virtual void OnExit(){};
- virtual void OnException(){} // signal termination handler
virtual void Process();
volatile bool m_bStop;
/**
* This call will wait on a CEvent in an interruptible way such that if
- * stop is called on the thread the wait will return with a respone
+ * stop is called on the thread the wait will return with a response
* indicating what happened.
*/
- inline WaitResponse AbortableWait(CEvent& event, int timeoutMillis)
- {
- XbmcThreads::CEventGroup group(&event, &m_StopEvent, NULL);
- CEvent* result = group.wait(timeoutMillis);
- return result == &event ? WAIT_SIGNALED :
- (result == NULL ? WAIT_TIMEDOUT : WAIT_INTERRUPTED);
- }
-
- inline WaitResponse AbortableWait(CEvent& event)
+ inline WaitResponse AbortableWait(CEvent& event, int timeoutMillis = -1 /* indicates wait forever*/)
{
XbmcThreads::CEventGroup group(&event, &m_StopEvent, NULL);
- CEvent* result = group.wait();
+ CEvent* result = timeoutMillis < 0 ? group.wait() : group.wait(timeoutMillis);
return result == &event ? WAIT_SIGNALED :
(result == NULL ? WAIT_TIMEDOUT : WAIT_INTERRUPTED);
}
private:
static THREADFUNC staticThread(void *data);
+ void Action();
+
+ // -----------------------------------------------------------------------------------
+ // These are platform specific and can be found in ./platform/[platform]/ThreadImpl.cpp
+ // -----------------------------------------------------------------------------------
ThreadIdentifier ThreadId() const;
void SetThreadInfo();
void TermHandler();
+ void SetSignalHandlers();
+ void SpawnThread(unsigned stacksize);
+ // -----------------------------------------------------------------------------------
ThreadIdentifier m_ThreadId;
ThreadOpaque m_ThreadOpaque;
float m_fLastUsage;
std::string m_ThreadName;
-
-#ifdef __APPLE__
- // Save the Mach thrad port, I don't think it can be obtained from
- // the pthread_t. We'll use it for querying timer information.
- //
- mach_port_t m_machThreadPort;
-#endif
-
};