Qore Programming Language 1.12.4
Loading...
Searching...
No Matches
QC_AbstractThreadResource.h
1/* -*- mode: c++; indent-tabs-mode: nil -*- */
2/*
3 AbstractThreadResource.h
4
5 Qore Programming Language
6
7 Copyright (C) 2003 - 2022 Qore Technologies, s.r.o.
8
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the "Software"),
11 to deal in the Software without restriction, including without limitation
12 the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26
27 Note that the Qore library is released under a choice of three open-source
28 licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29 information.
30*/
31
32#ifndef _QORE_INTERN_ABSTRACTTHREADRESOURCE_H
33
34#define _QORE_INTERN_ABSTRACTTHREADRESOURCE_H
35
36#include <qore/AbstractThreadResource.h>
37
38DLLEXPORT extern qore_classid_t CID_ABSTRACTTHREADRESOURCE;
39DLLLOCAL extern QoreClass* QC_ABSTRACTTHREADRESOURCE;
40DLLLOCAL QoreClass* initAbstractThreadResourceClass(QoreNamespace& ns);
41
44protected:
45 QoreObject& obj;
46
47public:
48 DLLLOCAL AbstractQoreThreadResource(QoreObject& n_obj) : obj(n_obj) {
49 obj.tRef();
50 }
51
52 DLLLOCAL virtual ~AbstractQoreThreadResource() {
53 obj.tDeref();
54 }
55
56 DLLLOCAL virtual void cleanup(ExceptionSink* xsink) {
57 obj.evalMethod("cleanup", 0, xsink).discard(xsink);
58 // issue #3551: if the first exception is "OBJECT-ALREADY-DELETED", then ignore
59 if (*xsink) {
60 const QoreValue err = xsink->getExceptionErr();
61 if (err.getType() == NT_STRING && *err.get<const QoreStringNode>() == "OBJECT-ALREADY-DELETED") {
62 xsink->clear();
63 }
64 }
65 }
66
67 DLLLOCAL virtual QoreProgram* getProgram() {
68 return obj.getProgram();
69 }
70};
71
72#endif
this class is used by the AbstractThreadResource Qore class to execute the cleanup method
Definition: QC_AbstractThreadResource.h:43
virtual DLLLOCAL void cleanup(ExceptionSink *xsink)
this function is called when a thread terminates and a thread resource is still allocated to the thre...
Definition: QC_AbstractThreadResource.h:56
virtual DLLLOCAL QoreProgram * getProgram()
this function is called when clearing thread resources for a particular Program when being destroyed
Definition: QC_AbstractThreadResource.h:67
base class for saving data using Qore's thread resource management system
Definition: AbstractThreadResource.h:51
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
DLLEXPORT const QoreValue getExceptionErr()
returns the error of the top exception
DLLEXPORT void clear()
deletes the exception list immediately
defines a Qore-language class
Definition: QoreClass.h:249
contains constants, classes, and subnamespaces in QoreProgram objects
Definition: QoreNamespace.h:65
the implementation of Qore's object data type, reference counted, dynamically-allocated only
Definition: QoreObject.h:60
DLLEXPORT void tRef() const
increments the existence reference count
DLLEXPORT void tDeref()
decrements the existence reference count, when it reaches 0 the C++ object ("this") will be deleted
DLLEXPORT QoreValue evalMethod(const QoreString *name, const QoreListNode *args, ExceptionSink *xsink)
evaluates the given method with the arguments passed and returns the return value,...
DLLEXPORT QoreProgram * getProgram() const
returns the QoreProgram object associated with this object
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only
Definition: QoreProgram.h:127
DLLLOCAL detail::QoreValueCastHelper< T >::Result get()
returns the value as the given type
Definition: QoreValue.h:214
DLLEXPORT qore_type_t getType() const
returns the type of value contained
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
unsigned qore_classid_t
used for the unique class ID for QoreClass objects
Definition: common.h:79
const qore_type_t NT_STRING
type value for QoreStringNode
Definition: node_types.h:45
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:276
DLLEXPORT void discard(ExceptionSink *xsink)
dereferences any contained AbstractQoreNode pointer and sets to 0; does not modify other values