tesseract  4.1.1
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 105 of file svutil.cpp.

105  {
106 #ifdef _WIN32
107  // ExitThread(0);
108 #else
109  pthread_exit(nullptr);
110 #endif
111 }

◆ StartProcess()

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

Starts a new process.

Definition at line 114 of file svutil.cpp.

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

◆ StartThread()

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

Create new thread.

Definition at line 81 of file svutil.cpp.

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

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