示例#1
0
void* OSThread::_Entry(void *inThread)  //static
#endif
{
	OSThread* theThread = (OSThread*)inThread;
#ifdef __Win32__
	BOOL theErr = ::TlsSetValue(sThreadStorageIndex, theThread);
	Assert(theErr == TRUE);
#elif __PTHREADS__
	theThread->fThreadID = (pthread_t)pthread_self();
	pthread_setspecific(OSThread::gMainKey, theThread);
#else
	theThread->fThreadID = (UInt32)cthread_self();
	cthread_set_data(cthread_self(), (any_t)theThread);
#endif
	theThread->SwitchPersonality();
	//
	// Run the thread
	theThread->Entry();

#ifdef __Win32__
	return 0;
#else
	return NULL;
#endif
}
int server (void)
{
    pLogFile = fopen ("unreliable_data_test.log", "a");
    if (pLogFile == NULL) {
        printf ("error creating the logfile\n");
        exit(1);
    }

    int rc;
    if ( (rc = msgServerMocket.listen (MOCKETS_PORT_NUM)) < 0 ) {
        printf ("server:: error on msgServerMocket.listen(). rc = %d\n", rc);
        return -1;
    }
    if (0 != (rc = dgSocket.init (UDP_PORT_NUM))) {
        fprintf (stderr, "failed to bind datagram socket to port %d; rc = %d\n", UDP_PORT_NUM, rc);
        return -2;
    }

    //printf ("server():: before mocketServerThread()\n");
    OSThread mocketServerThread;
    mocketServerThread.start (serverMocket, NULL);

    rc = udpServer();

    return rc;
}
示例#3
0
void* OSThread::Entry(void* arg)
{
    OSThread* thread = reinterpret_cast<OSThread*>(arg);
    thread->saveStackGuard();

    th_current = thread;
    thread->Run();
    thread->Unref();

#ifdef _WIN32
    _endthreadex(0);
#endif

    return 0;
}
// Called by the requesting thread to send a signal to target thread and
// execute "this" callback from the signal handler.
int OSThread::Sync_Interrupt_Callback::interrupt(Thread * target, int timeout) {
  // Let signals to the vm_thread go even if the Threads_lock is not acquired
  assert(Threads_lock->owned_by_self() || (target == VMThread::vm_thread()),
         "must have threads lock to call this");

  OSThread * osthread = target->osthread();

  // may block if target thread already has a pending callback
  osthread->set_interrupt_callback(this);

  _target = target;

  int rslt = thr_kill(osthread->thread_id(), os::Solaris::SIGasync());
  assert(rslt == 0, "thr_kill != 0");

  bool status = false;
  jlong t1 = os::javaTimeMillis();
  { // don't use safepoint check because we might be the watcher thread.
    MutexLockerEx ml(_sync, Mutex::_no_safepoint_check_flag);
    while (!is_done()) {
      status = _sync->wait(Mutex::_no_safepoint_check_flag, timeout);

      // status == true if timed out
      if (status) break;

      // update timeout
      jlong t2 = os::javaTimeMillis();
      timeout -= t2 - t1;
      t1 = t2;
    }
  }

  // reset current_callback
  osthread->remove_interrupt_callback(this);

  return status;
}
示例#5
0
 ~OSThreadContendState() {
   _osthread->set_state(_old_state);
 }
示例#6
0
 ~OSThreadWaitState() {
   _osthread->set_state(_old_state);
 }
示例#7
0
	bool linkOpen( OSThreadFunction func, OSThreadFunctionArg arg )
	{
		return listening_thread->start( func, arg );
	}
示例#8
0
	bool linkWatch( OSThreadFunction func, OSThreadFunctionArg arg )
	{
		return link_thread->start( func, arg );
	}
void
StacksReporter::threadMain(void)
{
  if (os.isDebug())
    {
      os.sched.lock.enter();
        {
          debug.putString("Thread '");
          debug.putString(getName());
          debug.putString("', seconds=");
          debug.putDec(m_rateSeconds);
          debug.putString(", max=");
          debug.putDec(m_maxSeconds);
          debug.putString(", increase%=");
          debug.putDec((unsigned short) m_increaseRate);
          debug.putNewLine();
        }
      os.sched.lock.exit();
    }

  unsigned int i;
  i = 0;

  unsigned int n;
  n = m_rateSeconds;

  // thread endless loop
  for (;;)
    {
      if (os.isDebug())
        {
          // Disable all other threads to write during the display.
          // Only the interrupts may write something
          os.sched.lock.enter();
            {
              if (i > n)
                {
                  if (n < m_maxSeconds)
                    {
                      // if max limit not reached,
                      // increase the limit with given rate
                      n = n * (100 + m_increaseRate) / 100;
                    }
                  i = 0;
                }
              if (i == 0)
                {
                  ulong_t val;

                  val = m_uptimeSeconds;

                  clog << std::endl << std::endl;
                  clog << " Up time: ";
                  if (val > 3600)
                    {
                      clog << (val / 3600) << "h ";
                      val %= 3600;
                    }
                  if (m_uptimeSeconds > 60)
                    {
                      clog << (val / 60) << "m ";
                    }
                  clog << (val % 60) << "s";

                  int nThreads;
                  nThreads = os.sched.getThreadsCount();
                  for (int j = 0; j < nThreads; ++j)
                    {
                      OSThread* pt;
                      pt = os.sched.getThread(j);
                      if (pt != 0)
                        {
                          clog << std::endl;

                          clog << ((pt == this) ? '*' : ' ');
                          clog << pt->getName() << ' ' << pt->getStackUsed()
                              << '/' << pt->getStackSize();
                          if (pt->isWaiting())
                            {
                              if ((OSEvent_t)pt == pt->getEvent())
                                {
                                  clog << " s";
                                }
                              else
                                {
                                  clog << " w " << std::hex << pt->getEvent();
                                }
                            }
                        }
                    }
                  clog << std::endl << std::endl;
                }
              ++i;
            }
          os.sched.lock.exit();
        }

#if defined(OS_INCLUDE_OSTIMERSECONDS)
      os.sched.timerSeconds.sleep(1);
#else
      os.sched.timerTicks.sleep(OS_CFGINT_TICK_RATE_HZ);
#endif

      ++m_uptimeSeconds;
    }
}
示例#10
0
文件: thread.cpp 项目: CYCOK/fibjs
static void *ThreadEntry(void *arg)
{
    OSThread *thread = reinterpret_cast<OSThread *>(arg);
    thread->Run();
    return NULL;
}