All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 55 of file svutil.h.

Member Function Documentation

void SVSync::ExitThread ( )
static

Signals a thread to exit.

Definition at line 66 of file svutil.cpp.

66  {
67 #ifdef _WIN32
68  // ExitThread(0);
69 #else
70  pthread_exit(0);
71 #endif
72 }
void SVSync::StartProcess ( const char *  executable,
const char *  args 
)
static

Starts a new process.

Definition at line 75 of file svutil.cpp.

75  {
76  std::string proc;
77  proc.append(executable);
78  proc.append(" ");
79  proc.append(args);
80  std::cout << "Starting " << proc << std::endl;
81 #ifdef _WIN32
82  STARTUPINFO start_info;
83  PROCESS_INFORMATION proc_info;
84  GetStartupInfo(&start_info);
85  if (!CreateProcess(NULL, const_cast<char*>(proc.c_str()), NULL, NULL, FALSE,
86  CREATE_NO_WINDOW | DETACHED_PROCESS, NULL, NULL,
87  &start_info, &proc_info))
88  return;
89 #else
90  int pid = fork();
91  if (pid != 0) { // The father process returns
92  } else {
93 #ifdef __linux__
94  // Make sure the java process terminates on exit, since its
95  // broken socket detection seems to be useless.
96  prctl(PR_SET_PDEATHSIG, 2, 0, 0, 0);
97 #endif
98  char* mutable_args = strdup(args);
99  int argc = 1;
100  for (int i = 0; mutable_args[i]; ++i) {
101  if (mutable_args[i] == ' ') {
102  ++argc;
103  }
104  }
105  char** argv = new char*[argc + 2];
106  argv[0] = strdup(executable);
107  argv[1] = mutable_args;
108  argc = 2;
109  bool inquote = false;
110  for (int i = 0; mutable_args[i]; ++i) {
111  if (!inquote && mutable_args[i] == ' ') {
112  mutable_args[i] = '\0';
113  argv[argc++] = mutable_args + i + 1;
114  } else if (mutable_args[i] == '"') {
115  inquote = !inquote;
116  mutable_args[i] = ' ';
117  }
118  }
119  argv[argc] = NULL;
120  execvp(executable, argv);
121  }
122 #endif
123 }
#define FALSE
Definition: capi.h:29
#define NULL
Definition: host.h:144
void SVSync::StartThread ( void *(*)(void *)  func,
void *  arg 
)
static

Create new thread.

Definition at line 187 of file svutil.cpp.

187  {
188 #ifdef _WIN32
189  LPTHREAD_START_ROUTINE f = (LPTHREAD_START_ROUTINE) func;
190  DWORD threadid;
191  HANDLE newthread = CreateThread(
192  NULL, // default security attributes
193  0, // use default stack size
194  f, // thread function
195  arg, // argument to thread function
196  0, // use default creation flags
197  &threadid); // returns the thread identifier
198 #else
199  pthread_t helper;
200  pthread_create(&helper, NULL, func, arg);
201 #endif
202 }
#define NULL
Definition: host.h:144

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