32 #ifndef _QORE_STREAMBASE_H 33 #define _QORE_STREAMBASE_H 35 #include "qore/AbstractPrivateData.h" 39 DLLEXPORT
extern QoreClass* QC_STREAMBASE;
54 if (tid.load(std::memory_order_relaxed) !=
gettid()) {
55 xsink->
raiseException(
"STREAM-THREAD-ERROR",
"this %s object was created in TID %d; it is an error " 56 "to access it from any other thread (accessed from TID %d)",
getName(), tid.load(std::memory_order_relaxed),
gettid());
70 if (!tid.compare_exchange_strong(chktid,
gettid(), std::memory_order_consume, std::memory_order_relaxed)) {
73 xsink->
raiseException(
"STREAM-THREAD-ERROR",
"this %s object is assigned to TID %d;" 87 if (!tid.compare_exchange_strong(chktid, -1, std::memory_order_release, std::memory_order_relaxed)) {
90 xsink->
raiseException(
"STREAM-THREAD-ERROR",
"this %s object is assigned to TID %d; unassignment may " 91 "be processed from that thread (accessed from TID %d)",
getName(), chktid,
gettid());
100 return tid.load(std::memory_order_relaxed);
107 DLLLOCAL
virtual const char *
getName() = 0;
122 std::atomic<int> tid;
125 #endif // _QORE_STREAMBASE_H DLLEXPORT int gettid()
returns the current TID number
DLLLOCAL int getThreadId()
Get currently assigned thread id.
Definition: StreamBase.h:99
the base class for all data to be used as private data of Qore objects
Definition: AbstractPrivateData.h:44
DLLLOCAL void reassignThread(ExceptionSink *xsink)
Reassigns current thread as thread used for stream manipulation, see check()
Definition: StreamBase.h:67
DLLEXPORT AbstractQoreNode * raiseException(const char *err, const char *fmt,...)
appends a Qore-language exception to the list
virtual DLLLOCAL const char * getName()=0
Returns the name of the class.
defines a Qore-language class
Definition: QoreClass.h:237
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:46
DLLLOCAL bool check(ExceptionSink *xsink)
Checks that the current thread is the same as when the instance was created or assigned via unassignT...
Definition: StreamBase.h:53
DLLLOCAL void unassignThread(ExceptionSink *xsink)
Unassigns current thread as thread used for stream manipulation, see check()
Definition: StreamBase.h:84
Base class for private data of stream implementations in C++.
Definition: StreamBase.h:44
StreamBase()
Constructor.
Definition: StreamBase.h:113