tesseract  4.1.3
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 36 of file svutil.h.

Member Function Documentation

◆ ExitThread()

void SVSync::ExitThread ( )
static

Signals a thread to exit.

Definition at line 113 of file svutil.cpp.

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

◆ StartProcess()

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

Starts a new process.

Definition at line 122 of file svutil.cpp.

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

◆ StartThread()

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

Create new thread.

Definition at line 89 of file svutil.cpp.

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

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