1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
#include "apr_arch_threadproc.h"
19
static struct beos_key key_table[BEOS_MAX_DATAKEYS];
20
static struct beos_private_data *beos_data[BEOS_MAX_DATAKEYS];
23
APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key,
24
void (*dest)(void *), apr_pool_t *pool)
26
(*key) = (apr_threadkey_t *)apr_palloc(pool, sizeof(apr_threadkey_t));
34
for ((*key)->key=0; (*key)->key < BEOS_MAX_DATAKEYS; (*key)->key++){
35
if (key_table[(*key)->key].assigned == 0){
36
key_table[(*key)->key].assigned = 1;
37
key_table[(*key)->key].destructor = dest;
47
APR_DECLARE(apr_status_t) apr_threadkey_private_get(void **new, apr_threadkey_t *key)
51
tid = find_thread(NULL);
52
for (i=0;i<BEOS_MAX_DATAKEYS;i++){
53
if (beos_data[i]->data){
55
if (beos_data[i]->td == tid){
61
/* no storage for thread so we can't get anything... */
65
if ((key->key < BEOS_MAX_DATAKEYS) && (key_table)){
66
acquire_sem(key_table[key->key].lock);
67
if (key_table[key->key].count){
68
(*new) = (void*)beos_data[index]->data[key->key];
72
release_sem(key_table[key->key].lock);
79
APR_DECLARE(apr_status_t) apr_threadkey_private_set(void *priv, apr_threadkey_t *key)
82
int i,index = 0, ret = 0;
84
tid = find_thread(NULL);
85
for (i=0; i < BEOS_MAX_DATAKEYS; i++){
86
if (beos_data[i]->data){
87
if (beos_data[i]->td == tid){index = i;}
91
/* not yet been allocated */
92
for (i=0; i< BEOS_MAX_DATAKEYS; i++){
93
if (! beos_data[i]->data){
94
/* we'll take this one... */
96
beos_data[i]->data = (const void **)malloc(sizeof(void *) * BEOS_MAX_DATAKEYS);
97
memset((void *)beos_data[i]->data, 0, sizeof(void *) * BEOS_MAX_DATAKEYS);
98
beos_data[i]->count = (int)malloc(sizeof(int));
99
beos_data[i]->td = (thread_id)malloc(sizeof(thread_id));
100
beos_data[i]->td = tid;
105
/* we're out of luck.. */
108
if ((key->key < BEOS_MAX_DATAKEYS) && (key_table)){
109
acquire_sem(key_table[key->key].lock);
110
if (key_table[key->key].count){
111
if (beos_data[index]->data[key->key] == NULL){
113
beos_data[index]->count++;
114
key_table[key->key].count++;
118
beos_data[index]->count--;
119
key_table[key->key].count--;
122
beos_data[index]->data[key->key] = priv;
127
release_sem(key_table[key->key].lock);
134
APR_DECLARE(apr_status_t) apr_threadkey_private_delete(apr_threadkey_t *key)
136
if (key->key < BEOS_MAX_DATAKEYS){
137
acquire_sem(key_table[key->key].lock);
138
if (key_table[key->key].count == 1){
139
key_table[key->key].destructor = NULL;
140
key_table[key->key].count = 0;
142
release_sem(key_table[key->key].lock);
149
APR_DECLARE(apr_status_t) apr_threadkey_data_get(void **data, const char *key,
150
apr_threadkey_t *threadkey)
152
return apr_pool_userdata_get(data, key, threadkey->pool);
155
APR_DECLARE(apr_status_t) apr_threadkey_data_set(void *data, const char *key,
156
apr_status_t (*cleanup) (void *),
157
apr_threadkey_t *threadkey)
159
return apr_pool_userdata_set(data, key, cleanup, threadkey->pool);
162
APR_DECLARE(apr_status_t) apr_os_threadkey_get(apr_os_threadkey_t *thekey, apr_threadkey_t *key)
168
APR_DECLARE(apr_status_t) apr_os_threadkey_put(apr_threadkey_t **key,
169
apr_os_threadkey_t *thekey, apr_pool_t *pool)
174
if ((*key) == NULL) {
175
(*key) = (apr_threadkey_t *)apr_pcalloc(pool, sizeof(apr_threadkey_t));
178
(*key)->key = *thekey;