init_windows.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2017. See AUTHORS.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // +build windows
  15. package openssl
  16. /*
  17. #include <errno.h>
  18. #include <openssl/crypto.h>
  19. #include <windows.h>
  20. CRITICAL_SECTION* goopenssl_locks;
  21. int go_init_locks() {
  22. int rc = 0;
  23. int nlock;
  24. int i;
  25. int locks_needed = CRYPTO_num_locks();
  26. goopenssl_locks = (CRITICAL_SECTION*)malloc(
  27. sizeof(*goopenssl_locks) * locks_needed);
  28. if (!goopenssl_locks) {
  29. return ENOMEM;
  30. }
  31. for (nlock = 0; nlock < locks_needed; ++nlock) {
  32. InitializeCriticalSection(&goopenssl_locks[nlock]);
  33. }
  34. return 0;
  35. }
  36. void go_thread_locking_callback(int mode, int n, const char *file,
  37. int line) {
  38. if (mode & CRYPTO_LOCK) {
  39. EnterCriticalSection(&goopenssl_locks[n]);
  40. } else {
  41. LeaveCriticalSection(&goopenssl_locks[n]);
  42. }
  43. }
  44. */
  45. import "C"