src/server/daemon/resourcepool.h

branch
webdav
changeset 269
3dfbd0b91950
parent 260
4779a6fb4fbe
child 272
f210681d9dd0
--- a/src/server/daemon/resourcepool.h	Thu Jan 20 16:04:58 2022 +0100
+++ b/src/server/daemon/resourcepool.h	Sat Jan 22 11:06:11 2022 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2020 Olaf Wintermann. All rights reserved.
+ * Copyright 2021 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -31,6 +31,10 @@
 
 #include "../public/nsapi.h"
 
+#include "config.h"
+
+#include <pthread.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -45,14 +49,62 @@
 };
 
 struct ResourcePool {
+    /*
+     * Memory pool
+     */
+    pool_handle_t *pool;
+    
+    /*
+     * Type information of this resource pool
+     * The type object is stored in the registered types map and should not
+     * be freed, when the resource pool is destroyed
+     */
     ResourceType *type;
     
+    /*
+     * Data returned by the ResourceType init function
+     * When the pool is destroyed, the data should be passed to
+     * ResourceType.destroy
+     */
+    void *data;
     
+    pthread_mutex_t lock;
+    pthread_cond_t available;
+    
+    /*
+     * Array of available resources
+     * each entry is created with ResourceType.createresource
+     */
+    void **resources;
     
+    /*
+     * Allocated size of the resources array
+     */
+    size_t resalloc;
+    
+    /*
+     * Number of currently available resources in the array
+     */
+    size_t numresources;
+    
+    /*
+     * resource pool min parameter
+     */
     int min;
+    
+    /*
+     * resource pool max parameter
+     */
     int max;
 };
 
+int init_resource_pools(void);
+
+int resourcepool_new(ServerConfiguration *cfg, scstr_t type, scstr_t name, ConfigNode *node);
+
+int resourcepool_create_resources(ResourcePool *pool, int num_res);
+
+void resourcepool_destroy(ResourcePool *respool);
 
 #ifdef __cplusplus
 }

mercurial