00001 /* -*- mode: c++; indent-tabs-mode: nil -*- */ 00002 /* 00003 qore_thread.h 00004 00005 POSIX thread library for Qore 00006 00007 Qore Programming Language 00008 00009 Copyright 2003 - 2010 David Nichols 00010 00011 This library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU Lesser General Public 00013 License as published by the Free Software Foundation; either 00014 version 2.1 of the License, or (at your option) any later version. 00015 00016 This library is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 Lesser General Public License for more details. 00020 00021 You should have received a copy of the GNU Lesser General Public 00022 License along with this library; if not, write to the Free Software 00023 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 */ 00025 00026 #ifndef _QORE_QORE_THREAD_H 00027 #define _QORE_QORE_THREAD_H 00028 00033 #include <stdio.h> 00034 #include <pthread.h> 00035 00036 class QoreProgram; 00037 class AbstractQoreZoneInfo; 00038 class ThreadCleanupNode; 00039 class AbstractThreadResource; 00040 00042 typedef void (*qtdest_t)(void *); 00043 00045 typedef void (*qtrdest_t)(void *, ExceptionSink *); 00046 00048 DLLEXPORT bool is_valid_qore_thread(); 00049 00051 DLLEXPORT int gettid(); 00052 00054 DLLEXPORT QoreProgram *getProgram(); 00055 00057 DLLEXPORT const AbstractQoreZoneInfo *currentTZ(); 00058 00060 00062 DLLEXPORT void set_thread_resource(AbstractThreadResource *atr); 00063 00065 00068 DLLEXPORT int remove_thread_resource(AbstractThreadResource *atr); 00069 00071 00078 class ThreadCleanupList { 00079 private: 00080 static ThreadCleanupNode *head; 00081 00082 public: 00083 DLLLOCAL ThreadCleanupList(); 00084 DLLLOCAL ~ThreadCleanupList(); 00085 DLLLOCAL void exec(); 00086 00088 00091 DLLEXPORT void push(qtdest_t func, void *arg); 00092 00094 00096 DLLEXPORT void pop(bool exec = true); 00097 }; 00098 00100 DLLEXPORT extern ThreadCleanupList tclist; 00101 00102 #endif // ifndef _QORE_THREAD_H