Tesseract  3.02
SVSync Class Reference

The SVSync class provides functionality for Thread & Process Creation. More...

#include <svutil.h>

List of all members.

Static Public Member Functions

static void StartThread (void *(*func)(void *), void *arg)
 Create new thread.
static void ExitThread ()
 Signals a thread to exit.
static void StartProcess (const char *executable, const char *args)
 Starts a new process.

Detailed Description

The SVSync class provides functionality for Thread & Process Creation.

Definition at line 55 of file svutil.h.


Member Function Documentation

void SVSync::ExitThread ( ) [static]

Signals a thread to exit.

Definition at line 66 of file svutil.cpp.

                        {
#ifdef _WIN32
  // ExitThread(0);
#else
  pthread_exit(0);
#endif
}
void SVSync::StartProcess ( const char *  executable,
const char *  args 
) [static]

Starts a new process.

Definition at line 75 of file svutil.cpp.

                                                                  {
#ifdef _WIN32
  std::string proc;
  proc.append(executable);
  proc.append(" ");
  proc.append(args);
  std::cout << "Starting " << proc << std::endl;
  STARTUPINFO start_info;
  PROCESS_INFORMATION proc_info;
  GetStartupInfo(&start_info);
  if (!CreateProcess(NULL, const_cast<char*>(proc.c_str()), NULL, NULL, FALSE,
                CREATE_NO_WINDOW | DETACHED_PROCESS, NULL, NULL,
                &start_info, &proc_info))
    return;
#else
  int pid = fork();
  if (pid != 0) {   // The father process returns
  } else {
#ifdef __linux__
    // Make sure the java process terminates on exit, since its
    // broken socket detection seems to be useless.
    prctl(PR_SET_PDEATHSIG, 2, 0, 0, 0);
#endif
    char* mutable_args = strdup(args);
    int argc = 1;
    for (int i = 0; mutable_args[i]; ++i) {
      if (mutable_args[i] == ' ') {
        ++argc;
      }
    }
    char** argv = new char*[argc + 2];
    argv[0] = strdup(executable);
    argv[1] = mutable_args;
    argc = 2;
    bool inquote = false;
    for (int i = 0; mutable_args[i]; ++i) {
      if (!inquote && mutable_args[i] == ' ') {
        mutable_args[i] = '\0';
        argv[argc++] = mutable_args + i + 1;
      } else if (mutable_args[i] == '"') {
        inquote = !inquote;
        mutable_args[i] = ' ';
      }
    }
    argv[argc] = NULL;
    execvp(executable, argv);
  }
#endif
}
void SVSync::StartThread ( void *(*)(void *)  func,
void *  arg 
) [static]

Create new thread.

Definition at line 175 of file svutil.cpp.

                                                        {
#ifdef _WIN32
  LPTHREAD_START_ROUTINE f = (LPTHREAD_START_ROUTINE) func;
  DWORD threadid;
  HANDLE newthread = CreateThread(
  NULL,          // default security attributes
  0,             // use default stack size
  f,             // thread function
  arg,           // argument to thread function
  0,             // use default creation flags
  &threadid);    // returns the thread identifier
#else
  pthread_t helper;
  pthread_create(&helper, NULL, func, arg);
#endif
}

The documentation for this class was generated from the following files: