Apache HTTPD
threadpriv.c
Go to the documentation of this file.
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
17#include "apr_arch_threadproc.h"
18
21static sem_id lock;
22
24 void (*dest)(void *), 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
31 (*key)->pool = pool;
32
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;
39 return APR_SUCCESS;
40 }
41
42 }
44 return APR_ENOMEM;
45}
46
48{
49 thread_id tid;
50 int i, index=0;
51 tid = find_thread(NULL);
52 for (i=0;i<BEOS_MAX_DATAKEYS;i++){
53 if (beos_data[i]->data){
54 /* it's been used */
55 if (beos_data[i]->td == tid){
56 index = i;
57 }
58 }
59 }
60 if (index == 0){
61 /* no storage for thread so we can't get anything... */
62 return APR_ENOMEM;
63 }
64
65 if ((key->key < BEOS_MAX_DATAKEYS) && (key_table)){
67 if (key_table[key->key].count){
68 (*new) = (void*)beos_data[index]->data[key->key];
69 } else {
70 (*new) = NULL;
71 }
73 } else {
74 (*new) = NULL;
75 }
76 return APR_SUCCESS;
77}
78
80{
81 thread_id tid;
82 int i,index = 0, ret = 0;
83
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;}
88 }
89 }
90 if (index==0){
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... */
95 index = i;
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;
101 }
102 }
103 }
104 if (index == 0){
105 /* we're out of luck.. */
106 return APR_ENOMEM;
107 }
108 if ((key->key < BEOS_MAX_DATAKEYS) && (key_table)){
110 if (key_table[key->key].count){
111 if (beos_data[index]->data[key->key] == NULL){
112 if (priv != NULL){
113 beos_data[index]->count++;
114 key_table[key->key].count++;
115 }
116 } else {
117 if (priv == NULL){
118 beos_data[index]->count--;
119 key_table[key->key].count--;
120 }
121 }
122 beos_data[index]->data[key->key] = priv;
123 ret = 1;
124 } else {
125 ret = 0;
126 }
128 }
129 if (ret)
130 return APR_SUCCESS;
131 return APR_ENOMEM;
132}
133
135{
136 if (key->key < BEOS_MAX_DATAKEYS){
138 if (key_table[key->key].count == 1){
140 key_table[key->key].count = 0;
141 }
143 } else {
144 return APR_ENOMEM;
145 }
146 return APR_SUCCESS;
147}
148
151{
152 return apr_pool_userdata_get(data, key, threadkey->pool);
153}
154
156 apr_status_t (*cleanup) (void *),
158{
160}
161
163{
164 *thekey = key->key;
165 return APR_SUCCESS;
166}
167
170{
171 if (pool == NULL) {
172 return APR_ENOPOOL;
173 }
174 if ((*key) == NULL) {
175 (*key) = (apr_threadkey_t *)apr_pcalloc(pool, sizeof(apr_threadkey_t));
176 (*key)->pool = pool;
177 }
178 (*key)->key = *thekey;
179 return APR_SUCCESS;
180}
#define BEOS_MAX_DATAKEYS
static sem_id lock
Definition threadpriv.c:21
static struct beos_private_data * beos_data[BEOS_MAX_DATAKEYS]
Definition threadpriv.c:20
static struct beos_key key_table[BEOS_MAX_DATAKEYS]
Definition threadpriv.c:19
#define APR_ENOMEM
Definition apr_errno.h:683
#define APR_ENOPOOL
Definition apr_errno.h:290
const void apr_status_t(*) apr_status_t(* APR_DECLARE)(void) apr_pool_pre_cleanup_register(apr_pool_t *p
Definition apr_pools.h:646
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
const char * key
void * data
void const char apr_status_t(* cleanup)(void *))
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
apr_status_t apr_threadkey_data_set(void *data, const char *key, apr_status_t(*cleanup)(void *), apr_threadkey_t *threadkey)
Definition threadpriv.c:75
apr_status_t apr_threadkey_private_delete(apr_threadkey_t *key)
Definition threadpriv.c:61
apr_status_t apr_os_threadkey_get(apr_os_threadkey_t *thekey, apr_threadkey_t *key)
Definition threadpriv.c:82
apr_status_t apr_os_threadkey_put(apr_threadkey_t **key, apr_os_threadkey_t *thekey, apr_pool_t *pool)
Definition threadpriv.c:89
apr_status_t apr_threadkey_private_create(apr_threadkey_t **key, void(*dest)(void *), apr_pool_t *pool)
Definition threadpriv.c:20
apr_status_t apr_threadkey_private_set(void *priv, apr_threadkey_t *key)
Definition threadpriv.c:50
apr_status_t apr_threadkey_private_get(void **new, apr_threadkey_t *key)
Definition threadpriv.c:38
apr_status_t apr_threadkey_data_get(void **data, const char *key, apr_threadkey_t *threadkey)
Definition threadpriv.c:70
void(* destructor)(void *)
volatile thread_id td
typedef int(WSAAPI *apr_winapi_fpt_WSAPoll)(IN OUT LPWSAPOLLFD fdArray