Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
project(KodiThreads)

set(SOURCES KodiThreads/threads/Atomics.cpp
KodiThreads/threads/Event.cpp
KodiThreads/threads/Thread.cpp
KodiThreads/threads/Timer.cpp
KodiThreads/threads/SystemClock.cpp
KodiThreads/commons/Exception.cpp
KodiThreads/system.cpp)

set(HEADERS KodiThreads/threads/platform/Implementation.cpp

KodiThreads/threads/Atomics.h
KodiThreads/threads/Condition.h
KodiThreads/threads/CriticalSection.h
KodiThreads/threads/Event.h
KodiThreads/threads/Helpers.h
KodiThreads/threads/Lockables.h
KodiThreads/threads/MipsAtomics.h
KodiThreads/threads/SharedSection.h
KodiThreads/threads/SingleLock.h
KodiThreads/threads/SystemClock.h
KodiThreads/threads/Thread.h
KodiThreads/threads/ThreadImpl.h
KodiThreads/threads/ThreadLocal.h
KodiThreads/threads/Timer.h
KodiThreads/threads/platform/Condition.h
KodiThreads/threads/platform/CriticalSection.h
KodiThreads/threads/platform/ThreadImpl.h
KodiThreads/threads/platform/ThreadLocal.h

KodiThreads/system.h
KodiThreads/commons/Exception.h)

include_directories(${p8-platform_INCLUDE_DIRS})

if(MSVC)
list(APPEND SOURCES KodiThreads/threads/platform/win/Win32Exception.cpp)
list(APPEND HEADERS KodiThreads/threads/platform/win/Win32Exception.h)
endif()

addon_source_group("${SOURCES}")
addon_source_group("${HEADERS}")

add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
add_library(kodi::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/KodiThreads
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/KodiThreads>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
if(MSVC)
target_link_libraries(${PROJECT_NAME} PUBLIC winmm.lib)
endif()

# install all specific module files
install(TARGETS ${PROJECT_NAME} EXPORT kodi DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
27 changes: 27 additions & 0 deletions KodiThreads/commons/Exception.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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
* 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, see
* <http://www.gnu.org/licenses/>.
*
*/

#include "Exception.h"

namespace XbmcCommons
{
Exception::~Exception() {}
}

121 changes: 121 additions & 0 deletions KodiThreads/commons/Exception.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* 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
* 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, see
* <http://www.gnu.org/licenses/>.
*
*/

#pragma once

#include <string>
#include <stdarg.h>
#include "system.h"

#ifdef __GNUC__
// The 'this' pointer counts as a parameter on member methods.
#define XBMCCOMMONS_ATTRIB_EXCEPTION_FORMAT __attribute__((format(printf,2,3)))
#else
#define XBMCCOMMONS_ATTRIB_EXCEPTION_FORMAT
#endif

#define XBMCCOMMONS_COPYVARARGS(fmt) va_list argList; va_start(argList, fmt); Set(fmt, argList); va_end(argList)
#define XBMCCOMMONS_STANDARD_EXCEPTION(E) \
class E : public XbmcCommons::Exception \
{ \
public: \
inline E(const char* message,...) XBMCCOMMONS_ATTRIB_EXCEPTION_FORMAT : Exception(#E) { XBMCCOMMONS_COPYVARARGS(message); } \
\
inline E(const E& other) : Exception(other) {} \
}

namespace XbmcCommons
{
/**
* This class a superclass for exceptions that want to utilize some
* utility functionality including autologging with the specific
* exception name.
*/
class Exception
{
private:

std::string classname;
std::string message;

protected:

inline Exception(const char* classname_) : classname(classname_) { }
inline Exception(const char* classname_, const char* message_) : classname(classname_), message(message_) { }
inline Exception(const Exception& other) : classname(other.classname), message(other.message) { }

/**
* This method is called from the constructor of subclasses. It
* will set the message from varargs as well as call log message
*/
inline void Set(const char* fmt, va_list& argList)
{
message = StringUtils::FormatV(fmt, argList);
}

/**
* This message can be called from the constructor of subclasses.
* It will set the message and log the throwing.
*/
inline void SetMessage(const char* fmt, ...) XBMCCOMMONS_ATTRIB_EXCEPTION_FORMAT
{
// calls 'set'
XBMCCOMMONS_COPYVARARGS(fmt);
}

inline void setClassname(const char* cn) { classname = cn; }

public:
virtual ~Exception();

inline virtual void LogThrowMessage(const char* prefix = NULL) const
{
LOG(LOGERROR, "EXCEPTION Thrown (%s) : %s", classname.c_str(), message.c_str());
}

inline virtual const char* GetMessage() const { return message.c_str(); }
};

/**
* This class forms the base class for unchecked exceptions. Unchecked exceptions
* are those that really shouldn't be handled explicitly. For example, on windows
* when a access violaton is converted to a win32_exception, there's nothing
* that can be done in most code. The outer most stack frame might try to
* do some error logging prior to shutting down, but that's really it.
*/
XBMCCOMMONS_STANDARD_EXCEPTION(UncheckedException);

/**
* In cases where you catch(...){} you will (may) inadvertently be
* catching UncheckedException's. Therefore this macro will allow
* you to do something equivalent to:
* catch (anything except UncheckedException) {}
*
* In order to avoid catching UncheckedException, use the macro as follows:
*
* try { ... }
* XBMCCOMMONS_HANDLE_UNCHECKED
* catch(...){ ... }
*/
// Yes. I recognize that the name of this macro is an oxymoron.
#define XBMCCOMMONS_HANDLE_UNCHECKED \
catch (const XbmcCommons::UncheckedException& ) { throw; } \
catch (const XbmcCommons::UncheckedException* ) { throw; }
}
57 changes: 57 additions & 0 deletions KodiThreads/system.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2005-2016 Team KODI
* http://kodi.tv
*
* 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 Kodi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/



#include "system.h"
#include "threads/CriticalSection.h"
#include "threads/SingleLock.h"

static CCriticalSection loc_CriticalSection;
static LogCallback_t loc_LoggerCallback;

int g_LOGERROR;
int g_LOGDEBUG;
int g_LOGINFO;
int g_LOGNOTICE;


void KodiThreadsLogger(int LogLevel, const char *format, ...)
{
CSingleLock lock(loc_CriticalSection);

if (loc_LoggerCallback)
{
}
}

void SetKodiThreadsLogger(LogCallback_t LoggerCallback)
{
CSingleLock lock(loc_CriticalSection);

loc_LoggerCallback = LoggerCallback;
}

void ReleaseKodiThreadsLogger()
{
CSingleLock lock(loc_CriticalSection);

loc_LoggerCallback = nullptr;
}
42 changes: 42 additions & 0 deletions KodiThreads/system.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

/*
* Copyright (C) 2005-2016 Team KODI
* http://kodi.tv
*
* 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 Kodi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/



#include <util/StringUtils.h>

extern int g_LOGERROR;
extern int g_LOGDEBUG;
extern int g_LOGINFO;
extern int g_LOGNOTICE;

typedef void (*LogCallback_t)(int loglevel, const char *format, ...);

void KodiThreadsLogger(int LogLevel, const char *format, ...);
void SetKodiThreadsLogger(LogCallback_t LoggerCallback);
void ReleaseKodiThreadsLogger();

#define LOG KodiThreadsLogger
#define LOGERROR g_LOGERROR
#define LOGDEBUG g_LOGDEBUG
#define LOGINFO g_LOGINFO
#define LOGNOTICE g_LOGNOTICE
Loading