tesseract  3.05.02
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 58 of file svutil.h.

Member Function Documentation

◆ ExitThread()

void SVSync::ExitThread ( )
static

Signals a thread to exit.

Definition at line 91 of file svutil.cpp.

91  {
92 #ifdef _WIN32
93  // ExitThread(0);
94 #else
95  pthread_exit(0);
96 #endif
97 }

◆ StartProcess()

void SVSync::StartProcess ( const char *  executable,
const char *  args 
)
static

Starts a new process.

Definition at line 100 of file svutil.cpp.

100  {
101  std::string proc;
102  proc.append(executable);
103  proc.append(" ");
104  proc.append(args);
105  std::cout << "Starting " << proc << std::endl;
106 #ifdef _WIN32
107  STARTUPINFO start_info;
108  PROCESS_INFORMATION proc_info;
109  GetStartupInfo(&start_info);
110  if (!CreateProcess(NULL, const_cast<char*>(proc.c_str()), NULL, NULL, FALSE,
111  CREATE_NO_WINDOW | DETACHED_PROCESS, NULL, NULL,
112  &start_info, &proc_info))
113  return;
114 #else
115  int pid = fork();
116  if (pid != 0) { // The father process returns
117  } else {
118 #ifdef __linux__
119  // Make sure the java process terminates on exit, since its
120  // broken socket detection seems to be useless.
121  prctl(PR_SET_PDEATHSIG, 2, 0, 0, 0);
122 #endif
123  char* mutable_args = strdup(args);
124  int argc = 1;
125  for (int i = 0; mutable_args[i]; ++i) {
126  if (mutable_args[i] == ' ') {
127  ++argc;
128  }
129  }
130  char** argv = new char*[argc + 2];
131  argv[0] = strdup(executable);
132  argv[1] = mutable_args;
133  argc = 2;
134  bool inquote = false;
135  for (int i = 0; mutable_args[i]; ++i) {
136  if (!inquote && mutable_args[i] == ' ') {
137  mutable_args[i] = '\0';
138  argv[argc++] = mutable_args + i + 1;
139  } else if (mutable_args[i] == '"') {
140  inquote = !inquote;
141  mutable_args[i] = ' ';
142  }
143  }
144  argv[argc] = NULL;
145  execvp(executable, argv);
146  free(argv[0]);
147  free(argv[1]);
148  delete[] argv;
149  }
150 #endif
151 }
#define FALSE
Definition: capi.h:46

◆ StartThread()

void SVSync::StartThread ( void *(*)(void *)  func,
void *  arg 
)
static

Create new thread.

Definition at line 192 of file svutil.cpp.

192  {
193 #ifdef _WIN32
194  LPTHREAD_START_ROUTINE f = (LPTHREAD_START_ROUTINE) func;
195  DWORD threadid;
196  HANDLE newthread = CreateThread(
197  NULL, // default security attributes
198  0, // use default stack size
199  f, // thread function
200  arg, // argument to thread function
201  0, // use default creation flags
202  &threadid); // returns the thread identifier
203 #else
204  pthread_t helper;
205  pthread_attr_t attr;
206  pthread_attr_init(&attr);
207  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
208  pthread_create(&helper, &attr, func, arg);
209 #endif
210 }

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