diff options
Diffstat (limited to 'crypto/compat/crypto_lock_win.c')
| -rw-r--r-- | crypto/compat/crypto_lock_win.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/crypto/compat/crypto_lock_win.c b/crypto/compat/crypto_lock_win.c new file mode 100644 index 0000000..47c3dcc --- /dev/null +++ b/crypto/compat/crypto_lock_win.c | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | /* $OpenBSD: crypto_lock.c,v 1.1 2018/11/11 06:41:28 bcook Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2018 Brent Cook <bcook@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <windows.h> | ||
| 19 | |||
| 20 | static HANDLE locks[CRYPTO_NUM_LOCKS]; | ||
| 21 | |||
| 22 | void | ||
| 23 | crypto_init_locks(void) | ||
| 24 | { | ||
| 25 | int i; | ||
| 26 | |||
| 27 | for (i = 0; i < CRYPTO_NUM_LOCKS; i++) | ||
| 28 | locks[i] = CreateMutex(NULL, FALSE, NULL); | ||
| 29 | } | ||
| 30 | |||
| 31 | void | ||
| 32 | CRYPTO_lock(int mode, int type, const char *file, int line) | ||
| 33 | { | ||
| 34 | if (type < 0 || type >= CRYPTO_NUM_LOCKS) | ||
| 35 | return; | ||
| 36 | |||
| 37 | if (mode & CRYPTO_LOCK) | ||
| 38 | WaitForSingleObject(locks[type], INFINITE); | ||
| 39 | else | ||
| 40 | ReleaseMutex(locks[type]); | ||
| 41 | } | ||
| 42 | |||
| 43 | int | ||
| 44 | CRYPTO_add_lock(int *pointer, int amount, int type, const char *file, | ||
| 45 | int line) | ||
| 46 | { | ||
| 47 | int ret = 0; | ||
| 48 | CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE, type, file, line); | ||
| 49 | ret = *pointer + amount; | ||
| 50 | *pointer = ret; | ||
| 51 | CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE, type, file, line); | ||
| 52 | return (ret); | ||
| 53 | } | ||
