static DWORD dde_initialise(void) { GET_LD DWORD ddeInst; dde_init_constants(); if ( !(ddeInst=LD->os.dde_instance) ) { if ( DdeInitializeW(&ddeInst, (PFNCALLBACK)DdeCallback, APPCLASS_STANDARD|CBF_FAIL_ADVISES|CBF_FAIL_POKES| CBF_SKIP_REGISTRATIONS|CBF_SKIP_UNREGISTRATIONS, 0L) == DMLERR_NO_ERROR) { LD->os.dde_instance = ddeInst; #ifdef O_PLMT PL_thread_at_exit(dde_uninitialise, NULL, FALSE); #endif } else { dde_warning("initialise"); } DEBUG(1, Sdprintf("Thread %d: created ddeInst %d\n", PL_thread_self(), ddeInst)); } return ddeInst; }
void *my_Perl_get_context(void) { PerlInterpreter *my_perl=Perl_get_context(); if (!my_perl) { my_perl=perl_alloc(); PERL_SET_CONTEXT(my_perl); perl_construct(my_perl); perl_parse(my_perl, xs_init, 3, pargs, NULL); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl_run(my_perl); PL_thread_at_exit(clear_perl, NULL, 0); /* warn ("new perl interpreter created %x (thread=%i)", my_perl, PL_thread_self()); */ } return my_perl; }
/** polling loop til buffer ready */ ssize_t Swipl_IO::_read_(char *buf, size_t bufsize) { qDebug() << "_read_" << CVP(target); int thid = PL_thread_self(); // handle setup interthread and termination for ( ; ; ) { { QMutexLocker lk(&sync); if (target) { if (!target->thids.contains(thid)) { target->add_thread(thid); int rc = PL_thread_at_exit(eng_at_exit, this, FALSE); qDebug() << "installed" << rc; } break; } } if ( PL_handle_signals() < 0 ) return -1; SwiPrologEngine::msleep(10); } if ( buffer.isEmpty() ) { PL_write_prompt(TRUE); emit user_prompt(thid, SwiPrologEngine::is_tty(this)); } for ( ; ; ) { { QMutexLocker lk(&sync); if (!query.isEmpty()) { try { int rc = PlCall(query.toStdWString().data()); qDebug() << "PlCall" << query << rc; } catch(PlException e) { qDebug() << t2w(e); } query.clear(); } uint n = buffer.length(); Q_ASSERT(bufsize >= n); if (n > 0) { uint l = bufsize < n ? bufsize : n; memcpy(buf, buffer, l); buffer.remove(0, l); return l; } if (target->status == ConsoleEdit::eof) { target->status = ConsoleEdit::running; return 0; } } if ( PL_handle_signals() < 0 ) return -1; SwiPrologEngine::msleep(10); } }