diff options
| author | kinichiro <kinichiro.inoguchi@gmail.com> | 2019-07-14 18:37:59 +0900 |
|---|---|---|
| committer | kinichiro <kinichiro.inoguchi@gmail.com> | 2019-07-14 19:45:34 +0900 |
| commit | 30e91bc6d2b6249da1c8c40582c63601a4838efc (patch) | |
| tree | d2fd609548d6eaf47c3751da052367cc433e708b /apps | |
| parent | 9e5a54ac9221c906c13a34722811884c0179adc1 (diff) | |
| download | portable-30e91bc6d2b6249da1c8c40582c63601a4838efc.tar.gz portable-30e91bc6d2b6249da1c8c40582c63601a4838efc.tar.bz2 portable-30e91bc6d2b6249da1c8c40582c63601a4838efc.zip | |
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
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/openssl/apps_win.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/apps/openssl/apps_win.c b/apps/openssl/apps_win.c index 364c033..ba7b1e6 100644 --- a/apps/openssl/apps_win.c +++ b/apps/openssl/apps_win.c | |||
| @@ -70,3 +70,69 @@ destroy_ui(void) | |||
| 70 | ui_method = NULL; | 70 | ui_method = NULL; |
| 71 | } | 71 | } |
| 72 | } | 72 | } |
| 73 | |||
| 74 | static void (*speed_alarm_handler)(int); | ||
| 75 | static HANDLE speed_thread; | ||
| 76 | static unsigned int speed_lapse; | ||
| 77 | static volatile unsigned int speed_schlock; | ||
| 78 | |||
| 79 | void | ||
| 80 | speed_signal(int sigcatch, void (*func)(int sigraised)) | ||
| 81 | { | ||
| 82 | speed_alarm_handler = func; | ||
| 83 | } | ||
| 84 | |||
| 85 | static DWORD WINAPI | ||
| 86 | speed_timer(VOID * arg) | ||
| 87 | { | ||
| 88 | speed_schlock = 1; | ||
| 89 | Sleep(speed_lapse); | ||
| 90 | (*speed_alarm_handler)(0); | ||
| 91 | return (0); | ||
| 92 | } | ||
| 93 | |||
| 94 | unsigned int | ||
| 95 | speed_alarm(unsigned int seconds) | ||
| 96 | { | ||
| 97 | DWORD err; | ||
| 98 | |||
| 99 | speed_lapse = seconds * 1000; | ||
| 100 | speed_schlock = 0; | ||
| 101 | |||
| 102 | speed_thread = CreateThread(NULL, 4096, speed_timer, NULL, 0, NULL); | ||
| 103 | if (speed_thread == NULL) { | ||
| 104 | err = GetLastError(); | ||
| 105 | BIO_printf(bio_err, "CreateThread failed (%lu)", err); | ||
| 106 | ExitProcess(err); | ||
| 107 | } | ||
| 108 | |||
| 109 | while (!speed_schlock) | ||
| 110 | Sleep(0); | ||
| 111 | |||
| 112 | return (seconds); | ||
| 113 | } | ||
| 114 | |||
| 115 | void | ||
| 116 | speed_alarm_free(int run) | ||
| 117 | { | ||
| 118 | DWORD err; | ||
| 119 | |||
| 120 | if (run) { | ||
| 121 | if (TerminateThread(speed_thread, 0) == 0) { | ||
| 122 | err = GetLastError(); | ||
| 123 | BIO_printf(bio_err, "TerminateThread failed (%lu)", | ||
| 124 | err); | ||
| 125 | ExitProcess(err); | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 129 | if (CloseHandle(speed_thread) == 0) { | ||
| 130 | err = GetLastError(); | ||
| 131 | BIO_printf(bio_err, "CloseHandle failed (%lu)", err); | ||
| 132 | ExitProcess(err); | ||
| 133 | } | ||
| 134 | |||
| 135 | speed_thread = NULL; | ||
| 136 | speed_lapse = 0; | ||
| 137 | speed_schlock = 0; | ||
| 138 | } | ||
