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/fspr_arch_threadproc.h"
  17. #include "fspr_thread_proc.h"
  18. #include "fspr_general.h"
  19. #include "fspr_lib.h"
  20. #include "fspr_errno.h"
  21. #include "fspr_portable.h"
  22. APR_DECLARE(fspr_status_t) fspr_threadkey_private_create(fspr_threadkey_t **key,
  23. void (*dest)(void *),
  24. fspr_pool_t *pool)
  25. {
  26. (*key) = (fspr_threadkey_t *)fspr_palloc(pool, sizeof(fspr_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 fspr_get_os_error();
  35. }
  36. APR_DECLARE(fspr_status_t) fspr_threadkey_private_get(void **new,
  37. fspr_threadkey_t *key)
  38. {
  39. if ((*new) = TlsGetValue(key->key)) {
  40. return APR_SUCCESS;
  41. }
  42. return fspr_get_os_error();
  43. }
  44. APR_DECLARE(fspr_status_t) fspr_threadkey_private_set(void *priv,
  45. fspr_threadkey_t *key)
  46. {
  47. if (TlsSetValue(key->key, priv)) {
  48. return APR_SUCCESS;
  49. }
  50. return fspr_get_os_error();
  51. }
  52. APR_DECLARE(fspr_status_t) fspr_threadkey_private_delete(fspr_threadkey_t *key)
  53. {
  54. if (TlsFree(key->key)) {
  55. return APR_SUCCESS;
  56. }
  57. return fspr_get_os_error();
  58. }
  59. APR_DECLARE(fspr_status_t) fspr_threadkey_data_get(void **data, const char *key,
  60. fspr_threadkey_t *threadkey)
  61. {
  62. return fspr_pool_userdata_get(data, key, threadkey->pool);
  63. }
  64. APR_DECLARE(fspr_status_t) fspr_threadkey_data_set(void *data, const char *key,
  65. fspr_status_t (*cleanup)(void *),
  66. fspr_threadkey_t *threadkey)
  67. {
  68. return fspr_pool_userdata_set(data, key, cleanup, threadkey->pool);
  69. }
  70. APR_DECLARE(fspr_status_t) fspr_os_threadkey_get(fspr_os_threadkey_t *thekey,
  71. fspr_threadkey_t *key)
  72. {
  73. *thekey = key->key;
  74. return APR_SUCCESS;
  75. }
  76. APR_DECLARE(fspr_status_t) fspr_os_threadkey_put(fspr_threadkey_t **key,
  77. fspr_os_threadkey_t *thekey,
  78. fspr_pool_t *pool)
  79. {
  80. if (pool == NULL) {
  81. return APR_ENOPOOL;
  82. }
  83. if ((*key) == NULL) {
  84. (*key) = (fspr_threadkey_t *)fspr_palloc(pool, sizeof(fspr_threadkey_t));
  85. (*key)->pool = pool;
  86. }
  87. (*key)->key = *thekey;
  88. return APR_SUCCESS;
  89. }