Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SVSync Class Reference

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

#include <svutil.h>

Static Public Member Functions

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

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.

66  {
67 #ifdef _WIN32
68  // ExitThread(0);
69 #else
70  pthread_exit(0);
71 #endif
72 }
void SVSync::StartProcess ( const char *  executable,
const char *  args 
)
static

Starts a new process.

Definition at line 75 of file svutil.cpp.

75  {
76 #ifdef _WIN32
77  std::string proc;
78  proc.append(executable);
79  proc.append(" ");
80  proc.append(args);
81  std::cout << "Starting " << proc << std::endl;
82  STARTUPINFO start_info;
83  PROCESS_INFORMATION proc_info;
84  GetStartupInfo(&start_info);
85  if (!CreateProcess(NULL, const_cast<char*>(proc.c_str()), NULL, NULL, FALSE,
86  CREATE_NO_WINDOW | DETACHED_PROCESS, NULL, NULL,
87  &start_info, &proc_info))
88  return;
89 #else
90  int pid = fork();
91  if (pid != 0) { // The father process returns
92  } else {
93 #ifdef __linux__
94  // Make sure the java process terminates on exit, since its
95  // broken socket detection seems to be useless.
96  prctl(PR_SET_PDEATHSIG, 2, 0, 0, 0);
97 #endif
98  char* mutable_args = strdup(args);
99  int argc = 1;
100  for (int i = 0; mutable_args[i]; ++i) {
101  if (mutable_args[i] == ' ') {
102  ++argc;
103  }
104  }
105  char** argv = new char*[argc + 2];
106  argv[0] = strdup(executable);
107  argv[1] = mutable_args;
108  argc = 2;
109  bool inquote = false;
110  for (int i = 0; mutable_args[i]; ++i) {
111  if (!inquote && mutable_args[i] == ' ') {
112  mutable_args[i] = '\0';
113  argv[argc++] = mutable_args + i + 1;
114  } else if (mutable_args[i] == '"') {
115  inquote = !inquote;
116  mutable_args[i] = ' ';
117  }
118  }
119  argv[argc] = NULL;
120  execvp(executable, argv);
121  }
122 #endif
123 }
#define NULL
Definition: host.h:144
#define FALSE
Definition: capi.h:28
void SVSync::StartThread ( void *(*)(void *)  func,
void *  arg 
)
static

Create new thread.

Definition at line 175 of file svutil.cpp.

175  {
176 #ifdef _WIN32
177  LPTHREAD_START_ROUTINE f = (LPTHREAD_START_ROUTINE) func;
178  DWORD threadid;
179  HANDLE newthread = CreateThread(
180  NULL, // default security attributes
181  0, // use default stack size
182  f, // thread function
183  arg, // argument to thread function
184  0, // use default creation flags
185  &threadid); // returns the thread identifier
186 #else
187  pthread_t helper;
188  pthread_create(&helper, NULL, func, arg);
189 #endif
190 }
#define NULL
Definition: host.h:144
#define f(xc, yc)
Definition: imgscale.cpp:39

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