source: EcnlProtoTool/trunk/openssl-1.1.0e/crypto/threads_win.c@ 331

Last change on this file since 331 was 331, checked in by coas-nagasima, 6 years ago

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 2.8 KB
Line 
1/*
2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
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
8 */
9
10#if defined(_WIN32)
11# include <windows.h>
12#endif
13
14#include <openssl/crypto.h>
15
16#if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG) && defined(OPENSSL_SYS_WINDOWS)
17
18CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)
19{
20 CRYPTO_RWLOCK *lock = OPENSSL_zalloc(sizeof(CRITICAL_SECTION));
21 if (lock == NULL)
22 return NULL;
23
24 /* 0x400 is the spin count value suggested in the documentation */
25 if (!InitializeCriticalSectionAndSpinCount(lock, 0x400)) {
26 OPENSSL_free(lock);
27 return NULL;
28 }
29
30 return lock;
31}
32
33int CRYPTO_THREAD_read_lock(CRYPTO_RWLOCK *lock)
34{
35 EnterCriticalSection(lock);
36 return 1;
37}
38
39int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)
40{
41 EnterCriticalSection(lock);
42 return 1;
43}
44
45int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock)
46{
47 LeaveCriticalSection(lock);
48 return 1;
49}
50
51void CRYPTO_THREAD_lock_free(CRYPTO_RWLOCK *lock)
52{
53 if (lock == NULL)
54 return;
55
56 DeleteCriticalSection(lock);
57 OPENSSL_free(lock);
58
59 return;
60}
61
62# define ONCE_UNINITED 0
63# define ONCE_ININIT 1
64# define ONCE_DONE 2
65
66/*
67 * We don't use InitOnceExecuteOnce because that isn't available in WinXP which
68 * we still have to support.
69 */
70int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))
71{
72 LONG volatile *lock = (LONG *)once;
73 LONG result;
74
75 if (*lock == ONCE_DONE)
76 return 1;
77
78 do {
79 result = InterlockedCompareExchange(lock, ONCE_ININIT, ONCE_UNINITED);
80 if (result == ONCE_UNINITED) {
81 init();
82 *lock = ONCE_DONE;
83 return 1;
84 }
85 } while (result == ONCE_ININIT);
86
87 return (*lock == ONCE_DONE);
88}
89
90int CRYPTO_THREAD_init_local(CRYPTO_THREAD_LOCAL *key, void (*cleanup)(void *))
91{
92 *key = TlsAlloc();
93 if (*key == TLS_OUT_OF_INDEXES)
94 return 0;
95
96 return 1;
97}
98
99void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)
100{
101 return TlsGetValue(*key);
102}
103
104int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val)
105{
106 if (TlsSetValue(*key, val) == 0)
107 return 0;
108
109 return 1;
110}
111
112int CRYPTO_THREAD_cleanup_local(CRYPTO_THREAD_LOCAL *key)
113{
114 if (TlsFree(*key) == 0)
115 return 0;
116
117 return 1;
118}
119
120CRYPTO_THREAD_ID CRYPTO_THREAD_get_current_id(void)
121{
122 return GetCurrentThreadId();
123}
124
125int CRYPTO_THREAD_compare_id(CRYPTO_THREAD_ID a, CRYPTO_THREAD_ID b)
126{
127 return (a == b);
128}
129
130int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
131{
132 *ret = InterlockedExchangeAdd(val, amount) + amount;
133 return 1;
134}
135
136#endif
Note: See TracBrowser for help on using the repository browser.