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) !=
q_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(),
57 tid.load(std::memory_order_relaxed),
q_gettid());
71 if (!tid.compare_exchange_strong(chktid,
q_gettid(), std::memory_order_consume, std::memory_order_relaxed)) {
74 xsink->
raiseException(
"STREAM-THREAD-ERROR",
"this %s object is assigned to TID %d; it is an error " \
75 "to access it from any other thread (accessed from TID %d)",
getName(), chktid,
q_gettid());
88 if (!tid.compare_exchange_strong(chktid, -1, std::memory_order_release, std::memory_order_relaxed)) {
91 xsink->
raiseException(
"STREAM-THREAD-ERROR",
"this %s object is assigned to TID %d; unassignment may " \
92 "be processed from that thread (accessed from TID %d)",
getName(), chktid,
q_gettid());
101 return tid.load(std::memory_order_relaxed);
123 std::atomic<int> tid;
the base class for all data to be used as private data of Qore objects
Definition: AbstractPrivateData.h:44
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
DLLEXPORT AbstractQoreNode * raiseException(const char *err, const char *fmt,...)
appends a Qore-language exception to the list
defines a Qore-language class
Definition: QoreClass.h:249
Base class for private data of stream implementations in C++.
Definition: StreamBase.h:44
DLLLOCAL int getThreadId()
Get currently assigned thread id.
Definition: StreamBase.h:100
virtual DLLLOCAL const char * getName()=0
Returns the name of the class.
StreamBase()
Constructor.
Definition: StreamBase.h:114
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 reassignThread(ExceptionSink *xsink)
Reassigns current thread as thread used for stream manipulation, see check()
Definition: StreamBase.h:68
DLLLOCAL void unassignThread(ExceptionSink *xsink)
Unassigns current thread as thread used for stream manipulation, see check()
Definition: StreamBase.h:85
DLLEXPORT int q_gettid() noexcept
returns the current TID number