Hash :
30e91bc6
Author :
Date :
2019-07-14T18:37:59
Enable speed on win32 - Use thread and sleep instead of signal and alarm, on win32 - Disable -multi option on win32 since fork is hard to implement
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
/*
* Public domain
*
* Dongsheng Song <dongsheng.song@gmail.com>
* Brent Cook <bcook@openbsd.org>
*/
#include <windows.h>
#include <io.h>
#include <fcntl.h>
#include "apps.h"
double
app_timer_real(int get)
{
static __int64 start;
__int64 now;
now = GetTickCount64();
if (get) {
return (now - start) / 1000.0;
}
start = now;
return 0.0;
}
double
app_timer_user(int stop)
{
static unsigned __int64 tmstart;
union {
unsigned __int64 u64;
FILETIME ft;
} ct, et, kt, ut;
GetProcessTimes(GetCurrentProcess(), &ct.ft, &et.ft, &kt.ft, &ut.ft);
if (stop)
return (ut.u64 + kt.u64 - tmstart) / (double) 10000000;
tmstart = ut.u64 + kt.u64;
return 0.0;
}
int
setup_ui(void)
{
ui_method = UI_create_method("OpenSSL application user interface");
UI_method_set_opener(ui_method, ui_open);
UI_method_set_reader(ui_method, ui_read);
UI_method_set_writer(ui_method, ui_write);
UI_method_set_closer(ui_method, ui_close);
/*
* Set STDIO to binary
*/
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
_setmode(_fileno(stderr), _O_BINARY);
return 0;
}
void
destroy_ui(void)
{
if (ui_method) {
UI_destroy_method(ui_method);
ui_method = NULL;
}
}
static void (*speed_alarm_handler)(int);
static HANDLE speed_thread;
static unsigned int speed_lapse;
static volatile unsigned int speed_schlock;
void
speed_signal(int sigcatch, void (*func)(int sigraised))
{
speed_alarm_handler = func;
}
static DWORD WINAPI
speed_timer(VOID * arg)
{
speed_schlock = 1;
Sleep(speed_lapse);
(*speed_alarm_handler)(0);
return (0);
}
unsigned int
speed_alarm(unsigned int seconds)
{
DWORD err;
speed_lapse = seconds * 1000;
speed_schlock = 0;
speed_thread = CreateThread(NULL, 4096, speed_timer, NULL, 0, NULL);
if (speed_thread == NULL) {
err = GetLastError();
BIO_printf(bio_err, "CreateThread failed (%lu)", err);
ExitProcess(err);
}
while (!speed_schlock)
Sleep(0);
return (seconds);
}
void
speed_alarm_free(int run)
{
DWORD err;
if (run) {
if (TerminateThread(speed_thread, 0) == 0) {
err = GetLastError();
BIO_printf(bio_err, "TerminateThread failed (%lu)",
err);
ExitProcess(err);
}
}
if (CloseHandle(speed_thread) == 0) {
err = GetLastError();
BIO_printf(bio_err, "CloseHandle failed (%lu)", err);
ExitProcess(err);
}
speed_thread = NULL;
speed_lapse = 0;
speed_schlock = 0;
}