All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
qore_thread.h
Go to the documentation of this file.
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
qore_thread.h
POSIX thread library for Qore
Qore Programming Language
Copyright 2003 - 2013 David Nichols
This library is free software; you can redistribute it and/or
modify it under the terms of the 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 along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _QORE_QORE_THREAD_H
#define _QORE_QORE_THREAD_H
#include <stdio.h>
#include <pthread.h>
class QoreProgram;
class AbstractQoreZoneInfo;
class ThreadCleanupNode;
class AbstractThreadResource;
typedef void (*qtdest_t)(void *);
typedef void (*qtrdest_t)(void *, ExceptionSink *);
DLLEXPORT bool is_valid_qore_thread();
DLLEXPORT int gettid();
DLLEXPORT QoreProgram *getProgram();
DLLEXPORT const AbstractQoreZoneInfo *currentTZ();
DLLEXPORT void set_thread_resource(AbstractThreadResource *atr);
DLLEXPORT int remove_thread_resource(AbstractThreadResource *atr);
DLLEXPORT void set_thread_resource_id(q_trid_t trid, AbstractThreadResource *atr);
DLLEXPORT int remove_thread_resource_id(q_trid_t trid);
DLLEXPORT bool check_thread_resource_id(q_trid_t trid);
DLLEXPORT q_trid_t qore_get_trid();
class ThreadCleanupList {
private:
static ThreadCleanupNode *head;
public:
DLLLOCAL ThreadCleanupList();
DLLLOCAL ~ThreadCleanupList();
DLLLOCAL void exec();
DLLEXPORT void push(qtdest_t func, void *arg);
DLLEXPORT void pop(bool exec = true);
};
DLLEXPORT extern ThreadCleanupList tclist;
#define QFT_OK 0
#define QFT_ERROR -1
#define QFT_REGISTERED -2
DLLEXPORT int q_register_foreign_thread();
DLLEXPORT int q_deregister_foreign_thread();
DLLEXPORT int q_reserve_foreign_thread_id();
DLLEXPORT int q_release_reserved_foreign_thread_id(int tid);
DLLEXPORT int q_register_reserved_foreign_thread(int tid);
DLLEXPORT int q_deregister_reserved_foreign_thread();
class QoreForeignThreadHelper {
private:
DLLLOCAL QoreForeignThreadHelper& operator=(const QoreForeignThreadHelper&);
DLLLOCAL QoreForeignThreadHelper(const QoreForeignThreadHelper&);
DLLLOCAL void* operator new(size_t);
protected:
class qore_foreign_thread_priv* priv;
public:
DLLEXPORT QoreForeignThreadHelper();
DLLEXPORT explicit QoreForeignThreadHelper(int tid);
DLLEXPORT ~QoreForeignThreadHelper();
};
#endif // ifndef _QORE_THREAD_H