src/server/daemon/resourcepool.c

changeset 415
d938228c382e
parent 371
ea836c4f7341
child 460
b9a447b02046
equal deleted inserted replaced
414:99a34860c105 415:d938228c382e
34 34
35 #define RESOURCE_POOL_MAX_DEFAULT 32 35 #define RESOURCE_POOL_MAX_DEFAULT 32
36 36
37 #define RESOURCE_POOL_MAX_ALLOC 268435455 37 #define RESOURCE_POOL_MAX_ALLOC 268435455
38 38
39 static UcxMap *resource_pool_types; 39 static CxMap *resource_pool_types;
40 40
41 int init_resource_pools(void) { 41 int init_resource_pools(void) {
42 resource_pool_types = ucx_map_new(4); 42 resource_pool_types = cxHashMapCreate(cxDefaultAllocator, 4);
43 return resource_pool_types ? 0 : 1; 43 return resource_pool_types ? 0 : 1;
44 } 44 }
45 45
46 int resourcepool_register_type(const char *type_name, ResourceType *type_info) { 46 int resourcepool_register_type(const char *type_name, ResourceType *type_info) {
47 if(ucx_map_cstr_put(resource_pool_types, type_name, type_info)) { 47 if(cxMapPut(resource_pool_types, cx_hash_key_str(type_name), type_info)) {
48 log_ereport(LOG_CATASTROPHE, "resourcepool_register_type: OOM"); 48 log_ereport(LOG_CATASTROPHE, "resourcepool_register_type: OOM");
49 return 1; 49 return 1;
50 } 50 }
51 return 0; 51 return 0;
52 } 52 }
53 53
54 54
55 55
56 int resourcepool_new(ServerConfiguration *cfg, scstr_t type, scstr_t name, ConfigNode *node) { 56 int resourcepool_new(ServerConfiguration *cfg, cxstring type, cxstring name, ConfigNode *node) {
57 ResourceType *restype = ucx_map_sstr_get(resource_pool_types, type); 57 ResourceType *restype = cxMapGet(resource_pool_types, cx_hash_key_bytes((unsigned const char*)type.ptr, type.length));
58 if(!restype) { 58 if(!restype) {
59 log_ereport(LOG_MISCONFIG, "Unknown resource pool type: %s", type.ptr); 59 log_ereport(LOG_MISCONFIG, "unknown resource pool type: %s", type.ptr);
60 return 1; 60 return 1;
61 } 61 }
62 62
63 // convert ConfigNode to pblock 63 // convert ConfigNode to pblock
64 // no sub-objects allowed for this specific ConfigNode, therefore 64 // no sub-objects allowed for this specific ConfigNode, therefore
99 } 99 }
100 100
101 respool->resalloc = respool->max; 101 respool->resalloc = respool->max;
102 respool->resources = pool_malloc(cfg->pool, respool->resalloc * sizeof(ResourceDataPrivate*)); 102 respool->resources = pool_malloc(cfg->pool, respool->resalloc * sizeof(ResourceDataPrivate*));
103 103
104 if(!respool->resources || ucx_map_sstr_put(cfg->resources, name, respool)) { 104 if(!respool->resources || cxMapPut(cfg->resources, cx_hash_key_bytes((unsigned const char*)name.ptr, name.length), respool)) {
105 log_ereport(LOG_FAILURE, "Cannot add resource pool: OOM"); 105 log_ereport(LOG_FAILURE, "Cannot add resource pool: OOM");
106 // the only cleanup we have to do 106 // the only cleanup we have to do
107 restype->destroy(respool_data); 107 restype->destroy(respool_data);
108 return 1; 108 return 1;
109 } 109 }
119 NSAPISession *session = (NSAPISession*)opt_sn; 119 NSAPISession *session = (NSAPISession*)opt_sn;
120 ResourceDataPrivate *resource = NULL; 120 ResourceDataPrivate *resource = NULL;
121 121
122 // was this resource already used by this request? 122 // was this resource already used by this request?
123 if(request && request->resources) { 123 if(request && request->resources) {
124 resource = ucx_map_cstr_get(request->resources, name); 124 resource = cxMapGet(request->resources, cx_hash_key_str(name));
125 if(resource) { 125 if(resource) {
126 return &resource->data; 126 return &resource->data;
127 } 127 }
128 } 128 }
129 129
130 ResourcePool *respool = ucx_map_cstr_get(cfg->resources, name); 130 ResourcePool *respool = cxMapGet(cfg->resources, cx_hash_key_str(name));
131 if(!respool) return NULL; 131 if(!respool) return NULL;
132 132
133 133
134 pthread_mutex_lock(&respool->lock); 134 pthread_mutex_lock(&respool->lock);
135 WSBool createResource = FALSE; 135 WSBool createResource = FALSE;
168 // for cleanup later 168 // for cleanup later
169 int err = 0; 169 int err = 0;
170 if(resource) { 170 if(resource) {
171 if(request && session) { 171 if(request && session) {
172 if(!request->resources) { 172 if(!request->resources) {
173 request->resources = ucx_map_new_a(&session->allocator, 8); 173 request->resources = cxHashMapCreate(pool_allocator(session->sn.pool), 8);
174 } 174 }
175 175
176 if(request->resources) { 176 if(request->resources) {
177 if(ucx_map_cstr_put(request->resources, name, resource)) { 177 if(cxMapPut(request->resources, cx_hash_key_str(name), resource)) {
178 err = 1; 178 err = 1;
179 } 179 }
180 } else { 180 } else {
181 err = 1; 181 err = 1;
182 } 182 }

mercurial