aboutsummaryrefslogtreecommitdiffstats
path: root/common/core
diff options
context:
space:
mode:
Diffstat (limited to 'common/core')
-rw-r--r--common/core/CMakeLists.txt4
-rw-r--r--common/core/Configuration.cxx4
-rw-r--r--common/core/Configuration.h2
-rw-r--r--common/core/Mutex.cxx157
-rw-r--r--common/core/Mutex.h64
-rw-r--r--common/core/Thread.cxx172
-rw-r--r--common/core/Thread.h58
-rw-r--r--common/core/string.cxx3
8 files changed, 9 insertions, 455 deletions
diff --git a/common/core/CMakeLists.txt b/common/core/CMakeLists.txt
index 1932e5db..7e58acc0 100644
--- a/common/core/CMakeLists.txt
+++ b/common/core/CMakeLists.txt
@@ -5,10 +5,8 @@ add_library(core STATIC
Logger_file.cxx
Logger_stdio.cxx
LogWriter.cxx
- Mutex.cxx
Region.cxx
Timer.cxx
- Thread.cxx
string.cxx
time.cxx
xdgdirs.cxx)
@@ -16,11 +14,9 @@ add_library(core STATIC
target_include_directories(core PUBLIC ${CMAKE_SOURCE_DIR}/common)
target_include_directories(core SYSTEM PUBLIC ${PIXMAN_INCLUDE_DIRS})
target_link_libraries(core ${PIXMAN_LIBRARIES})
-target_link_directories(core PUBLIC ${PIXMAN_LIBRARY_DIRS})
if(UNIX)
target_sources(core PRIVATE Logger_syslog.cxx)
- target_link_libraries(core pthread)
endif()
if(WIN32)
diff --git a/common/core/Configuration.cxx b/common/core/Configuration.cxx
index 129d1b9e..e6affb06 100644
--- a/common/core/Configuration.cxx
+++ b/common/core/Configuration.cxx
@@ -570,6 +570,10 @@ bool ListParameter<ValueType>::setParam(const char* v)
entry.erase(0, entry.find_first_not_of(" \f\n\r\t\v"));
entry.erase(entry.find_last_not_of(" \f\n\r\t\v")+1);
+ // Special case, entire v was just whitespace
+ if (entry.empty() && (entries.size() == 1))
+ break;
+
if (!decodeEntry(entry.c_str(), &e)) {
vlog.error("List parameter %s: Invalid value '%s'",
getName(), entry.c_str());
diff --git a/common/core/Configuration.h b/common/core/Configuration.h
index 57bc48e1..431dd0c5 100644
--- a/common/core/Configuration.h
+++ b/common/core/Configuration.h
@@ -86,6 +86,8 @@ namespace core {
std::list<VoidParameter*>::iterator begin() { return params.begin(); }
std::list<VoidParameter*>::iterator end() { return params.end(); }
+ // - Returns the number of parameters
+ int size() { return params.size(); }
// - Get the Global Configuration object
// NB: This call does NOT lock the Configuration system.
diff --git a/common/core/Mutex.cxx b/common/core/Mutex.cxx
deleted file mode 100644
index 6f72581e..00000000
--- a/common/core/Mutex.cxx
+++ /dev/null
@@ -1,157 +0,0 @@
-/* Copyright 2015 Pierre Ossman for Cendio AB
- *
- * This 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 of the License, or
- * (at your option) any later version.
- *
- * This software 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 this software; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
- * USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef WIN32
-#include <windows.h>
-#else
-#include <pthread.h>
-#endif
-
-#include <core/Exception.h>
-#include <core/Mutex.h>
-
-using namespace core;
-
-Mutex::Mutex()
-{
-#ifdef WIN32
- systemMutex = new CRITICAL_SECTION;
- InitializeCriticalSection((CRITICAL_SECTION*)systemMutex);
-#else
- int ret;
-
- systemMutex = new pthread_mutex_t;
- ret = pthread_mutex_init((pthread_mutex_t*)systemMutex, nullptr);
- if (ret != 0)
- throw posix_error("Failed to create mutex", ret);
-#endif
-}
-
-Mutex::~Mutex()
-{
-#ifdef WIN32
- DeleteCriticalSection((CRITICAL_SECTION*)systemMutex);
- delete (CRITICAL_SECTION*)systemMutex;
-#else
- pthread_mutex_destroy((pthread_mutex_t*)systemMutex);
- delete (pthread_mutex_t*)systemMutex;
-#endif
-}
-
-void Mutex::lock()
-{
-#ifdef WIN32
- EnterCriticalSection((CRITICAL_SECTION*)systemMutex);
-#else
- int ret;
-
- ret = pthread_mutex_lock((pthread_mutex_t*)systemMutex);
- if (ret != 0)
- throw posix_error("Failed to lock mutex", ret);
-#endif
-}
-
-void Mutex::unlock()
-{
-#ifdef WIN32
- LeaveCriticalSection((CRITICAL_SECTION*)systemMutex);
-#else
- int ret;
-
- ret = pthread_mutex_unlock((pthread_mutex_t*)systemMutex);
- if (ret != 0)
- throw posix_error("Failed to unlock mutex", ret);
-#endif
-}
-
-Condition::Condition(Mutex* mutex_)
-{
- this->mutex = mutex_;
-
-#ifdef WIN32
- systemCondition = new CONDITION_VARIABLE;
- InitializeConditionVariable((CONDITION_VARIABLE*)systemCondition);
-#else
- int ret;
-
- systemCondition = new pthread_cond_t;
- ret = pthread_cond_init((pthread_cond_t*)systemCondition, nullptr);
- if (ret != 0)
- throw posix_error("Failed to create condition variable", ret);
-#endif
-}
-
-Condition::~Condition()
-{
-#ifdef WIN32
- delete (CONDITION_VARIABLE*)systemCondition;
-#else
- pthread_cond_destroy((pthread_cond_t*)systemCondition);
- delete (pthread_cond_t*)systemCondition;
-#endif
-}
-
-void Condition::wait()
-{
-#ifdef WIN32
- BOOL ret;
-
- ret = SleepConditionVariableCS((CONDITION_VARIABLE*)systemCondition,
- (CRITICAL_SECTION*)mutex->systemMutex,
- INFINITE);
- if (!ret)
- throw win32_error("Failed to wait on condition variable", GetLastError());
-#else
- int ret;
-
- ret = pthread_cond_wait((pthread_cond_t*)systemCondition,
- (pthread_mutex_t*)mutex->systemMutex);
- if (ret != 0)
- throw posix_error("Failed to wait on condition variable", ret);
-#endif
-}
-
-void Condition::signal()
-{
-#ifdef WIN32
- WakeConditionVariable((CONDITION_VARIABLE*)systemCondition);
-#else
- int ret;
-
- ret = pthread_cond_signal((pthread_cond_t*)systemCondition);
- if (ret != 0)
- throw posix_error("Failed to signal condition variable", ret);
-#endif
-}
-
-void Condition::broadcast()
-{
-#ifdef WIN32
- WakeAllConditionVariable((CONDITION_VARIABLE*)systemCondition);
-#else
- int ret;
-
- ret = pthread_cond_broadcast((pthread_cond_t*)systemCondition);
- if (ret != 0)
- throw posix_error("Failed to broadcast condition variable", ret);
-#endif
-}
diff --git a/common/core/Mutex.h b/common/core/Mutex.h
deleted file mode 100644
index 17a97d1b..00000000
--- a/common/core/Mutex.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/* Copyright 2015 Pierre Ossman for Cendio AB
- *
- * This 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 of the License, or
- * (at your option) any later version.
- *
- * This software 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 this software; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
- * USA.
- */
-
-#ifndef __CORE_MUTEX_H__
-#define __CORE_MUTEX_H__
-
-namespace core {
- class Condition;
-
- class Mutex {
- public:
- Mutex();
- ~Mutex();
-
- void lock();
- void unlock();
-
- private:
- friend class Condition;
-
- void* systemMutex;
- };
-
- class AutoMutex {
- public:
- AutoMutex(Mutex* mutex) { m = mutex; m->lock(); }
- ~AutoMutex() { m->unlock(); }
- private:
- Mutex* m;
- };
-
- class Condition {
- public:
- Condition(Mutex* mutex);
- ~Condition();
-
- void wait();
-
- void signal();
- void broadcast();
-
- private:
- Mutex* mutex;
- void* systemCondition;
- };
-
-}
-
-#endif
diff --git a/common/core/Thread.cxx b/common/core/Thread.cxx
deleted file mode 100644
index be518cd4..00000000
--- a/common/core/Thread.cxx
+++ /dev/null
@@ -1,172 +0,0 @@
-/* Copyright 2015 Pierre Ossman for Cendio AB
- *
- * This 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 of the License, or
- * (at your option) any later version.
- *
- * This software 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 this software; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
- * USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef WIN32
-#include <windows.h>
-#else
-#include <pthread.h>
-#include <signal.h>
-#include <unistd.h>
-#endif
-
-#include <core/Exception.h>
-#include <core/Mutex.h>
-#include <core/Thread.h>
-
-using namespace core;
-
-Thread::Thread() : running(false), threadId(nullptr)
-{
- mutex = new Mutex;
-
-#ifdef WIN32
- threadId = new HANDLE;
-#else
- threadId = new pthread_t;
-#endif
-}
-
-Thread::~Thread()
-{
-#ifdef WIN32
- delete (HANDLE*)threadId;
-#else
- if (isRunning())
- pthread_cancel(*(pthread_t*)threadId);
- delete (pthread_t*)threadId;
-#endif
-
- delete mutex;
-}
-
-void Thread::start()
-{
- AutoMutex a(mutex);
-
-#ifdef WIN32
- *(HANDLE*)threadId = CreateThread(nullptr, 0, startRoutine, this, 0, nullptr);
- if (*(HANDLE*)threadId == nullptr)
- throw win32_error("Failed to create thread", GetLastError());
-#else
- int ret;
- sigset_t all, old;
-
- // Creating threads from libraries is a bit evil, so mitigate the
- // issue by at least avoiding signals on these threads
- sigfillset(&all);
- ret = pthread_sigmask(SIG_SETMASK, &all, &old);
- if (ret != 0)
- throw posix_error("Failed to mask signals", ret);
-
- ret = pthread_create((pthread_t*)threadId, nullptr, startRoutine, this);
-
- pthread_sigmask(SIG_SETMASK, &old, nullptr);
-
- if (ret != 0)
- throw posix_error("Failed to create thread", ret);
-#endif
-
- running = true;
-}
-
-void Thread::wait()
-{
- if (!isRunning())
- return;
-
-#ifdef WIN32
- DWORD ret;
-
- ret = WaitForSingleObject(*(HANDLE*)threadId, INFINITE);
- if (ret != WAIT_OBJECT_0)
- throw win32_error("Failed to join thread", GetLastError());
-#else
- int ret;
-
- ret = pthread_join(*(pthread_t*)threadId, nullptr);
- if (ret != 0)
- throw posix_error("Failed to join thread", ret);
-#endif
-}
-
-bool Thread::isRunning()
-{
- AutoMutex a(mutex);
-
- return running;
-}
-
-size_t Thread::getSystemCPUCount()
-{
-#ifdef WIN32
- SYSTEM_INFO si;
- size_t count;
- DWORD mask;
-
- GetSystemInfo(&si);
-
- count = 0;
- for (mask = si.dwActiveProcessorMask;mask != 0;mask >>= 1) {
- if (mask & 0x1)
- count++;
- }
-
- if (count > si.dwNumberOfProcessors)
- count = si.dwNumberOfProcessors;
-
- return count;
-#else
- long ret;
-
- ret = sysconf(_SC_NPROCESSORS_ONLN);
- if (ret == -1)
- return 0;
-
- return ret;
-#endif
-}
-
-#ifdef WIN32
-long unsigned __stdcall Thread::startRoutine(void* data)
-#else
-void* Thread::startRoutine(void* data)
-#endif
-{
- Thread *self;
-
- self = (Thread*)data;
-
- try {
- self->worker();
- } catch(...) {
- }
-
- self->mutex->lock();
- self->running = false;
- self->mutex->unlock();
-
-#ifdef WIN32
- return 0;
-#else
- return nullptr;
-#endif
-}
diff --git a/common/core/Thread.h b/common/core/Thread.h
deleted file mode 100644
index 53c5ef18..00000000
--- a/common/core/Thread.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/* Copyright 2015 Pierre Ossman for Cendio AB
- *
- * This 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 of the License, or
- * (at your option) any later version.
- *
- * This software 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 this software; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
- * USA.
- */
-
-#ifndef __CORE_THREAD_H__
-#define __CORE_THREAD_H__
-
-#include <stddef.h>
-
-namespace core {
- class Mutex;
-
- class Thread {
- public:
- Thread();
- virtual ~Thread();
-
- void start();
- void wait();
-
- bool isRunning();
-
- public:
- static size_t getSystemCPUCount();
-
- protected:
- virtual void worker() = 0;
-
- private:
-#ifdef WIN32
- static long unsigned __stdcall startRoutine(void* data);
-#else
- static void* startRoutine(void* data);
-#endif
-
- private:
- Mutex *mutex;
- bool running;
-
- void *threadId;
- };
-}
-
-#endif
diff --git a/common/core/string.cxx b/common/core/string.cxx
index 49501a9f..091836db 100644
--- a/common/core/string.cxx
+++ b/common/core/string.cxx
@@ -64,6 +64,9 @@ namespace core {
std::vector<std::string> out;
const char *start, *stop;
+ if (src[0] == '\0')
+ return out;
+
start = src;
do {
stop = strchr(start, delimiter);