2
0

threadpriv.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "win32/apr_arch_threadproc.h"
  17. #include "apr_thread_proc.h"
  18. #include "apr_general.h"
  19. #include "apr_lib.h"
  20. #include "apr_errno.h"
  21. #include "apr_portable.h"
  22. APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key,
  23. void (*dest)(void *),
  24. apr_pool_t *pool)
  25. {
  26. (*key) = (apr_threadkey_t *)apr_palloc(pool, sizeof(apr_threadkey_t));
  27. if ((*key) == NULL) {
  28. return APR_ENOMEM;
  29. }
  30. (*key)->pool = pool;
  31. if (((*key)->key = TlsAlloc()) != 0xFFFFFFFF) {
  32. return APR_SUCCESS;
  33. }
  34. return apr_get_os_error();
  35. }
  36. APR_DECLARE(apr_status_t) apr_threadkey_private_get(void **new,
  37. apr_threadkey_t *key)
  38. {
  39. if ((*new) = TlsGetValue(key->key)) {
  40. return APR_SUCCESS;
  41. }
  42. return apr_get_os_error();
  43. }
  44. APR_DECLARE(apr_status_t) apr_threadkey_private_set(void *priv,
  45. apr_threadkey_t *key)
  46. {
  47. if (TlsSetValue(key->key, priv)) {
  48. return APR_SUCCESS;
  49. }
  50. return apr_get_os_error();
  51. }
  52. APR_DECLARE(apr_status_t) apr_threadkey_private_delete(apr_threadkey_t *key)
  53. {
  54. if (TlsFree(key->key)) {
  55. return APR_SUCCESS;
  56. }
  57. return apr_get_os_error();
  58. }
  59. APR_DECLARE(apr_status_t) apr_threadkey_data_get(void **data, const char *key,
  60. apr_threadkey_t *threadkey)
  61. {
  62. return apr_pool_userdata_get(data, key, threadkey->pool);
  63. }
  64. APR_DECLARE(apr_status_t) apr_threadkey_data_set(void *data, const char *key,
  65. apr_status_t (*cleanup)(void *),
  66. apr_threadkey_t *threadkey)
  67. {
  68. return apr_pool_userdata_set(data, key, cleanup, threadkey->pool);
  69. }
  70. APR_DECLARE(apr_status_t) apr_os_threadkey_get(apr_os_threadkey_t *thekey,
  71. apr_threadkey_t *key)
  72. {
  73. *thekey = key->key;
  74. return APR_SUCCESS;
  75. }
  76. APR_DECLARE(apr_status_t) apr_os_threadkey_put(apr_threadkey_t **key,
  77. apr_os_threadkey_t *thekey,
  78. apr_pool_t *pool)
  79. {
  80. if (pool == NULL) {
  81. return APR_ENOPOOL;
  82. }
  83. if ((*key) == NULL) {
  84. (*key) = (apr_threadkey_t *)apr_palloc(pool, sizeof(apr_threadkey_t));
  85. (*key)->pool = pool;
  86. }
  87. (*key)->key = *thekey;
  88. return APR_SUCCESS;
  89. }