threadpriv.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 "apr_portable.h"
  17. #include "apr_arch_threadproc.h"
  18. apr_status_t apr_threadkey_private_create(apr_threadkey_t **key,
  19. void (*dest)(void *), apr_pool_t *pool)
  20. {
  21. apr_status_t stat;
  22. (*key) = (apr_threadkey_t *)apr_palloc(pool, sizeof(apr_threadkey_t));
  23. if ((*key) == NULL) {
  24. return APR_ENOMEM;
  25. }
  26. (*key)->pool = pool;
  27. if ((stat = NXKeyCreate(NULL, dest, &(*key)->key)) == 0) {
  28. return stat;
  29. }
  30. return stat;
  31. }
  32. apr_status_t apr_threadkey_private_get(void **new, apr_threadkey_t *key)
  33. {
  34. apr_status_t stat;
  35. if ((stat = NXKeyGetValue(key->key, new)) == 0) {
  36. return APR_SUCCESS;
  37. }
  38. else {
  39. return stat;
  40. }
  41. }
  42. apr_status_t apr_threadkey_private_set(void *priv, apr_threadkey_t *key)
  43. {
  44. apr_status_t stat;
  45. if ((stat = NXKeySetValue(key->key, priv)) == 0) {
  46. return APR_SUCCESS;
  47. }
  48. else {
  49. return stat;
  50. }
  51. }
  52. apr_status_t apr_threadkey_private_delete(apr_threadkey_t *key)
  53. {
  54. apr_status_t stat;
  55. if ((stat = NXKeyDelete(key->key)) == 0) {
  56. return APR_SUCCESS;
  57. }
  58. return stat;
  59. }
  60. apr_status_t apr_threadkey_data_get(void **data, const char *key, apr_threadkey_t *threadkey)
  61. {
  62. return apr_pool_userdata_get(data, key, threadkey->pool);
  63. }
  64. apr_status_t apr_threadkey_data_set(void *data,
  65. const char *key, 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_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_status_t apr_os_threadkey_put(apr_threadkey_t **key,
  77. apr_os_threadkey_t *thekey, apr_pool_t *pool)
  78. {
  79. if (pool == NULL) {
  80. return APR_ENOPOOL;
  81. }
  82. if ((*key) == NULL) {
  83. (*key) = (apr_threadkey_t *)apr_palloc(pool, sizeof(apr_threadkey_t));
  84. (*key)->pool = pool;
  85. }
  86. (*key)->key = *thekey;
  87. return APR_SUCCESS;
  88. }