34 #ifndef _QORE_QORE_THREAD_INTERN_H
35 #define _QORE_QORE_THREAD_INTERN_H
41 #ifndef QORE_THREAD_STACK_SIZE
42 #define QORE_THREAD_STACK_SIZE 1024*512
46 #ifndef QORE_STACK_GUARD
49 #define QORE_STACK_GUARD (1024 * 32)
54 #define QORE_STACK_GUARD (1024 * 22)
57 #if defined(HPUX) && !defined(__ia64) && !defined(__LP64__)
59 #define QORE_STACK_GUARD (1024 * 10)
63 #define QORE_STACK_GUARD (1024 * 8)
68 #endif // QORE_STACK_GUARD
77 class ClosureParseEnvironment;
78 class QoreClosureBase;
79 hashdecl ClosureVarValue;
82 class qore_ns_private;
83 class qore_root_ns_private;
84 class qore_class_private;
85 class AbstractQoreFunctionVariant;
86 class AbstractQoreZoneInfo;
87 class ThreadProgramData;
88 hashdecl ThreadLocalProgramData;
89 class QoreAbstractModule;
92 DLLLOCAL
extern Operator* OP_BACKGROUND;
95 class AbstractQoreZoneInfo;
98 hashdecl ModuleContextNamespaceCommit {
99 qore_ns_private* parent;
100 qore_ns_private* nns;
102 DLLLOCAL ModuleContextNamespaceCommit(qore_ns_private* n_parent, qore_ns_private* n_nns) : parent(n_parent), nns(n_nns) {
106 typedef std::vector<ModuleContextNamespaceCommit> mcnl_t;
108 class ModuleContextNamespaceList :
public mcnl_t {
111 DLLLOCAL ModuleContextNamespaceList(
const ModuleContextNamespaceList&);
114 DLLLOCAL ModuleContextNamespaceList() {
117 DLLLOCAL ~ModuleContextNamespaceList() {
121 DLLLOCAL
void clear();
124 hashdecl ModuleContextFunctionCommit {
125 qore_ns_private* parent;
127 AbstractQoreFunctionVariant* v;
129 DLLLOCAL ModuleContextFunctionCommit(qore_ns_private* n_parent,
const char* n_name, AbstractQoreFunctionVariant* n_v) : parent(n_parent), name(n_name), v(n_v) {
133 typedef std::vector<ModuleContextFunctionCommit> mcfl_t;
135 class ModuleContextFunctionList :
public mcfl_t {
138 DLLLOCAL ModuleContextFunctionList(
const ModuleContextFunctionList&);
141 DLLLOCAL ModuleContextFunctionList() {
144 DLLLOCAL ~ModuleContextFunctionList() {
148 DLLLOCAL
void clear();
151 class QoreModuleContext {
153 ModuleContextNamespaceList mcnl;
154 ModuleContextFunctionList mcfl;
156 DLLLOCAL QoreModuleContext(
const char* n, qore_root_ns_private* n_rns,
ExceptionSink& xs) : name(n), rns(n_rns), xsink(xs) {
159 DLLLOCAL ~QoreModuleContext() {
163 DLLLOCAL
void error(
const char* fmt, ...);
165 DLLLOCAL
bool hasError()
const {
169 DLLLOCAL
void commit();
171 DLLLOCAL
void rollback() {
176 DLLLOCAL qore_root_ns_private* getRootNS()
const {
180 DLLLOCAL
const char* getName()
const {
186 qore_root_ns_private* rns;
191 class QoreModuleDefContext {
193 typedef std::set<std::string> strset_t;
194 typedef std::map<std::string, std::string> strmap_t;
199 const QoreProgramLocation* init_loc,
202 DLLLOCAL QoreModuleDefContext() {
205 DLLLOCAL ~QoreModuleDefContext() {
211 static strset_t vset;
216 DLLLOCAL
void set(
const QoreProgramLocation* loc,
const char* key,
QoreValue val);
218 DLLLOCAL
const char* get(
const char* str)
const {
219 strmap_t::const_iterator i = vmap.find(str);
220 return i == vmap.end() || i->second.empty() ? nullptr : i->second.c_str();
223 DLLLOCAL
void parseInit();
225 DLLLOCAL
bool hasInit()
const {
226 return init_c ? true :
false;
234 DLLLOCAL
void initClosure(
const QoreProgramLocation* loc,
QoreValue& c,
const char* n);
240 DLLLOCAL
int purge_thread_resources_to_mark(
ExceptionSink* xsink);
243 DLLLOCAL
void mark_thread_resources();
244 DLLLOCAL
void beginParsing(
const char* file,
void* ps = NULL,
const char* src =
nullptr,
int offset = 0);
245 DLLLOCAL
void* endParsing();
246 DLLLOCAL Context* get_context_stack();
247 DLLLOCAL
void update_context_stack(Context* cstack);
251 const AbstractStatement*& current_stmt,
QoreProgram*& current_pgm);
253 const AbstractStatement*& current_stmt,
QoreProgram*& current_pgm,
const QoreProgramLocation*& old_runtime_loc);
255 DLLLOCAL
void update_runtime_stack_location(
const QoreStackLocation* stack_loc,
const QoreProgramLocation* runtime_loc);
257 DLLLOCAL
const QoreProgramLocation* get_runtime_location();
258 DLLLOCAL
void update_get_runtime_statement_location(
const AbstractStatement* stmt,
259 const QoreProgramLocation* loc,
const AbstractStatement*& old_stmt,
const QoreProgramLocation*& old_loc);
260 DLLLOCAL
void update_runtime_statement_location(
const AbstractStatement* stmt,
const QoreProgramLocation* loc);
262 DLLLOCAL
void set_parse_file_info(QoreProgramLocation& loc);
263 DLLLOCAL
const char* get_parse_code();
265 DLLLOCAL
const AbstractStatement* get_runtime_statement();
267 DLLLOCAL
const QoreTypeInfo* parse_set_implicit_arg_type_info(
const QoreTypeInfo* ti);
268 DLLLOCAL
const QoreTypeInfo* parse_get_implicit_arg_type_info();
270 DLLLOCAL
int64 parse_get_parse_options();
271 DLLLOCAL
int64 runtime_get_parse_options();
273 DLLLOCAL
bool parse_check_parse_option(
int64 o);
274 DLLLOCAL
bool runtime_check_parse_option(
int64 o);
277 DLLLOCAL
void updateCVarStack(CVNode* ncvs);
278 DLLLOCAL CVNode* getCVarStack();
279 DLLLOCAL
void updateVStack(VNode* nvs);
280 DLLLOCAL VNode* getVStack();
284 DLLLOCAL qore_class_private* parse_get_class_priv();
285 DLLLOCAL
void thread_set_class_and_ns(
const qore_class_private* new_cls, qore_ns_private* new_ns,
const qore_class_private*& old_cls, qore_ns_private*& old_ns);
286 DLLLOCAL
void thread_set_class_and_ns(
const qore_class_private* new_cls, qore_ns_private* new_ns);
287 DLLLOCAL
void thread_set_ns(qore_ns_private* new_ns, qore_ns_private*& old_ns);
288 DLLLOCAL
void thread_set_ns(qore_ns_private* new_ns);
289 DLLLOCAL qore_ns_private* parse_get_ns();
291 DLLLOCAL
void substituteObjectIfEqual(
QoreObject* o);
293 DLLLOCAL QoreException* catchSwapException(QoreException* e);
294 DLLLOCAL QoreException* catchGetException();
295 DLLLOCAL VLock* getVLock();
297 DLLLOCAL
void delete_thread_local_data();
298 DLLLOCAL
void parse_cond_push(
bool mark =
false);
299 DLLLOCAL
bool parse_cond_else();
300 DLLLOCAL
bool parse_cond_pop(
const QoreProgramLocation* loc);
301 DLLLOCAL
bool parse_cond_test(
const QoreProgramLocation* loc);
302 DLLLOCAL
void push_parse_options();
303 DLLLOCAL
void parse_try_module_inc();
304 DLLLOCAL
bool parse_try_module_dec(
const QoreProgramLocation* loc);
305 DLLLOCAL
unsigned parse_try_module_get();
306 DLLLOCAL
void parse_try_module_set(
unsigned c);
308 DLLLOCAL
void parse_push_name(
const char* name);
309 DLLLOCAL std::string parse_pop_name();
311 DLLLOCAL
void set_module_context(QoreModuleContext* qmc);
312 DLLLOCAL QoreModuleContext* get_module_context();
313 DLLLOCAL QoreModuleDefContext* set_module_def_context(QoreModuleDefContext* qmd);
314 DLLLOCAL QoreModuleDefContext* get_module_def_context();
315 DLLLOCAL
void parse_set_module_def_context_name(
const char* name);
316 DLLLOCAL
const char* set_user_module_context_name(
const char* n);
317 DLLLOCAL
const char* get_user_module_context_name();
318 DLLLOCAL
const char* get_module_context_name();
320 DLLLOCAL
void parse_set_try_reexport(
bool tr);
321 DLLLOCAL
bool parse_get_try_reexport();
323 DLLLOCAL
void set_thread_tz(
const AbstractQoreZoneInfo* tz);
324 DLLLOCAL
const AbstractQoreZoneInfo* get_thread_tz(
bool& set);
325 DLLLOCAL
void clear_thread_tz();
327 DLLLOCAL ThreadProgramData* get_thread_program_data();
328 DLLLOCAL ThreadLocalProgramData* get_thread_local_program_data();
330 DLLLOCAL
int thread_ref_set(
const lvalue_ref* r);
331 DLLLOCAL
void thread_ref_remove(
const lvalue_ref* r);
334 DLLLOCAL
void new_argv_ref();
337 DLLLOCAL
void inc_argv_ref();
340 DLLLOCAL
void push_ignore_numeric_argv_ref();
343 DLLLOCAL
void pop_ignore_numeric_argv_ref();
346 DLLLOCAL
void inc_numeric_argv_ref();
349 DLLLOCAL
int get_pop_argv_ref();
352 DLLLOCAL
void clear_argv_ref();
354 DLLLOCAL
int set_constant(ConstantEntry* ce);
355 DLLLOCAL
void remove_constant(ConstantEntry* ce);
357 DLLLOCAL QoreAbstractModule* set_reexport(QoreAbstractModule* m,
bool current_reexport,
bool& old_reexport);
358 DLLLOCAL
void set_reexport(QoreAbstractModule* m,
bool reexport);
360 DLLLOCAL
void parseSetCodeInfo(
const char* parse_code,
const QoreTypeInfo* returnTypeInfo,
const char*& old_code,
const QoreTypeInfo*& old_returnTypeInfo);
361 DLLLOCAL
void parseRestoreCodeInfo(
const char* parse_code,
const QoreTypeInfo* returnTypeInfo);
363 DLLLOCAL
const QoreTypeInfo* saveReturnTypeInfo(
const QoreTypeInfo* returnTypeInfo);
364 DLLLOCAL
const QoreTypeInfo* getReturnTypeInfo();
366 DLLLOCAL
const QoreTypeInfo* parse_get_return_type_info();
369 DLLLOCAL
void set_program_call_context(
QoreProgram* new_pgm);
372 class LVarStackBreakHelper {
374 DLLLOCAL LVarStackBreakHelper();
375 DLLLOCAL ~LVarStackBreakHelper();
381 class ProgramCallContextHelper {
383 DLLLOCAL ProgramCallContextHelper(
QoreProgram* new_pgm);
384 DLLLOCAL ~ProgramCallContextHelper();
390 class ModuleReExportHelper {
392 QoreAbstractModule* m;
396 DLLLOCAL ModuleReExportHelper(QoreAbstractModule* mi,
bool reexp);
397 DLLLOCAL ~ModuleReExportHelper();
400 class QoreParseCountContextHelper {
405 DLLLOCAL QoreParseCountContextHelper() : count(parse_try_module_get()) {
406 parse_try_module_set(0);
409 DLLLOCAL ~QoreParseCountContextHelper() {
410 parse_try_module_set(count);
414 class QoreProgramStackLocationHelper {
416 DLLLOCAL QoreProgramStackLocationHelper(
QoreStackLocation* stack_loc,
const AbstractStatement*& current_stmt,
418 stack_loc(update_get_runtime_stack_location(stack_loc, current_stmt, current_pgm)) {
421 DLLLOCAL ~QoreProgramStackLocationHelper() {
422 update_runtime_stack_location(stack_loc);
429 class QoreInternalCallStackLocationHelperBase :
public QoreStackLocation,
public QoreProgramStackLocationHelper {
431 DLLLOCAL QoreInternalCallStackLocationHelperBase() : QoreProgramStackLocationHelper(this, stmt, pgm) {
438 DLLLOCAL
virtual const AbstractStatement*
getStatement()
const {
443 const AbstractStatement* stmt;
447 class QoreInternalCallStackLocationHelper :
public QoreInternalCallStackLocationHelperBase {
449 DLLLOCAL QoreInternalCallStackLocationHelper(
const QoreProgramLocation& loc,
const std::string& call,
450 qore_call_t call_type) : loc(loc), call(call), call_type(call_type) {
454 DLLLOCAL
virtual const QoreProgramLocation& getLocation()
const {
459 DLLLOCAL
virtual const std::string& getCallName()
const {
463 DLLLOCAL
virtual qore_call_t getCallType()
const {
468 const QoreProgramLocation& loc;
469 const std::string call;
470 qore_call_t call_type;
473 class QoreProgramLocationHelper {
475 DLLLOCAL QoreProgramLocationHelper(
const QoreProgramLocation* n_loc,
const AbstractStatement* n_stat =
nullptr) {
476 update_get_runtime_statement_location(n_stat, n_loc, statement, loc);
479 DLLLOCAL ~QoreProgramLocationHelper() {
480 update_runtime_statement_location(statement, loc);
484 const QoreProgramLocation* loc;
485 const AbstractStatement* statement;
488 class QoreProgramOptionalLocationHelper {
490 DLLLOCAL QoreProgramOptionalLocationHelper(
const QoreProgramLocation* n_loc,
const AbstractStatement* n_stat =
nullptr) : restore((bool)n_loc) {
492 update_get_runtime_statement_location(n_stat, n_loc, statement, loc);
496 DLLLOCAL ~QoreProgramOptionalLocationHelper() {
498 update_runtime_statement_location(statement, loc);
503 const QoreProgramLocation* loc;
504 const AbstractStatement* statement;
509 class CurrentProgramRuntimeParseContextHelper {
512 DLLEXPORT CurrentProgramRuntimeParseContextHelper();
514 DLLEXPORT ~CurrentProgramRuntimeParseContextHelper();
518 CurrentProgramRuntimeParseContextHelper(
const CurrentProgramRuntimeParseContextHelper&) =
delete;
519 void*
operator new(size_t) =
delete;
523 class ParseImplicitArgTypeHelper {
525 DLLLOCAL ParseImplicitArgTypeHelper(
const QoreTypeInfo* ti) : ati(parse_set_implicit_arg_type_info(ti)) {
528 DLLLOCAL ~ParseImplicitArgTypeHelper() {
529 parse_set_implicit_arg_type_info(ati);
533 const QoreTypeInfo* ati;
537 DLLLOCAL
int get_thread_entry();
539 DLLLOCAL
int get_signal_thread_entry();
540 DLLLOCAL
void deregister_signal_thread();
541 DLLLOCAL
void register_thread(
int tid, pthread_t ptid,
QoreProgram* pgm,
bool foreign =
false);
542 DLLLOCAL
void deregister_thread(
int tid);
543 DLLLOCAL
void delete_signal_thread();
550 DLLLOCAL
void pushBlock(block_list_t::iterator i);
552 DLLLOCAL block_list_t::iterator popBlock();
554 DLLLOCAL
void advanceOnBlockExit();
556 DLLLOCAL LocalVarValue* thread_instantiate_lvar();
557 DLLLOCAL
void thread_uninstantiate_lvar(
ExceptionSink* xsink);
558 DLLLOCAL
void thread_uninstantiate_self();
560 DLLLOCAL
void thread_set_closure_parse_env(ClosureParseEnvironment* cenv);
561 DLLLOCAL ClosureParseEnvironment* thread_get_closure_parse_env();
563 DLLLOCAL ClosureVarValue* thread_instantiate_closure_var(
const char*
id,
const QoreTypeInfo* typeInfo,
QoreValue& nval,
bool assign);
564 DLLLOCAL
void thread_instantiate_closure_var(ClosureVarValue* cvar);
565 DLLLOCAL
void thread_uninstantiate_closure_var(
ExceptionSink* xsink);
566 DLLLOCAL ClosureVarValue* thread_find_closure_var(
const char*
id);
568 DLLLOCAL ClosureVarValue* thread_get_runtime_closure_var(
const LocalVar*
id);
569 DLLLOCAL
const QoreClosureBase* thread_set_runtime_closure_env(
const QoreClosureBase* current);
571 typedef std::vector<ClosureVarValue*> cvv_vec_t;
572 DLLLOCAL cvv_vec_t* thread_get_all_closure_vars();
574 DLLLOCAL
void thread_push_frame_boundary();
575 DLLLOCAL
void thread_pop_frame_boundary();
579 DLLLOCAL
int thread_set_local_var_value(
int frame,
const char* name,
const QoreValue& val,
ExceptionSink* xsink);
581 DLLLOCAL
int thread_set_closure_var_value(
int frame,
const char* name,
const QoreValue& val,
ExceptionSink* xsink);
583 DLLLOCAL
int get_implicit_element();
584 DLLLOCAL
int save_implicit_element(
int n_element);
586 DLLLOCAL VNode* update_get_vstack(VNode* vn);
587 DLLLOCAL
void save_global_vnode(VNode* vn);
588 DLLLOCAL VNode* get_global_vnode();
590 class QoreContainerHelper {
599 if (!thread_push_container(n_n)) {
613 DLLLOCAL ~QoreContainerHelper() {
615 thread_pop_container(n);
617 DLLLOCAL
operator bool ()
const {
622 DLLLOCAL
const QoreListNode* thread_get_implicit_args();
624 DLLLOCAL LocalVarValue* thread_find_lvar(
const char*
id);
627 DLLLOCAL
QoreObject* runtime_get_stack_object();
629 DLLLOCAL
const qore_class_private* runtime_get_class();
630 DLLLOCAL
void runtime_get_object_and_class(
QoreObject*& obj,
const qore_class_private*& qc);
632 DLLLOCAL
bool runtime_in_object_method(
const char* name,
const QoreObject* o);
634 class CodeContextHelperBase {
636 const char* old_code;
638 const qore_class_private* old_class;
646 DLLLOCAL CodeContextHelperBase(
const char* code,
QoreObject* obj,
const qore_class_private* c,
ExceptionSink* xsink,
bool ref_obj =
true);
647 DLLLOCAL ~CodeContextHelperBase();
650 class ObjectSubstitutionHelper {
653 const qore_class_private* old_class;
656 DLLLOCAL ObjectSubstitutionHelper(
QoreObject* obj,
const qore_class_private* c);
657 DLLLOCAL ~ObjectSubstitutionHelper();
660 class OptionalClassObjSubstitutionHelper {
662 DLLLOCAL OptionalClassObjSubstitutionHelper(
const qore_class_private* qc);
663 DLLLOCAL ~OptionalClassObjSubstitutionHelper();
667 const qore_class_private* old_class;
671 class OptionalClassOnlySubstitutionHelper {
673 DLLLOCAL OptionalClassOnlySubstitutionHelper(
const qore_class_private* qc);
674 DLLLOCAL ~OptionalClassOnlySubstitutionHelper();
677 const qore_class_private* old_class;
681 class OptionalObjectOnlySubstitutionHelper {
683 DLLLOCAL OptionalObjectOnlySubstitutionHelper(
QoreObject* obj);
684 DLLLOCAL ~OptionalObjectOnlySubstitutionHelper();
691 class ThreadSafeLocalVarRuntimeEnvironmentHelper {
693 const QoreClosureBase* prev;
696 DLLLOCAL ThreadSafeLocalVarRuntimeEnvironmentHelper(
const QoreClosureBase* current);
697 DLLLOCAL ~ThreadSafeLocalVarRuntimeEnvironmentHelper();
700 typedef std::map<const LocalVar*, ClosureVarValue*> cvar_map_t;
701 typedef std::set<ClosureVarValue*> cvv_set_t;
703 class ThreadSafeLocalVarRuntimeEnvironment {
709 DLLLOCAL ThreadSafeLocalVarRuntimeEnvironment(
const lvar_set_t* vlist);
710 DLLLOCAL ~ThreadSafeLocalVarRuntimeEnvironment();
711 DLLLOCAL ClosureVarValue* find(
const LocalVar*
id)
const;
712 DLLLOCAL
bool hasVar(ClosureVarValue* cvv)
const;
715 DLLLOCAL
bool empty() {
719 DLLLOCAL
const cvar_map_t& getMap()
const {
724 hashdecl ThreadLocalProgramData;
726 class QoreProgramBlockParseOptionHelper {
728 DLLLOCAL QoreProgramBlockParseOptionHelper(
int64 n_po);
729 DLLLOCAL ~QoreProgramBlockParseOptionHelper();
735 class ProgramThreadCountContextHelper {
738 DLLLOCAL ~ProgramThreadCountContextHelper();
739 static ThreadLocalProgramData* getContextFrame(
int& frame,
ExceptionSink* xsink);
740 bool isFirstThreadLocalProgramData(
const ThreadLocalProgramData* tlpd)
const;
744 ThreadLocalProgramData* old_tlpd =
nullptr;
745 ProgramThreadCountContextHelper* old_ctx =
nullptr;
747 int save_frameCount = 0;
749 bool restore =
false;
750 bool init_tlpd =
false;
753 class ProgramRuntimeParseContextHelper {
760 DLLLOCAL ~ProgramRuntimeParseContextHelper();
764 class ProgramRuntimeParseCommitContextHelper {
767 ThreadLocalProgramData* old_tlpd;
772 DLLLOCAL ~ProgramRuntimeParseCommitContextHelper();
775 class ProgramRuntimeParseAccessHelper {
782 DLLLOCAL ~ProgramRuntimeParseAccessHelper();
785 class RuntimeReferenceHelperBase {
787 const lvalue_ref* ref;
788 ProgramThreadCountContextHelper pch;
789 ObjectSubstitutionHelper osh;
793 DLLLOCAL RuntimeReferenceHelperBase(
const lvalue_ref& r,
ExceptionSink* n_xsink)
794 : ref(&r), pch(n_xsink, r.pgm, true), osh(r.self, r.cls) {
796 if (thread_ref_set(&r)) {
798 n_xsink->
raiseException(
"CIRCULAR-REFERENCE-ERROR",
"a circular lvalue reference was detected");
803 DLLLOCAL ~RuntimeReferenceHelperBase() {
805 thread_ref_remove(ref);
808 DLLLOCAL
operator bool()
const {
813 class RuntimeReferenceHelper :
public RuntimeReferenceHelperBase {
815 DLLLOCAL RuntimeReferenceHelper(
const ReferenceNode& r,
ExceptionSink* n_xsink) : RuntimeReferenceHelperBase(*lvalue_ref::get(&r), n_xsink) {
818 DLLLOCAL RuntimeReferenceHelper(
const lvalue_ref& r,
ExceptionSink* n_xsink) : RuntimeReferenceHelperBase(r, n_xsink) {
822 class ArgvContextHelper {
830 DLLLOCAL ~ArgvContextHelper();
833 class SingleArgvContextHelper {
842 DLLLOCAL ~SingleArgvContextHelper();
845 class ImplicitElementHelper {
850 DLLLOCAL ImplicitElementHelper(
int n_element) : element(save_implicit_element(n_element)) {
852 DLLLOCAL ~ImplicitElementHelper() {
853 save_implicit_element(element);
857 class CodeContextHelper :
public CodeContextHelperBase {
859 DLLLOCAL CodeContextHelper(
ExceptionSink* xs,
int t,
const char* c,
QoreObject* obj =
nullptr,
const qore_class_private* cls =
nullptr,
bool ref_obj =
true) :
860 CodeContextHelperBase(c, obj, cls, xs, ref_obj) {
864 DLLLOCAL
void init_qore_threads();
866 DLLLOCAL
void delete_qore_threads();
871 #if defined(HAVE_PTHREAD_GET_STACKSIZE_NP) || (defined(QORE_HAVE_PTHREAD_GETATTR_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACKSIZE))
872 #define QORE_HAVE_GET_STACK_SIZE
875 #if defined(QORE_HAVE_PTHREAD_SETNAME_NP_1) || defined(QORE_HAVE_PTHREAD_SETNAME_NP_2) || defined(QORE_HAVE_PTHREAD_SETNAME_NP_3) || defined(QORE_HAVE_PTHREAD_SET_NAME_NP)
876 #if defined(HAVE_PTHREAD_GET_NAME_NP) || defined(HAVE_PTHREAD_GETNAME_NP)
877 #define QORE_HAVE_THREAD_NAME
881 class QorePThreadAttr {
886 DLLLOCAL QorePThreadAttr() {
887 pthread_attr_init(&attr);
888 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
891 DLLLOCAL ~QorePThreadAttr() {
893 pthread_attr_destroy(&attr);
897 #ifdef HAVE_PTHREAD_ATTR_GETSTACK
898 DLLLOCAL
void getstack(
void*& ptr,
size_t& ssize) {
899 pthread_attr_getstack(&attr, &ptr, &ssize);
903 DLLLOCAL
size_t getstacksize()
const {
905 pthread_attr_getstacksize(&attr, &ssize);
909 DLLLOCAL
int setstacksize(
size_t ssize) {
910 return pthread_attr_setstacksize(&attr, ssize);
913 DLLLOCAL pthread_attr_t* get_ptr() {
917 #ifdef QORE_HAVE_GET_STACK_SIZE
918 DLLLOCAL
static size_t getCurrentThreadStackSize() {
919 #ifdef HAVE_PTHREAD_GET_STACKSIZE_NP
920 return pthread_get_stacksize_np(pthread_self());
923 if (pthread_getattr_np(pthread_self(), &attr)) {
926 ON_BLOCK_EXIT(pthread_attr_destroy, &attr);
928 if (pthread_attr_getstacksize(&attr, &size)) {
937 DLLLOCAL
extern QorePThreadAttr ta_default;
939 #ifdef QORE_MANAGE_STACK
943 class ParseCodeInfoHelper {
945 const char* parse_code;
946 const QoreTypeInfo* returnTypeInfo;
949 DLLLOCAL ParseCodeInfoHelper(
const char* n_parse_code,
const QoreTypeInfo* n_returnTypeInfo) {
950 parseSetCodeInfo(n_parse_code, n_returnTypeInfo, parse_code, returnTypeInfo);
953 DLLLOCAL ~ParseCodeInfoHelper() {
954 parseRestoreCodeInfo(parse_code, returnTypeInfo);
958 class NamespaceParseContextHelper {
964 DLLLOCAL NamespaceParseContextHelper(qore_ns_private* n_ns) {
965 thread_set_ns(n_ns, ns);
966 restore = (ns != n_ns);
969 DLLLOCAL ~NamespaceParseContextHelper() {
976 class OptionalNamespaceParseContextHelper {
982 DLLLOCAL OptionalNamespaceParseContextHelper(qore_ns_private* n_ns) {
984 thread_set_ns(n_ns, ns);
985 restore = (ns != n_ns);
991 DLLLOCAL ~OptionalNamespaceParseContextHelper() {
998 class QoreParseClassHelper {
1000 const qore_class_private* cls;
1001 qore_ns_private* ns;
1005 DLLLOCAL QoreParseClassHelper(
QoreClass* new_cls, qore_ns_private* new_ns =
nullptr);
1007 DLLLOCAL ~QoreParseClassHelper();
1015 typedef std::set<QoreProgram*> pgm_set_t;
1023 DLLLOCAL
void ref() {
1027 DLLLOCAL ~ThreadProgramData() {
1028 assert(pgm_set.empty());
1032 DLLLOCAL ThreadProgramData(ThreadData* n_td) : td(n_td) {
1036 DLLLOCAL
bool saveProgram(
bool runtime,
ExceptionSink* xsink);
1039 DLLLOCAL
void deref() {
1046 class ThreadFrameBoundaryHelper {
1048 DLLLOCAL ThreadFrameBoundaryHelper(
bool doit) : doit(doit) {
1051 thread_push_frame_boundary();
1055 DLLLOCAL ~ThreadFrameBoundaryHelper() {
1058 thread_pop_frame_boundary();
1066 DLLLOCAL
extern pthread_mutexattr_t ma_recursive;
1067 DLLLOCAL
extern QoreRWLock lck_debug_program;
1069 #ifdef QORE_HAVE_THREAD_NAME
1070 DLLLOCAL
void q_set_thread_name(
const char* name);
1071 DLLLOCAL
void q_get_thread_name(
QoreString& str);