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 } |
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 |