]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/threads_none.c
Remove tab characters from C source files.
[thirdparty/openssl.git] / crypto / threads_none.c
CommitLineData
62867571 1/*
28428130 2 * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
71a04cfc 3 *
0e9725bc 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
62867571
RS
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
71a04cfc
AG
8 */
9
10#include <openssl/crypto.h>
5f8dd0f8 11#include "internal/cryptlib.h"
71a04cfc
AG
12
13#if !defined(OPENSSL_THREADS) || defined(CRYPTO_TDEBUG)
14
15CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)
16{
7de2b9c4
RS
17 CRYPTO_RWLOCK *lock;
18
19 if ((lock = OPENSSL_zalloc(sizeof(unsigned int))) == NULL) {
20 /* Don't set error, to avoid recursion blowup. */
71a04cfc 21 return NULL;
7de2b9c4 22 }
71a04cfc
AG
23
24 *(unsigned int *)lock = 1;
25
26 return lock;
27}
28
29int CRYPTO_THREAD_read_lock(CRYPTO_RWLOCK *lock)
30{
fb7621cb
MC
31 if (!ossl_assert(*(unsigned int *)lock == 1))
32 return 0;
71a04cfc
AG
33 return 1;
34}
35
36int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)
37{
fb7621cb
MC
38 if (!ossl_assert(*(unsigned int *)lock == 1))
39 return 0;
71a04cfc
AG
40 return 1;
41}
42
43int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock)
44{
fb7621cb
MC
45 if (!ossl_assert(*(unsigned int *)lock == 1))
46 return 0;
71a04cfc
AG
47 return 1;
48}
49
50void CRYPTO_THREAD_lock_free(CRYPTO_RWLOCK *lock) {
51 if (lock == NULL)
52 return;
53
54 *(unsigned int *)lock = 0;
55 OPENSSL_free(lock);
56
57 return;
58}
59
60int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))
61{
62 if (*once != 0)
63 return 1;
64
65 init();
66 *once = 1;
67
68 return 1;
69}
70
71#define OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX 256
72
73static void *thread_local_storage[OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX];
74
75int CRYPTO_THREAD_init_local(CRYPTO_THREAD_LOCAL *key, void (*cleanup)(void *))
76{
77 static unsigned int thread_local_key = 0;
78
79 if (thread_local_key >= OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX)
80 return 0;
81
82 *key = thread_local_key++;
83
84 thread_local_storage[*key] = NULL;
85
86 return 1;
87}
88
89void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)
90{
91 if (*key >= OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX)
92 return NULL;
93
94 return thread_local_storage[*key];
95}
96
97int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val)
98{
99 if (*key >= OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX)
100 return 0;
101
102 thread_local_storage[*key] = val;
103
104 return 1;
105}
106
107int CRYPTO_THREAD_cleanup_local(CRYPTO_THREAD_LOCAL *key)
108{
109 *key = OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX + 1;
110 return 1;
111}
112
113CRYPTO_THREAD_ID CRYPTO_THREAD_get_current_id(void)
114{
115 return 0;
116}
117
118int CRYPTO_THREAD_compare_id(CRYPTO_THREAD_ID a, CRYPTO_THREAD_ID b)
119{
120 return (a == b);
121}
122
123int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
124{
125 *val += amount;
126 *ret = *val;
127
128 return 1;
129}
130
2915fe19
RS
131int openssl_init_fork_handlers(void)
132{
133 return 0;
134}
135
71a04cfc 136#endif