[Rtk-cvs] rtk/src/core/platform/linux CMakeLists.txt,NONE,1.1 Mutex.cpp,NONE,1.1 Thread.cpp,NONE,1.1
From: <le...@us...> - 2004-03-05 18:40:34
|
Update of /cvsroot/rtk/rtk/src/core/platform/linux In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28229 Added Files: CMakeLists.txt Mutex.cpp Thread.cpp Log Message: Linux Mutex and Thread implementations added to RTK CVS repository. NOTE: CMake build system is still not good - i have to learn how to add stuff to RTK CORE library, which is in .. --- NEW FILE: CMakeLists.txt --- ## # # RTK # Fast and easy cross-platform GUI ToolKit. # # Copyright (C) 2001-200x RTK Development Team # # This library is free software; you can redistribute it and/or modify it # under the terms of the slightly modified (see the "EXCEPTION NOTICE" part # of RTK Library License) GNU Lesser General Public License as published # by the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # This library 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 Lesser General Public # License for more details. # # You should have received a copy of the GNU Lesser General Public License # and along with this library; if not, write to the # Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA . # # Also you should have received a copy of RTK Library License, if not please # write an e-mail to some of RTK authors (listed in file AUTHORS). # # Bug reports: bu...@rt... # Suggestions: rf...@rt... # # Authors (chronological order): # Dejan Lekic , de...@nu... # Contributors # N/A #################################################################### ##------------------------------------------------------------------- # Here we define all platform/linux core RTK files # - It's IMHO (Dejan) handy to have them in one variable # SET(RTK_CORE_LINUX_SFILES Thread.cpp Mutex.cpp) # Now we can put 'em in main RTK_CORE_SFILES variable SET(RTK_CORE_SFILES ${RTK_CORE_SFILES} ${RTK_CORE_LINUX_SFILES}) ADD_LIBRARY(${RTK_LIBRTK} STATIC ${RTK_CORE_LINUX_SFILES}) MESSAGE("### ${RTK_CORE_SFILES}") ##------------------------------------------------------------------- # LOG # IF (RTK_OPT_BCLOG) WRITE_FILE(${RTK_BC_LOGFILE} "was in /src/core/platform/linux\n" APPEND) ENDIF (RTK_OPT_BCLOG) ## # $Id: CMakeLists.txt,v 1.1 2004/03/05 18:18:25 leka Exp $ #################################################################### --- NEW FILE: Mutex.cpp --- /** * * RTK * Fast and easy cross-platform GUI ToolKit. * * Copyright (C) 2001-200x RTK Development Team * * This library is free software; you can redistribute it and/or modify it * under the terms of the slightly modified (see the "EXCEPTION NOTICE" part * of RTK Library License) GNU Lesser General Public License as published * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library 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 Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License * and along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA . * * Also you should have received a copy of RTK Library License, if not please * write an e-mail to some of RTK authors (listed in file AUTHORS). * * Bug reports: bu...@rt... * Suggestions: rf...@rt... ***************************************************************************/ /** * $Source: /cvsroot/rtk/rtk/src/core/platform/linux/Mutex.cpp,v $ ***** * Authors (chronological order): * Mikko Lahteenmaki, mikko§rtk.cx * Dejan Lekic, dejan§rtk.cx * Contributors (chronological order): * $fname $lname, $email ***** * T0D0 List: * - ***************************************************************************/ #include <rtk/Mutex.h> namespace Rtk { // Linux supports recursive locks, use them directly, with some cheating: #ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP extern pthread_mutexattr_t Mutex_attrib; void Mutex::Init() { pthread_mutex_init(&_cs, &Mutex_attrib); } void Mutex::Lock() { pthread_mutex_lock(&_cs); } void Mutex::Unlock() { pthread_mutex_unlock(&_cs); } #else // standard pthread mutexes need a bit of work to be recursive: void Mutex::Init() { recursive_counter = 0; pthread_mutex_init(&_cs, NULL); } void Mutex::Lock() { if(!recursive_counter || owner_ != pthread_self()) { pthread_mutex_lock(&_cs); owner_ = pthread_self(); } recursive_counter++; } void Mutex::Unlock() { if (!--recursive_counter) pthread_mutex_unlock(&_cs); } // unlock() #endif void Mutex::Destroy() { pthread_mutex_destroy(&_cs); } // destroy() }; // Rtk /** * $Id: Mutex.cpp,v 1.1 2004/03/05 18:18:25 leka Exp $ ***************************************************************************/ --- NEW FILE: Thread.cpp --- /** * * RTK * Fast and easy cross-platform GUI ToolKit. * * Copyright (C) 2001-200x RTK Development Team * * This library is free software; you can redistribute it and/or modify it * under the terms of the slightly modified (see the "EXCEPTION NOTICE" part * of RTK Library License) GNU Lesser General Public License as published * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library 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 Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License * and along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA . * * Also you should have received a copy of RTK Library License, if not please * write an e-mail to some of RTK authors (listed in file AUTHORS). * * Bug reports: bu...@rt... * Suggestions: rf...@rt... ***************************************************************************/ /** * $Source: /cvsroot/rtk/rtk/src/core/platform/linux/Thread.cpp,v $ ***** * Authors (chronological order): * Mikko Lahteenmaki, mikko§rtk.cx * Dejan Lekic, dejan§rtk.cx * Contributors (chronological order): * $fname $lname, $email ***** * T0D0 List: * - ***************************************************************************/ #include <rtk/Thread.h> namespace Rtk { void* thread_function(void *arg) { Thread *t = (Thread*)arg; ThreadFunction func = t->GetFunction(); void *f_arg = t->GetUserdata(); t->_running = true; int ret = 0; if(!func) { while(t->ThreadStep()); } else { ret = (*func)(f_arg); } t->_running = false; return (void*)ret; } bool Thread::Create(ThreadFunction function, void* arg) { bool result = true; _function = function; _arg = arg; _kill_thread = _running = 0; if (pthread_create((pthread_t*)(_thread_handle), NULL, thread_function, this)) result = false; return result; } void Thread::Terminate(int exitcode) { pthread_cancel(*((pthread_t*)(_thread_handle))); } bool Thread::Join(int timeout) { void *result; return (bool)pthread_join(*((pthread_t*)(_thread_handle)), &result); } int Thread::GetPriority() const { return 0; } int Thread::SetPriority(int priority) { return 0; } }; // Rtk /** * $Id: Thread.cpp,v 1.1 2004/03/05 18:18:25 leka Exp $ ***************************************************************************/ |