src/server/daemon/resourcepool.c

branch
webdav
changeset 283
25e5b771677d
parent 272
f210681d9dd0
child 343
78ce9733a54f
equal deleted inserted replaced
282:cfb588e27198 283:25e5b771677d
143 143
144 resource = pool_malloc(sn->pool, sizeof(ResourceDataPrivate)); 144 resource = pool_malloc(sn->pool, sizeof(ResourceDataPrivate));
145 if(resource) { 145 if(resource) {
146 resource->data.data = respool->type->getresourcedata(resourceData); 146 resource->data.data = respool->type->getresourcedata(resourceData);
147 resource->data.resourcepool = respool; 147 resource->data.resourcepool = respool;
148 resource->resdata = resourceData;
148 } else { 149 } else {
149 respool->type->freeresource(respool->data, resourceData); 150 respool->type->freeresource(respool->data, resourceData);
150 log_ereport(LOG_CATASTROPHE, "resourcepool_lookup: OOM"); 151 log_ereport(LOG_CATASTROPHE, "resourcepool_lookup: OOM");
151 } 152 }
152 } 153 }
174 err = 1; 175 err = 1;
175 } 176 }
176 } else { 177 } else {
177 err = 1; 178 err = 1;
178 } 179 }
180
181 if(respool->type->prepare(respool->data, resource->resdata)) {
182 err = -1;
183 }
179 } 184 }
180 185
181 if(err) { 186 if(err) {
182 // err == 1 caused by OOM 187 // err == 1 caused by OOM
183 log_ereport(LOG_FAILURE, "resourcepool_lookup: OOM"); 188 log_ereport(LOG_FAILURE, "resourcepool_lookup: OOM");
186 resource = NULL; 191 resource = NULL;
187 } 192 }
188 193
189 pthread_mutex_unlock(&respool->lock); 194 pthread_mutex_unlock(&respool->lock);
190 195
191 196 return (ResourceData*)resource;
192 return &resource->data;
193 } 197 }
194 198
195 void resourcepool_free(Session *sn, Request *rq, ResourceData *resource) { 199 void resourcepool_free(Session *sn, Request *rq, ResourceData *resource) {
196 ResourceDataPrivate *res = (ResourceDataPrivate*)resource; 200 ResourceDataPrivate *res = (ResourceDataPrivate*)resource;
197 ResourcePool *respool = resource->resourcepool; 201 ResourcePool *respool = resource->resourcepool;
202
203 if(respool->type->finish(respool->data, res->resdata)) {
204 log_ereport(LOG_FAILURE, "resourcepool_free: finish failed");
205 }
198 206
199 pthread_mutex_lock(&respool->lock); 207 pthread_mutex_lock(&respool->lock);
200 208
201 if(respool->numresources >= respool->resalloc) { 209 if(respool->numresources >= respool->resalloc) {
202 // actually respool->resalloc == respool->max 210 // actually respool->resalloc == respool->max

mercurial