tesseract  4.1.0
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

void SVSync::ExitThread ( )
static

Signals a thread to exit.

Definition at line 104 of file svutil.cpp.

104  {
105 #ifdef _WIN32
106  // ExitThread(0);
107 #else
108  pthread_exit(nullptr);
109 #endif
110 }
void SVSync::StartProcess ( const char *  executable,
const char *  args 
)
static

Starts a new process.

Definition at line 113 of file svutil.cpp.

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

Create new thread.

Definition at line 80 of file svutil.cpp.

80  {
81 #ifdef _WIN32
82  LPTHREAD_START_ROUTINE f = (LPTHREAD_START_ROUTINE)func;
83  DWORD threadid;
84  CreateThread(nullptr, // default security attributes
85  0, // use default stack size
86  f, // thread function
87  arg, // argument to thread function
88  0, // use default creation flags
89  &threadid); // returns the thread identifier
90 #else
91  pthread_t helper;
92  pthread_attr_t attr;
93  pthread_attr_init(&attr);
94  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
95  pthread_create(&helper, &attr, func, arg);
96 #endif
97 }

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