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 "fspr_portable.h"
  17. #include "fspr_arch_threadproc.h"
  18. fspr_status_t fspr_threadkey_private_create(fspr_threadkey_t **key,
  19. void (*dest)(void *), fspr_pool_t *pool)
  20. {
  21. fspr_status_t stat;
  22. (*key) = (fspr_threadkey_t *)fspr_palloc(pool, sizeof(fspr_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. fspr_status_t fspr_threadkey_private_get(void **new, fspr_threadkey_t *key)
  33. {
  34. fspr_status_t stat;
  35. if ((stat = NXKeyGetValue(key->key, new)) == 0) {
  36. return APR_SUCCESS;
  37. }
  38. else {
  39. return stat;
  40. }
  41. }
  42. fspr_status_t fspr_threadkey_private_set(void *priv, fspr_threadkey_t *key)
  43. {
  44. fspr_status_t stat;
  45. if ((stat = NXKeySetValue(key->key, priv)) == 0) {
  46. return APR_SUCCESS;
  47. }
  48. else {
  49. return stat;
  50. }
  51. }
  52. fspr_status_t fspr_threadkey_private_delete(fspr_threadkey_t *key)
  53. {
  54. fspr_status_t stat;
  55. if ((stat = NXKeyDelete(key->key)) == 0) {
  56. return APR_SUCCESS;
  57. }
  58. return stat;
  59. }
  60. fspr_status_t fspr_threadkey_data_get(void **data, const char *key, fspr_threadkey_t *threadkey)
  61. {
  62. return fspr_pool_userdata_get(data, key, threadkey->pool);
  63. }
  64. fspr_status_t fspr_threadkey_data_set(void *data,
  65. const char *key, fspr_status_t (*cleanup) (void *),
  66. fspr_threadkey_t *threadkey)
  67. {
  68. return fspr_pool_userdata_set(data, key, cleanup, threadkey->pool);
  69. }
  70. 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. fspr_status_t fspr_os_threadkey_put(fspr_threadkey_t **key,
  77. fspr_os_threadkey_t *thekey, fspr_pool_t *pool)
  78. {
  79. if (pool == NULL) {
  80. return APR_ENOPOOL;
  81. }
  82. if ((*key) == NULL) {
  83. (*key) = (fspr_threadkey_t *)fspr_palloc(pool, sizeof(fspr_threadkey_t));
  84. (*key)->pool = pool;
  85. }
  86. (*key)->key = *thekey;
  87. return APR_SUCCESS;
  88. }