All Classes Namespaces 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 (C) 2003 - 2017 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#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 *);
typedef void (*q_thread_t)(ExceptionSink* xsink, void* arg);
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 bool check_thread_resource(AbstractThreadResource* atr);
DLLEXPORT void set_thread_resource(const ResolvedCallReferenceNode* rcr, QoreValue arg);
DLLEXPORT int remove_thread_resource(const ResolvedCallReferenceNode* rcr, ExceptionSink* xsink);
#if 0
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);
#endif
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();
int q_start_thread(ExceptionSink* xsink, q_thread_t f, void* arg = 0);
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
AbstractThreadResource
base class for saving data using Qore&#39;s thread resource management system
Definition: AbstractThreadResource.h:51
q_reserve_foreign_thread_id
DLLEXPORT int q_reserve_foreign_thread_id()
reserves a thread ID for later registration and returns the TID reserved; use q_release_reserved_fore...
q_thread_t
void(* q_thread_t)(ExceptionSink *xsink, void *arg)
pointer to a function that can be started with q_start_thread()
Definition: qore_thread.h:56
gettid
DLLEXPORT int gettid()
returns the current TID number
ThreadCleanupList::pop
DLLEXPORT void pop(bool exec=true)
must only be called in the module destructor/deletion function
QoreForeignThreadHelper::~QoreForeignThreadHelper
DLLEXPORT ~QoreForeignThreadHelper()
deregisters the current thread if the registration was successful using either q_deregister_foreign_t...
check_thread_resource
DLLEXPORT bool check_thread_resource(AbstractThreadResource *atr)
check if a thread resouce has been saved
tclist
DLLEXPORT ThreadCleanupList tclist
the interface to the thread cleanup list
set_thread_resource
DLLEXPORT void set_thread_resource(AbstractThreadResource *atr)
save a resource against a thread for thread resource handling
qtrdest_t
void(* qtrdest_t)(void *, ExceptionSink *)
pointer to a qore thread resource destructor function
Definition: qore_thread.h:53
ThreadCleanupList::push
DLLEXPORT void push(qtdest_t func, void *arg)
must only be called in the module initialization function
remove_thread_resource
DLLEXPORT int remove_thread_resource(AbstractThreadResource *atr)
remove the resource from the thread resource list for the current thread
getProgram
DLLEXPORT QoreProgram * getProgram()
returns the current QoreProgram
q_deregister_foreign_thread
DLLEXPORT int q_deregister_foreign_thread()
deregisters the current thread as a foreign thread
qtdest_t
void(* qtdest_t)(void *)
pointer to a qore thread destructor function
Definition: qore_thread.h:50
q_release_reserved_foreign_thread_id
DLLEXPORT int q_release_reserved_foreign_thread_id(int tid)
releases a TID reserved with q_reserve_foreign_thread_id()
q_trid_t
unsigned q_trid_t
type for thread resource IDs (unique within a single running qore library process) ...
Definition: common.h:538
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:112
QoreProgram
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only ...
Definition: QoreProgram.h:117
ExceptionSink
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:47
QoreForeignThreadHelper::QoreForeignThreadHelper
DLLEXPORT QoreForeignThreadHelper()
registers the current thread as a foreign thread; the thread will be deregistered with q_deregister_f...
ThreadCleanupList
list of functions to be run when a thread ends; required for some external libraries that require exp...
Definition: qore_thread.h:142
ResolvedCallReferenceNode
base class for resolved call references
Definition: CallReferenceNode.h:130
q_register_foreign_thread
DLLEXPORT int q_register_foreign_thread()
registers the current thread as a Qore thread; returns QFT_OK (0) if the thread was successfully regi...
QoreForeignThreadHelper
use this class to temporarily register and deregister a foreign thread to allow Qore code to be execu...
Definition: qore_thread.h:246
q_start_thread
int q_start_thread(ExceptionSink *xsink, q_thread_t f, void *arg=0)
starts a new thread with the given arguments, when the thread terminates, it deregisters itself ...
qore_get_trid
DLLEXPORT q_trid_t qore_get_trid()
get a thread resource ID
q_deregister_reserved_foreign_thread
DLLEXPORT int q_deregister_reserved_foreign_thread()
deregisters a foreign qore thread but retains the TID as reserved
q_register_reserved_foreign_thread
DLLEXPORT int q_register_reserved_foreign_thread(int tid)
registers a foreign qore thread as a Qore thread with a reserved TID
is_valid_qore_thread
DLLEXPORT bool is_valid_qore_thread()
returns true if the current thread is a valid qore thread; it is not safe to call most Qore functions...
currentTZ
DLLEXPORT const AbstractQoreZoneInfo * currentTZ()
returns the current local time zone, note that if 0 = UTC