Ejemplo n.º 1
0
// This is a Posix-compatible function prototype that
// just calls the other function.
void *vrpn_Thread::threadFuncShellPosix( void *pvThread ) {
  threadFuncShell(pvThread);
  return NULL;
}
Ejemplo n.º 2
0
bool vrpn_Thread::kill() {
  // kill the os thread
#if defined(sgi) || defined(_WIN32)
  if (threadID>0) {
  #ifdef sgi
      if (::kill( (long) threadID, SIGKILL)<0) {
        perror("vrpn_Thread::kill: kill:");
        return false;
      }
  #elif defined(_WIN32)
      // Return value of -1 passed to TerminateThread causes a warning.
      if (!TerminateThread( (HANDLE) threadID, 1 )) {
        fprintf(stderr, "vrpn_Thread::kill: problem with terminateThread call.\n");
	return false;
      }
  #endif
#else
  if (threadID) {
    // Posix by default
    if (pthread_kill(threadID, SIGKILL) != 0) {
      perror("vrpn_Thread::kill:pthread_kill: ");
      return false;
    }
#endif
  } else {
    fprintf(stderr, "vrpn_Thread::kill: thread is not currently alive.\n");
    return false;
  }
  threadID = 0;
  return true;
}

bool vrpn_Thread::running() {
  return threadID!=0;
}

#if defined(sgi) || defined(_WIN32)
unsigned long vrpn_Thread::pid() {
#else
pthread_t vrpn_Thread::pid() {
#endif
  return threadID;
}

bool vrpn_Thread::available() {
#ifdef vrpn_THREADS_AVAILABLE
  return true;
#else
  return false;
#endif
}

void vrpn_Thread::userData( void *pvNewUserData ) {
  td.pvUD = pvNewUserData;
}

void *vrpn_Thread::userData() {
  return td.pvUD;
}

void vrpn_Thread::threadFuncShell( void *pvThread ) {
  vrpn_Thread *pth = (vrpn_Thread *)pvThread;
  pth->pfThread( pth->td );
  // thread has stopped running
  pth->threadID = 0;
}

// This is a Posix-compatible function prototype that
// just calls the other function.
void *vrpn_Thread::threadFuncShellPosix( void *pvThread ) {
  threadFuncShell(pvThread);
  return NULL;
}