1 /* |
1 /* |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 * |
3 * |
4 * Copyright 2020 Olaf Wintermann. All rights reserved. |
4 * Copyright 2021 Olaf Wintermann. All rights reserved. |
5 * |
5 * |
6 * Redistribution and use in source and binary forms, with or without |
6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are met: |
7 * modification, are permitted provided that the following conditions are met: |
8 * |
8 * |
9 * 1. Redistributions of source code must retain the above copyright |
9 * 1. Redistributions of source code must retain the above copyright |
43 Request *rq; |
47 Request *rq; |
44 ResourceType *type; |
48 ResourceType *type; |
45 }; |
49 }; |
46 |
50 |
47 struct ResourcePool { |
51 struct ResourcePool { |
|
52 /* |
|
53 * Memory pool |
|
54 */ |
|
55 pool_handle_t *pool; |
|
56 |
|
57 /* |
|
58 * Type information of this resource pool |
|
59 * The type object is stored in the registered types map and should not |
|
60 * be freed, when the resource pool is destroyed |
|
61 */ |
48 ResourceType *type; |
62 ResourceType *type; |
49 |
63 |
|
64 /* |
|
65 * Data returned by the ResourceType init function |
|
66 * When the pool is destroyed, the data should be passed to |
|
67 * ResourceType.destroy |
|
68 */ |
|
69 void *data; |
50 |
70 |
|
71 pthread_mutex_t lock; |
|
72 pthread_cond_t available; |
51 |
73 |
|
74 /* |
|
75 * Array of available resources |
|
76 * each entry is created with ResourceType.createresource |
|
77 */ |
|
78 void **resources; |
|
79 |
|
80 /* |
|
81 * Allocated size of the resources array |
|
82 */ |
|
83 size_t resalloc; |
|
84 |
|
85 /* |
|
86 * Number of currently available resources in the array |
|
87 */ |
|
88 size_t numresources; |
|
89 |
|
90 /* |
|
91 * resource pool min parameter |
|
92 */ |
52 int min; |
93 int min; |
|
94 |
|
95 /* |
|
96 * resource pool max parameter |
|
97 */ |
53 int max; |
98 int max; |
54 }; |
99 }; |
55 |
100 |
|
101 int init_resource_pools(void); |
|
102 |
|
103 int resourcepool_new(ServerConfiguration *cfg, scstr_t type, scstr_t name, ConfigNode *node); |
|
104 |
|
105 int resourcepool_create_resources(ResourcePool *pool, int num_res); |
|
106 |
|
107 void resourcepool_destroy(ResourcePool *respool); |
56 |
108 |
57 #ifdef __cplusplus |
109 #ifdef __cplusplus |
58 } |
110 } |
59 #endif |
111 #endif |
60 |
112 |