tesseract  4.0.0-1-g2a2b
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 46 of file svutil.h.

Member Function Documentation

◆ ExitThread()

void SVSync::ExitThread ( )
static

Signals a thread to exit.

Definition at line 111 of file svutil.cpp.

111  {
112 #ifdef _WIN32
113  // ExitThread(0);
114 #else
115  pthread_exit(nullptr);
116 #endif
117 }

◆ StartProcess()

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

Starts a new process.

Definition at line 120 of file svutil.cpp.

120  {
121  std::string proc;
122  proc.append(executable);
123  proc.append(" ");
124  proc.append(args);
125  std::cout << "Starting " << proc << std::endl;
126 #ifdef _WIN32
127  STARTUPINFO start_info;
128  PROCESS_INFORMATION proc_info;
129  GetStartupInfo(&start_info);
130  if (!CreateProcess(nullptr, const_cast<char*>(proc.c_str()), nullptr, nullptr, FALSE,
131  CREATE_NO_WINDOW | DETACHED_PROCESS, nullptr, nullptr,
132  &start_info, &proc_info))
133  return;
134 #else
135  int pid = fork();
136  if (pid != 0) { // The father process returns
137  } else {
138 #ifdef __linux__
139  // Make sure the java process terminates on exit, since its
140  // broken socket detection seems to be useless.
141  prctl(PR_SET_PDEATHSIG, 2, 0, 0, 0);
142 #endif
143  char* mutable_args = strdup(args);
144  int argc = 1;
145  for (int i = 0; mutable_args[i]; ++i) {
146  if (mutable_args[i] == ' ') {
147  ++argc;
148  }
149  }
150  std::unique_ptr<char*[]> argv(new char*[argc + 2]);
151  argv[0] = strdup(executable);
152  argv[1] = mutable_args;
153  argc = 2;
154  bool inquote = false;
155  for (int i = 0; mutable_args[i]; ++i) {
156  if (!inquote && mutable_args[i] == ' ') {
157  mutable_args[i] = '\0';
158  argv[argc++] = mutable_args + i + 1;
159  } else if (mutable_args[i] == '"') {
160  inquote = !inquote;
161  mutable_args[i] = ' ';
162  }
163  }
164  argv[argc] = nullptr;
165  execvp(executable, argv.get());
166  free(argv[0]);
167  free(argv[1]);
168  }
169 #endif
170 }
#define FALSE
Definition: capi.h:52

◆ StartThread()

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

Create new thread.

Definition at line 87 of file svutil.cpp.

87  {
88 #ifdef _WIN32
89  LPTHREAD_START_ROUTINE f = (LPTHREAD_START_ROUTINE)func;
90  DWORD threadid;
91  HANDLE newthread = CreateThread(nullptr, // default security attributes
92  0, // use default stack size
93  f, // thread function
94  arg, // argument to thread function
95  0, // use default creation flags
96  &threadid); // returns the thread identifier
97 #else
98  pthread_t helper;
99  pthread_attr_t attr;
100  pthread_attr_init(&attr);
101  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
102  pthread_create(&helper, &attr, func, arg);
103 #endif
104 }

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