24 #ifndef PCM_UTILS_HEADER
25 #define PCM_UTILS_HEADER
50 void set_post_cleanup_callback(
void(*cb)(
void));
53 inline void win_usleep(
int delay_us)
55 uint64 t1 = 0, t2 = 0, freq = 0;
57 QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
58 wait_tick = freq * delay_us / 1000000ULL;
59 QueryPerformanceCounter((LARGE_INTEGER *)&t1);
61 QueryPerformanceCounter((LARGE_INTEGER *)&t2);
63 }
while ((t2 - t1) < wait_tick);
67 inline void MySleep(
int delay)
70 if (delay) Sleep(delay * 1000);
76 inline void MySleepMs(
int delay_ms)
79 if (delay_ms) Sleep((DWORD)delay_ms);
81 struct timespec sleep_intrval;
82 double complete_seconds;
83 sleep_intrval.tv_nsec =
static_cast<long>(1000000000.0 * (::modf(delay_ms / 1000.0, &complete_seconds)));
84 sleep_intrval.tv_sec =
static_cast<time_t
>(complete_seconds);
85 ::nanosleep(&sleep_intrval, NULL);
89 inline void MySleepUs(
int delay_us)
92 if (delay_us) win_usleep(delay_us);
99 void MySystem(
char * sysCmd,
char ** argc);
102 #pragma warning (disable : 4068 ) // disable unknown pragma warning
106 #pragma GCC diagnostic push
107 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
108 #elif defined __clang__
109 #pragma clang diagnostic push
110 #pragma clang diagnostic ignored "-Woverloaded-virtual"
114 void overflow(
char) { }
117 #pragma GCC diagnostic pop
118 #elif defined __clang__
119 #pragma clang diagnostic pop
122 template <
class IntType>
123 inline std::string unit_format(IntType n)
128 snprintf(buffer, 1024,
"%4d ", int32(n));
133 snprintf(buffer, 1024,
"%4d K", int32(n / 1000ULL));
136 if (n <= 9999999999ULL)
138 snprintf(buffer, 1024,
"%4d M", int32(n / 1000000ULL));
141 if (n <= 9999999999999ULL)
143 snprintf(buffer, 1024,
"%4d G", int32(n / 1000000000ULL));
147 snprintf(buffer, 1024,
"%4d T", int32(n / (1000000000ULL * 1000ULL)));
151 void print_cpu_details();
153 #define PCM_UNUSED(x) (void)(x)
155 #define PCM_COMPILE_ASSERT(condition) \
156 typedef char pcm_compile_assert_failed[(condition) ? 1 : -1]; \
157 pcm_compile_assert_failed pcm_compile_assert_failed_; \
158 PCM_UNUSED(pcm_compile_assert_failed_);
161 class ThreadGroupTempAffinity
163 GROUP_AFFINITY PreviousGroupAffinity;
165 ThreadGroupTempAffinity();
166 ThreadGroupTempAffinity(
const ThreadGroupTempAffinity &);
167 ThreadGroupTempAffinity & operator = (
const ThreadGroupTempAffinity &);
170 ThreadGroupTempAffinity(uint32 core_id);
171 ~ThreadGroupTempAffinity();
179 typedef std::istringstream pcm_sscanf;
184 explicit s_expect(
const char * s) : std::string(s) {}
185 explicit s_expect(
const std::string & s) : std::string(s) {}
186 friend std::istream & operator >> (std::istream & istr,
s_expect && s);
187 friend std::istream & operator >> (std::istream && istr,
s_expect && s);
190 void match(std::istream & istr)
const
192 istr >> std::noskipws;
193 const auto len = length();
194 char * buffer =
new char[len + 2];
196 istr.get(buffer, len+1);
197 if (*
this != std::string(buffer))
199 istr.setstate(std::ios_base::failbit);
205 inline std::istream & operator >> (std::istream & istr,
s_expect && s)
211 inline std::istream & operator >> (std::istream && istr,
s_expect && s)
217 inline tm pcm_localtime()
219 time_t now = time(NULL);
222 localtime_s(&result, &now);
224 localtime_r(&now, &result);
void sigCONT_handler(int signum)
handles signals that lead to update of configuration such as SIGCONT
Definition: utils.cpp:231
Internal type and constant definitions.
void set_signal_handlers(void)
install various handlers for system signals
Definition: utils.cpp:240
void sigSTOP_handler(int signum)
handles signals that lead to update of configuration such as SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU
Definition: utils.cpp:209
void MySystem(char *sysCmd, char **argc)
launches external program in a separate process
Definition: utils.cpp:379
void sigUSR_handler(int signum)
handles signals that lead to update of configuration such as SIGUSR1 and SIGUSR2. for the future exte...
Definition: utils.cpp:197
void sigHUP_handler(int signum)
handles signals that lead to restart the application such as SIGHUP. for example to re-read environme...
Definition: utils.cpp:183
void restore_signal_handlers(void)
Restores default signal handlers under Linux/UNIX.
Definition: utils.cpp:337
void sigINT_handler(int signum)
handles signals that lead to termination of the program such as SIGINT, SIGQUIT, SIGABRT, SIGSEGV, SIGTERM, SIGCHLD this function specifically works when the client aplication launched by pcm – terminates
Definition: utils.cpp:164
void exit_cleanup(void)
handler of exit() call
Definition: utils.cpp:35