src/server/daemon/resourcepool.c

2 months ago

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 30 Jan 2025 18:29:30 +0100 (2 months ago)
changeset 573
76ccfc2a932f
parent 563
6ca97c99173e
child 579
e10457d74fe1
permissions
-rw-r--r--

add resourcepools/common saf shutdown cleanup code

260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
4 * Copyright 2022 Olaf Wintermann. All rights reserved.
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "resourcepool.h"
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include "request.h"
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include "session.h"
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
32 #include "../public/nsapi.h"
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
33 #include "../util/atomic.h"
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
34
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
35 #define RESOURCE_POOL_MAX_DEFAULT 32
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
36
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
37 #define RESOURCE_POOL_MAX_ALLOC 268435455
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
38
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
39 static CxMap *resource_pool_types;
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
40
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
41 int init_resource_pools(void) {
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 463
diff changeset
42 resource_pool_types = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 4);
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
43 return resource_pool_types ? 0 : 1;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
44 }
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
45
573
76ccfc2a932f add resourcepools/common saf shutdown cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
46 void resource_pool_cleanup(void) {
76ccfc2a932f add resourcepools/common saf shutdown cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
47 cxMapDestroy(resource_pool_types);
76ccfc2a932f add resourcepools/common saf shutdown cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
48 }
76ccfc2a932f add resourcepools/common saf shutdown cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
49
270
4cfaa02055cd add first code for postgresql plugin: resourcepool type implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
50 int resourcepool_register_type(const char *type_name, ResourceType *type_info) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
51 if(cxMapPut(resource_pool_types, cx_hash_key_str(type_name), type_info)) {
270
4cfaa02055cd add first code for postgresql plugin: resourcepool type implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
52 log_ereport(LOG_CATASTROPHE, "resourcepool_register_type: OOM");
4cfaa02055cd add first code for postgresql plugin: resourcepool type implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
53 return 1;
4cfaa02055cd add first code for postgresql plugin: resourcepool type implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
54 }
4cfaa02055cd add first code for postgresql plugin: resourcepool type implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
55 return 0;
4cfaa02055cd add first code for postgresql plugin: resourcepool type implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
56 }
4cfaa02055cd add first code for postgresql plugin: resourcepool type implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
57
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
58
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
59
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
60 int resourcepool_new(ServerConfiguration *cfg, cxstring type, cxstring name, ConfigNode *node) {
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
61 ResourceType *restype = cxMapGet(resource_pool_types, cx_hash_key_bytes((unsigned const char*)type.ptr, type.length));
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
62 if(!restype) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
63 log_ereport(LOG_MISCONFIG, "unknown resource pool type: %s", type.ptr);
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
64 return 1;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
65 }
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
66
460
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
67 char *respool_name = cx_strdup_a(cfg->a, name).ptr;
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
68 if(!respool_name) {
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
69 log_ereport(LOG_FAILURE, "resourcepool_new: OOM");
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
70 return 1;
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
71 }
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
72
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
73 // convert ConfigNode to pblock
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
74 // no sub-objects allowed for this specific ConfigNode, therefore
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
75 // it can be represented as key-value-pairs
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
76 pblock *param = config_obj2pblock(cfg->pool, node);
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
77 if(!param) {
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
78 log_ereport(LOG_FAILURE, "resourcepool_new: OOM");
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
79 return 1;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
80 }
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
81
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
82 ResourcePool *respool = pool_malloc(cfg->pool, sizeof(ResourcePool));
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
83 if(!respool) {
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
84 log_ereport(LOG_FAILURE, "resourcepool_new: OOM");
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
85 return 1;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
86 }
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
87 respool->pool = cfg->pool;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
88
270
4cfaa02055cd add first code for postgresql plugin: resourcepool type implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
89 void *respool_data = restype->init(cfg->pool, name.ptr, param);
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
90 if(!respool_data) {
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
91 log_ereport(LOG_FAILURE, "Cannot create resource pool data: pool: %s type: %s", name.ptr, type.ptr);
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
92 return 1;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
93 }
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
94
460
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
95 respool->name = respool_name;
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
96 respool->type = restype;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
97 respool->data = respool_data;
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
98 respool->min = 4; // TODO: get from node
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
99 respool->max = RESOURCE_POOL_MAX_DEFAULT; // TODO: get from node
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
100
343
78ce9733a54f fix resource pool memory management
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 283
diff changeset
101 respool->numcreated = 0;
78ce9733a54f fix resource pool memory management
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 283
diff changeset
102 respool->numresources = 0;
78ce9733a54f fix resource pool memory management
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 283
diff changeset
103
78ce9733a54f fix resource pool memory management
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 283
diff changeset
104
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
105 // don't allow too large resource pools
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
106 // this prevents the need to check malloc integer overflows
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
107 if(respool->max > RESOURCE_POOL_MAX_ALLOC) {
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
108 respool->max = RESOURCE_POOL_MAX_ALLOC;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
109 log_ereport(LOG_WARN, "Resource pool %s: limit max to %d", name.ptr, respool->max);
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
110 }
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
111
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
112 respool->resalloc = respool->max;
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
113 respool->resources = pool_malloc(cfg->pool, respool->resalloc * sizeof(ResourceDataPrivate*));
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
114
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
115 if(!respool->resources || cxMapPut(cfg->resources, cx_hash_key_bytes((unsigned const char*)name.ptr, name.length), respool)) {
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
116 log_ereport(LOG_FAILURE, "Cannot add resource pool: OOM");
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
117 // the only cleanup we have to do
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
118 restype->destroy(respool_data);
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
119 return 1;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
120 }
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
121
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
122 pthread_mutex_init(&respool->lock, NULL);
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
123 pthread_cond_init(&respool->available, NULL);
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
124
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
125 return 0;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
126 }
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
127
371
ea836c4f7341 add global resource lookup function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
128 static ResourceData* s_resourcepool_lookup(ServerConfiguration *cfg, Request *opt_rq, Session *opt_sn, const char *name, int flags) {
ea836c4f7341 add global resource lookup function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
129 NSAPIRequest *request = (NSAPIRequest*)opt_rq;
ea836c4f7341 add global resource lookup function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
130 NSAPISession *session = (NSAPISession*)opt_sn;
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
131 ResourceDataPrivate *resource = NULL;
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 // was this resource already used by this request?
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 343
diff changeset
134 if(request && request->resources) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
135 resource = cxMapGet(request->resources, cx_hash_key_str(name));
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
136 if(resource) {
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
137 return &resource->data;
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 }
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 }
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
141 ResourcePool *respool = cxMapGet(cfg->resources, cx_hash_key_str(name));
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
142 if(!respool) return NULL;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
143
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
144
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
145 pthread_mutex_lock(&respool->lock);
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
146 WSBool createResource = FALSE;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
147 if(respool->numcreated < respool->min) {
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
148 createResource = TRUE;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
149 }
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
151 if(createResource) {
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
152 // create a new resource and store it in the resourcepool
463
4fd523fff13b add option to automatically bind new ldap sessions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 460
diff changeset
153 log_ereport(LOG_DEBUG, "resourcepool %s: create resource", name);
4fd523fff13b add option to automatically bind new ldap sessions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 460
diff changeset
154
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
155 void *resourceData = respool->type->createresource(respool->data);
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
156 if(resourceData) {
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
157 respool->numcreated++;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
158
343
78ce9733a54f fix resource pool memory management
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 283
diff changeset
159 resource = pool_malloc(respool->pool, sizeof(ResourceDataPrivate));
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
160 if(resource) {
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
161 resource->data.data = respool->type->getresourcedata(resourceData);
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
162 resource->data.resourcepool = respool;
283
25e5b771677d minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 272
diff changeset
163 resource->resdata = resourceData;
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
164 } else {
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
165 respool->type->freeresource(respool->data, resourceData);
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
166 log_ereport(LOG_CATASTROPHE, "resourcepool_lookup: OOM");
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
167 }
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
168 }
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
169 // else: respool->type->createresource does logging in case of errors
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
170 } else if(respool->numresources > 0) {
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
171 resource = respool->resources[--respool->numresources];
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
172 } else {
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
173 // wait for free resource
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
174 pthread_cond_wait(&respool->available, &respool->lock);
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
175 if(respool->numresources > 0) {
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
176 resource = respool->resources[--respool->numresources];
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
177 }
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 }
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
179
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
180 // save the resource in the request object, for caching and also
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
181 // for cleanup later
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
182 int err = 0;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
183 if(resource) {
371
ea836c4f7341 add global resource lookup function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
184 if(request && session) {
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 343
diff changeset
185 if(!request->resources) {
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 463
diff changeset
186 request->resources = cxHashMapCreate(pool_allocator(session->sn.pool), CX_STORE_POINTERS, 8);
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 343
diff changeset
187 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 343
diff changeset
188
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 343
diff changeset
189 if(request->resources) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 371
diff changeset
190 if(cxMapPut(request->resources, cx_hash_key_str(name), resource)) {
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 343
diff changeset
191 err = 1;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 343
diff changeset
192 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 343
diff changeset
193 } else {
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
194 err = 1;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
195 }
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 343
diff changeset
196 } // else: lookup is outside of any request context
283
25e5b771677d minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 272
diff changeset
197
25e5b771677d minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 272
diff changeset
198 if(respool->type->prepare(respool->data, resource->resdata)) {
25e5b771677d minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 272
diff changeset
199 err = -1;
25e5b771677d minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 272
diff changeset
200 }
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
201 }
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
202
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
203 if(err) {
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
204 // err == 1 caused by OOM
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
205 log_ereport(LOG_FAILURE, "resourcepool_lookup: OOM");
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
206 // cleanup
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
207 resourcepool_destroy_resource(resource);
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
208 resource = NULL;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
209 }
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
210
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
211 pthread_mutex_unlock(&respool->lock);
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
212
283
25e5b771677d minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 272
diff changeset
213 return (ResourceData*)resource;
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 }
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215
371
ea836c4f7341 add global resource lookup function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
216 ResourceData* resourcepool_cfg_lookup(ServerConfiguration *cfg, const char *name, int flags) {
ea836c4f7341 add global resource lookup function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
217 return s_resourcepool_lookup(cfg, NULL, NULL, name, flags);
ea836c4f7341 add global resource lookup function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
218 }
ea836c4f7341 add global resource lookup function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
219
ea836c4f7341 add global resource lookup function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
220 ResourceData* resourcepool_lookup(Session *sn, Request *rq, const char *name, int flags) {
ea836c4f7341 add global resource lookup function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
221 NSAPISession *session = (NSAPISession*)sn;
ea836c4f7341 add global resource lookup function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
222 ServerConfiguration *cfg = session->config;
ea836c4f7341 add global resource lookup function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
223 return s_resourcepool_lookup(cfg, rq, sn, name, flags);
ea836c4f7341 add global resource lookup function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
224 }
ea836c4f7341 add global resource lookup function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
225
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
226 void resourcepool_free(Session *sn, Request *rq, ResourceData *resource) {
460
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
227 NSAPIRequest *nsapi_rq = (NSAPIRequest *)rq;
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
228 ResourceDataPrivate *res = (ResourceDataPrivate*)resource;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
229 ResourcePool *respool = resource->resourcepool;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
230
460
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
231 if(nsapi_rq && !nsapi_rq->finished) {
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
232 // request processing still ongoing and SAFs will be executed
563
6ca97c99173e add TODO to use a future ucx feature
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
233 // TODO: future ucx cxMapRemove returns, if it actually removed something, therefore use just cxMapRemove
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 463
diff changeset
234 if(!cxMapRemoveAndGet(nsapi_rq->resources, cx_hash_key_str(respool->name))) {
460
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
235 log_ereport(LOG_FAILURE, "resourcepool_free: cannot remove resource from request: potential double free");
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
236 }
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
237 }
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
238 // else: safe to ignore nsapi_rq->resources
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
239
283
25e5b771677d minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 272
diff changeset
240 if(respool->type->finish(respool->data, res->resdata)) {
25e5b771677d minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 272
diff changeset
241 log_ereport(LOG_FAILURE, "resourcepool_free: finish failed");
25e5b771677d minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 272
diff changeset
242 }
25e5b771677d minimal working send_file with postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 272
diff changeset
243
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
244 pthread_mutex_lock(&respool->lock);
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
246 if(respool->numresources >= respool->resalloc) {
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
247 // actually respool->resalloc == respool->max
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
248 // and numresources should always be smaller
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
249 // however just be extra safe here
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
250 respool->resalloc += 8;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
251 ResourceDataPrivate **new_res_array = pool_realloc(
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
252 respool->pool,
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
253 respool->resources,
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
254 respool->resalloc * sizeof(ResourceDataPrivate*));
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
255 if(new_res_array) {
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
256 respool->resources = new_res_array;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
257 } else {
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
258 log_ereport(LOG_FAILURE, "resourcepool_free: OOM");
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
259 resourcepool_destroy_resource(res);
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
260 pthread_mutex_unlock(&respool->lock);
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
261 return;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
262 }
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
263 }
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
264
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
265 respool->resources[respool->numresources++] = res;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
266
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
267 pthread_cond_signal(&respool->available);
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
268 pthread_mutex_unlock(&respool->lock);
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
269 }
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
270
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
271 void resourcepool_destroy_resource(ResourceDataPrivate *res) {
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
272 res->data.resourcepool->numcreated--;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
273 res->data.resourcepool->type->freeresource(res->data.resourcepool->data, res->resdata);
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 271
diff changeset
274 pool_free(res->data.resourcepool->pool, res);
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 }
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
276
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
277 void resourcepool_destroy(ResourcePool *respool) {
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
278 // TODO
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
279 }

mercurial