aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/openssl/apps_win.c66
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
74static void (*speed_alarm_handler)(int);
75static HANDLE speed_thread;
76static unsigned int speed_lapse;
77static volatile unsigned int speed_schlock;
78
79void
80speed_signal(int sigcatch, void (*func)(int sigraised))
81{
82 speed_alarm_handler = func;
83}
84
85static DWORD WINAPI
86speed_timer(VOID * arg)
87{
88 speed_schlock = 1;
89 Sleep(speed_lapse);
90 (*speed_alarm_handler)(0);
91 return (0);
92}
93
94unsigned int
95speed_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
115void
116speed_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}