xref: /nrf52832-nimble/rt-thread/components/dfs/filesystems/uffs/src/inc/uffs/uffs_pool.h (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2   This file is part of UFFS, the Ultra-low-cost Flash File System.
3 
4   Copyright (C) 2005-2009 Ricky Zheng <[email protected]>
5 
6   UFFS is free software; you can redistribute it and/or modify it under
7   the GNU Library General Public License as published by the Free Software
8   Foundation; either version 2 of the License, or (at your option) any
9   later version.
10 
11   UFFS is distributed in the hope that it will be useful, but WITHOUT
12   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   or GNU Library General Public License, as applicable, for more details.
15 
16   You should have received a copy of the GNU General Public License
17   and GNU Library General Public License along with UFFS; if not, write
18   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19   Boston, MA  02110-1301, USA.
20 
21   As a special exception, if other files instantiate templates or use
22   macros or inline functions from this file, or you compile this file
23   and link it with other works to produce a work based on this file,
24   this file does not by itself cause the resulting work to be covered
25   by the GNU General Public License. However the source code for this
26   file must still be made available in accordance with section (3) of
27   the GNU General Public License v2.
28 
29   This exception does not invalidate any other reasons why a work based
30   on this file might be covered by the GNU General Public License.
31 */
32 
33 /**
34  * \file uffs_pool.h
35  * \brief Fast fixed size memory pool management.
36  * \author Ricky Zheng, Simon Kallweit
37  */
38 
39 #ifndef _UFFS_POOL_H_
40 #define _UFFS_POOL_H_
41 
42 
43 #include "uffs/uffs_types.h"
44 #include "uffs/uffs_os.h"
45 
46 #ifdef __cplusplus
47 extern "C"{
48 #endif
49 
50 /**
51  * \struct uffs_PoolEntrySt
52  * \brief Helper type for free buffer entries.
53  */
54 typedef struct uffs_PoolEntrySt {
55     struct uffs_PoolEntrySt *next;
56 } uffs_PoolEntry;
57 
58 /**
59  * \struct uffs_PoolSt
60  * \brief Memory pool.
61  */
62 typedef struct uffs_PoolSt {
63 	u8 *mem;					//!< memory pool
64 	u32 buf_size;				//!< size of a buffer
65 	u32 num_bufs;				//!< number of buffers in the pool
66 	uffs_PoolEntry *free_list;	//!< linked list of free buffers
67 	OSSEM sem;					//!< buffer lock
68 } uffs_Pool;
69 
70 URET uffs_PoolInit(uffs_Pool *pool, void *mem, u32 mem_size, u32 buf_size, u32 num_bufs);
71 URET uffs_PoolRelease(uffs_Pool *pool);
72 
73 UBOOL uffs_PoolVerify(uffs_Pool *pool, void *p);
74 
75 void *uffs_PoolGet(uffs_Pool *pool);
76 void *uffs_PoolGetLocked(uffs_Pool *pool);
77 
78 int uffs_PoolPut(uffs_Pool *pool, void *p);
79 int uffs_PoolPutLocked(uffs_Pool *pool, void *p);
80 
81 void *uffs_PoolGetBufByIndex(uffs_Pool *pool, u32 index);
82 u32 uffs_PoolGetIndex(uffs_Pool *pool, void *p);
83 UBOOL uffs_PoolCheckFreeList(uffs_Pool *pool, void *p);
84 
85 void * uffs_PoolFindNextAllocated(uffs_Pool *pool, void *from);
86 
87 int uffs_PoolGetFreeCount(uffs_Pool *pool);
88 int uffs_PoolPutAll(uffs_Pool *pool);
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif // _UFFS_POOL_H_
95