diff options
author | Alan Korr <alkorr@rockbox.org> | 2002-04-17 12:20:41 +0000 |
---|---|---|
committer | Alan Korr <alkorr@rockbox.org> | 2002-04-17 12:20:41 +0000 |
commit | 0256fdf30b44395d9695a5306d8b1d5485e602db (patch) | |
tree | fd781f358bc35bf90931d88349b43474607a7031 /firmware/test/memory/memory-block.h | |
parent | 08dada2df506405d7fa7dc57a19d4a283f51162d (diff) | |
download | rockbox-0256fdf30b44395d9695a5306d8b1d5485e602db.tar.gz rockbox-0256fdf30b44395d9695a5306d8b1d5485e602db.zip |
cosmetic changes and additions :
* now we have seperate private headers files
containing private and static or public functions
in memory-* files.
* there is only one .c file of the same name the library.
Zagor: because now there is only one .c file, you could only have a .o file and use it instead of the .a libfile.
* most structures and codes are now private.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@113 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/test/memory/memory-block.h')
-rw-r--r-- | firmware/test/memory/memory-block.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/firmware/test/memory/memory-block.h b/firmware/test/memory/memory-block.h new file mode 100644 index 0000000000..2c29d255e2 --- /dev/null +++ b/firmware/test/memory/memory-block.h | |||
@@ -0,0 +1,77 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef __LIBRARY_MEMORY_C__ | ||
20 | # error "This header file must be included ONLY from memory.c." | ||
21 | #endif | ||
22 | #ifndef __LIBRARY_MEMORY_BLOCK_H__ | ||
23 | # define __LIBRARY_MEMORY_BLOCK_H__ | ||
24 | |||
25 | static struct memory_cache *free_block_cache[MEMORY_PAGE_MINIMAL_ORDER - 2]; | ||
26 | |||
27 | /////////////////////////////////////////////////////////////////////////////// | ||
28 | // MEMORY BLOCK : | ||
29 | ///////////////// | ||
30 | // | ||
31 | // - memory_allocate_block : allocate a power-of-2-sized block (or a page) | ||
32 | // - memory_release_block : release a power-of-2-sized block (or a page) | ||
33 | // | ||
34 | |||
35 | static inline void *allocate_small_block (int order) | ||
36 | { | ||
37 | struct memory_cache *cache = free_block_cache[order - 2]; | ||
38 | do | ||
39 | { | ||
40 | if (cache) | ||
41 | return memory_cache_allocate (cache); | ||
42 | } | ||
43 | while ((free_block_cache[order] = cache = memory_create_cache (size,0,0))); | ||
44 | return MEMORY_RETURN_FAILURE; | ||
45 | } | ||
46 | |||
47 | void *memory_allocate_block (int order) | ||
48 | { | ||
49 | if (order < 2) | ||
50 | order = 2; | ||
51 | if (order < MEMORY_PAGE_MINIMAL_ORDER) | ||
52 | return allocate_small_block (order); | ||
53 | if (order < MEMORY_PAGE_MAXIMAL_ORDER) | ||
54 | return memory_allocate_page (order); | ||
55 | return MEMORY_RETURN_FAILURE; | ||
56 | } | ||
57 | |||
58 | static inline int release_block (int order,void *address) | ||
59 | { | ||
60 | struct memory_cache *cache = free_block_cache[order - 2]; | ||
61 | if (cache) | ||
62 | return memory_cache_release (cache,address); | ||
63 | return MEMORY_RETURN_FAILURE; | ||
64 | } | ||
65 | |||
66 | int memory_release_block (int order,void *address) | ||
67 | { | ||
68 | if (order < 2) | ||
69 | order = 2; | ||
70 | if (order < MEMORY_PAGE_MINIMAL_ORDER) | ||
71 | return release_block (order); | ||
72 | if (order < MEMORY_PAGE_MAXIMAL_ORDER) | ||
73 | return memory_release_page (address); | ||
74 | return MEMORY_RETURN_FAILURE; | ||
75 | } | ||
76 | |||
77 | #endif | ||