src/server/daemon/resourcepool.h

Wed, 27 Nov 2024 23:00:07 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 27 Nov 2024 23:00:07 +0100
changeset 563
6ca97c99173e
parent 460
b9a447b02046
permissions
-rw-r--r--

add TODO to use a future ucx feature

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 2021 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 #ifndef WS_RESOURCEPOOL_H
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #define WS_RESOURCEPOOL_H
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "../public/nsapi.h"
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
34 #include "config.h"
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
35
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
36 #include <pthread.h>
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
37
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #ifdef __cplusplus
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 extern "C" {
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #endif
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 typedef struct ResourceDataPrivate ResourceDataPrivate;
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 struct ResourceDataPrivate {
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 ResourceData data;
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
46
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
47 /*
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
48 * the void* pointer returned by respool->type->createresource
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
49 *
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
50 * ResourceData.data contains the pointer returned by
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
51 * respool->type->getresourcedata(resdata))
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
52 */
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
53 void *resdata;
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 };
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 struct ResourcePool {
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
57 /*
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
58 * Memory pool
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
59 */
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
60 pool_handle_t *pool;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
61
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
62 /*
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
63 * Type information of this resource pool
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
64 * The type object is stored in the registered types map and should not
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
65 * be freed, when the resource pool is destroyed
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
66 */
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 ResourceType *type;
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
69 /*
460
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
70 * The name of the resource pool
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 char *name;
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
73
b9a447b02046 resourcepool_free should remove the resource from the request resource cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
74 /*
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
75 * Data returned by the ResourceType init function
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
76 * When the pool is destroyed, the data should be passed to
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
77 * ResourceType.destroy
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
78 */
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
79 void *data;
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
81 pthread_mutex_t lock;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
82 pthread_cond_t available;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
83
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
84 /*
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
85 * Array of available resources
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
86 * each entry is created with ResourceType.createresource
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
87 */
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
88 ResourceDataPrivate **resources;
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
90 /*
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
91 * Allocated size of the resources array
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
92 */
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
93 size_t resalloc;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
94
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
95 /*
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
96 * Number of currently available resources in the array
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
97 */
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
98 size_t numresources;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
99
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
100
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
101 /*
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
102 * Number of created resources (in use + available)
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
103 */
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
104 size_t numcreated;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
105
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
106 /*
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
107 * resource pool min parameter
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
108 */
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 int min;
269
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 * resource pool max parameter
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
113 */
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 int max;
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 };
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
117 int init_resource_pools(void);
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
118
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 272
diff changeset
119 int resourcepool_new(ServerConfiguration *cfg, cxstring type, cxstring name, ConfigNode *node);
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
120
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
121 void resourcepool_destroy_resource(ResourceDataPrivate *res);
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
122
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
123 void resourcepool_destroy(ResourcePool *respool);
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 #ifdef __cplusplus
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 }
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 #endif
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 #endif /* WS_RESOURCEPOOL_H */
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130

mercurial