Пример #1
0
void ExceptionSink::outOfMemory() {
#ifdef QORE_OOM
   // get pre-allocated out of memory exception for this thread
   QoreException* ex = getOutOfMemoryException();
   // if it's already been used then return
   if (!ex)
      return;
   ex->set(QoreProgramLocation(RuntimeLocation));
   // there is no callstack in an out-of-memory exception
   // add exception to list
   priv->insert(ex);
#else
   printf("OUT OF MEMORY: aborting\n");
   exit(1);
#endif
}
Пример #2
0
void qore_program_private::waitForTerminationAndClear(ExceptionSink* xsink) {
   // we only clear the internal data structures once
   bool clr = false;
   {
      ReferenceHolder<QoreListNode> l(xsink);
      {
         AutoLocker al(plock);
         // wait for all threads to terminate
         waitForAllThreadsToTerminateIntern();
         if (!ptid) {
            l = new QoreListNode;
            qore_root_ns_private::clearConstants(*RootNS, **l);
	    // mark the program so that only code from this thread can run during data destruction
	    ptid = gettid();
	    clr = true;
         }
      }
   }

   if (clr) {
      //printd(5, "qore_program_private::waitForTerminationAndClear() this: %p clr: %d\n", this, clr);
      // delete all global variables, etc
      qore_root_ns_private::clearData(*RootNS, xsink);

      // clear thread init code reference if any
      {
	 ReferenceHolder<ResolvedCallReferenceNode> old(xsink);

	 {
	    AutoLocker al(tlock);

	    // clear thread init code reference
	    old = thr_init;
	    thr_init = 0;
	 }
      }

      // clear thread data if base object
      if (base_object)
         clearThreadData(xsink);

      clearProgramThreadData(xsink);

      {
         AutoLocker al(plock);
         ptid = -1;
      }

      // now clear the original map
      {
	 AutoLocker al(tlock);
	 pgm_data_map.clear();
	 tclear = 0;
	    
	 if (twaiting)
	    tcond.broadcast();
      }
#ifdef HAVE_SIGNAL_HANDLING
      {
         int_set_t ns = sigset;
         // clear all signal handlers managed by this program
         for (int_set_t::iterator i = ns.begin(), e = ns.end(); i != e; ++i)
            QSM.removeHandler(*i, xsink);
      }
#endif

      // merge pending parse exceptions into the passed exception sink, if any
      if (pendingParseSink) {
         xsink->assimilate(pendingParseSink);
         pendingParseSink = 0;
      }

      // clear any exec-class return value
      discard(exec_class_rv, xsink);
      exec_class_rv = 0;
      
      // clear program location
      update_runtime_location(QoreProgramLocation());
   }
}