Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
object_pool.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2019 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
10#ifndef __UTILS_OBJECT_POOL_H__
11#define __UTILS_OBJECT_POOL_H__
12
13#include "utils/types.h"
14
15#include "zix/sem.h"
16
21typedef void * (*ObjectCreatorFunc) (void);
22
23typedef struct ObjectPool
24{
25 int max_objects;
26
29 int num_obj_available;
30
33
35 ZixSem access_sem;
37
43 ObjectCreatorFunc create_func,
44 ObjectFreeFunc free_func,
45 int max_objects);
46
50void *
52
60int
62
66void
67object_pool_return (ObjectPool * self, void * object);
68
72void
74
75#endif
void(* ObjectFreeFunc)(void *)
Function to call to free objects.
Definition types.h:122
void * object_pool_get(ObjectPool *self)
Returns an available object.
void object_pool_free(ObjectPool *self)
Frees the pool and all its objects.
int object_pool_get_num_available(ObjectPool *self)
Returns the number of available objects.
ObjectPool * object_pool_new(ObjectCreatorFunc create_func, ObjectFreeFunc free_func, int max_objects)
Creates a new object pool.
void *(* ObjectCreatorFunc)(void)
Function to call to create the objects in the pool.
Definition object_pool.h:21
void object_pool_return(ObjectPool *self, void *object)
Puts an object back in the pool.
void ** obj_available
Available objects.
Definition object_pool.h:28
ZixSem access_sem
Semaphore for atomic operations.
Definition object_pool.h:35
ObjectFreeFunc free_func
Object free func.
Definition object_pool.h:32
Custom types.