summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Gjenero <dreamlayers@rockbox.org>2011-11-29 00:42:27 +0000
committerBoris Gjenero <dreamlayers@rockbox.org>2011-11-29 00:42:27 +0000
commitd51e5983357593981e604b05ad3826f2496f4a6b (patch)
tree036fa986dcf4f6ec4c529dd74c5f996533f62d4f
parent297c29cba60e34ed01fb72974dcb562e58df322b (diff)
downloadrockbox-d51e5983357593981e604b05ad3826f2496f4a6b.tar.gz
rockbox-d51e5983357593981e604b05ad3826f2496f4a6b.zip
FS#12412 : Delete old buffer allocation code which has been replaced by core_alloc, and move buffer setup code to core_alloc.c
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31088 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/gui/skin_engine/skin_engine.c1
-rw-r--r--apps/menus/main_menu.c1
-rw-r--r--apps/mp3data.c1
-rw-r--r--apps/plugin.c1
-rw-r--r--apps/recorder/pcm_record.c1
-rw-r--r--firmware/SOURCES1
-rw-r--r--firmware/buffer.c202
-rw-r--r--firmware/buflib.c1
-rw-r--r--firmware/core_alloc.c35
-rw-r--r--firmware/include/buffer.h38
-rw-r--r--firmware/thread.c11
-rw-r--r--flash/bootbox/main.c2
12 files changed, 29 insertions, 266 deletions
diff --git a/apps/gui/skin_engine/skin_engine.c b/apps/gui/skin_engine/skin_engine.c
index 30ec0e75b8..74abd92fdf 100644
--- a/apps/gui/skin_engine/skin_engine.c
+++ b/apps/gui/skin_engine/skin_engine.c
@@ -30,7 +30,6 @@
30#include "settings.h" 30#include "settings.h"
31#include "wps.h" 31#include "wps.h"
32#include "file.h" 32#include "file.h"
33#include "buffer.h"
34#if CONFIG_TUNER 33#if CONFIG_TUNER
35#include "radio.h" 34#include "radio.h"
36#endif 35#endif
diff --git a/apps/menus/main_menu.c b/apps/menus/main_menu.c
index bb8ea276fb..b6ce9e75c6 100644
--- a/apps/menus/main_menu.c
+++ b/apps/menus/main_menu.c
@@ -42,7 +42,6 @@
42#include "screens.h" 42#include "screens.h"
43#include "plugin.h" 43#include "plugin.h"
44#include "talk.h" 44#include "talk.h"
45#include "buffer.h"
46#include "splash.h" 45#include "splash.h"
47#include "debug_menu.h" 46#include "debug_menu.h"
48#include "version.h" 47#include "version.h"
diff --git a/apps/mp3data.c b/apps/mp3data.c
index 53f13f4f64..79baec3df2 100644
--- a/apps/mp3data.c
+++ b/apps/mp3data.c
@@ -38,7 +38,6 @@
38#include "logf.h" 38#include "logf.h"
39#include "mp3data.h" 39#include "mp3data.h"
40#include "file.h" 40#include "file.h"
41#include "buffer.h"
42#include "system.h" 41#include "system.h"
43 42
44//#define DEBUG_VERBOSE 43//#define DEBUG_VERBOSE
diff --git a/apps/plugin.c b/apps/plugin.c
index b9c2e7cb5b..3cc9e6c413 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -27,7 +27,6 @@
27#include "lang.h" 27#include "lang.h"
28#include "led.h" 28#include "led.h"
29#include "keyboard.h" 29#include "keyboard.h"
30#include "buffer.h"
31#include "backlight.h" 30#include "backlight.h"
32#include "sound_menu.h" 31#include "sound_menu.h"
33#include "mp3data.h" 32#include "mp3data.h"
diff --git a/apps/recorder/pcm_record.c b/apps/recorder/pcm_record.c
index 3b069b6dc8..e83db0f418 100644
--- a/apps/recorder/pcm_record.c
+++ b/apps/recorder/pcm_record.c
@@ -29,7 +29,6 @@
29#include "string-extra.h" 29#include "string-extra.h"
30#include "storage.h" 30#include "storage.h"
31#include "usb.h" 31#include "usb.h"
32#include "buffer.h"
33#include "general.h" 32#include "general.h"
34#include "codec_thread.h" 33#include "codec_thread.h"
35#include "audio.h" 34#include "audio.h"
diff --git a/firmware/SOURCES b/firmware/SOURCES
index b918a19418..f5ee7873a2 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -1,7 +1,6 @@
1ata_idle_notify.c 1ata_idle_notify.c
2events.c 2events.c
3backlight.c 3backlight.c
4buffer.c
5buflib.c 4buflib.c
6core_alloc.c 5core_alloc.c
7general.c 6general.c
diff --git a/firmware/buffer.c b/firmware/buffer.c
deleted file mode 100644
index e0496fe149..0000000000
--- a/firmware/buffer.c
+++ /dev/null
@@ -1,202 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include <stdio.h>
22#include <stdint.h>
23#include "system.h"
24#include "buffer.h"
25#include "panic.h"
26#include "logf.h"
27
28#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
29#else
30#endif
31
32/* defined in linker script */
33#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
34#if defined(IPOD_VIDEO) && !defined(BOOTLOADER)
35extern unsigned char *audiobufend_lds[];
36unsigned char *audiobufend;
37#else /* !IPOD_VIDEO */
38extern unsigned char audiobufend[];
39#endif
40/* defined in linker script */
41extern unsigned char audiobuffer[];
42#else /* PLATFORM_HOSTED */
43unsigned char audiobuffer[(MEMORYSIZE*1024-256)*1024];
44unsigned char *audiobufend = audiobuffer + sizeof(audiobuffer);
45extern unsigned char *audiobufend;
46#endif
47
48static unsigned char *audiobuf;
49
50#ifdef BUFFER_ALLOC_DEBUG
51static unsigned char *audiobuf_orig_start;
52
53struct buffer_start_marker
54{
55 unsigned int magic;
56 size_t buffer_size;
57};
58#define BUF_MAGIC 0xDEADD0D0
59
60struct buffer_end_marker
61{
62 unsigned int magic;
63 int last;
64};
65#endif /* BUFFER_ALLOC_DEBUG */
66
67void buffer_init(void)
68{
69 /* 32-bit aligned */
70 audiobuf = (void *)(((unsigned long)audiobuffer + 3) & ~3);
71
72#if defined(IPOD_VIDEO) && !defined(BOOTLOADER) && !defined(SIMULATOR)
73 audiobufend=(unsigned char *)audiobufend_lds;
74 if(MEMORYSIZE==64 && probed_ramsize!=64)
75 {
76 audiobufend -= (32<<20);
77 }
78#endif
79
80#ifdef BUFFER_ALLOC_DEBUG
81 audiobuf_orig_start = audiobuf;
82#endif /* BUFFER_ALLOC_DEBUG */
83}
84
85/* protect concurrent access */
86static volatile int lock;
87
88/*
89 * Give the entire buffer, return the size in size.
90 * The caller needs to make sure audiobuf is not otherwise used
91 *
92 * Note that this does not modify the buffer position (buffer_release_buffer()
93 * does), so call this if you want to aquire temporary memory
94 **/
95void *buffer_get_buffer(size_t *size)
96{
97 if (lock)
98 panicf("concurrent audiobuf access");
99 lock = 1;
100 audiobuf = ALIGN_UP(audiobuf, sizeof(intptr_t));
101 *size = (audiobufend - audiobuf);
102 return audiobuf;
103}
104
105/*
106 * Release the buffer gotten with buffer_get_buffer
107 *
108 * size should have the amount of bytes (from the front) that caller keeps for
109 * its own, 0 if the entire buffer is to be released
110 *
111 * safe to be called with size=0 even if the buffer wasn't claimed before
112 **/
113void buffer_release_buffer(size_t size)
114{
115 audiobuf += size;
116 /* ensure alignment */
117 audiobuf = ALIGN_UP(audiobuf, sizeof(intptr_t));
118 lock = 0;
119}
120
121/*
122 * Query how much free space the buffer has */
123size_t buffer_available(void)
124{
125 return audiobufend - audiobuf;
126}
127
128void *buffer_alloc(size_t size)
129{
130 if (lock) /* it's not save to call this here */
131 panicf("buffer_alloc(): exclusive buffer owner");
132 void *retval;
133#ifdef BUFFER_ALLOC_DEBUG
134 struct buffer_start_marker *start;
135 struct buffer_end_marker *end;
136#endif /* BUFFER_ALLOC_DEBUG */
137
138 /* 32-bit aligned */
139 size = (size + 3) & ~3;
140
141 /* Other code touches audiobuf. Make sure it stays aligned */
142 audiobuf = (void *)(((unsigned long)audiobuf + 3) & ~3);
143
144 retval = audiobuf;
145
146#ifdef BUFFER_ALLOC_DEBUG
147 retval +=sizeof(struct buffer_start_marker);
148 if(size>0)
149 {
150 end=(struct buffer_end_marker*)(audiobuf - sizeof(struct buffer_end_marker));
151 if(end->magic == BUF_MAGIC)
152 {
153 end->last=0;
154 }
155 start=(struct buffer_start_marker*)audiobuf;
156 start->magic = BUF_MAGIC;
157 start->buffer_size = size;
158 end=(struct buffer_end_marker*)(audiobuf+sizeof(struct buffer_start_marker)+size);
159 end->magic = BUF_MAGIC;
160 end->last = 1;
161
162 audiobuf = ((unsigned char *)end) + sizeof(struct buffer_end_marker);
163 }
164
165 logf("Alloc %x %d",(unsigned int)retval,size);
166#else /* !BUFFER_ALLOC_DEBUG */
167 audiobuf += size;
168#endif /* BUFFER_ALLOC_DEBUG */
169
170 if (audiobuf > audiobufend) {
171 panicf("OOM: %d bytes", (int) size);
172 }
173
174 return retval;
175}
176
177#ifdef BUFFER_ALLOC_DEBUG
178void buffer_alloc_check(char *name)
179{
180 unsigned char *buf_ptr = audiobuf_orig_start;
181 struct buffer_start_marker *start;
182 struct buffer_end_marker *end;
183
184
185 while(buf_ptr < audiobuf)
186 {
187 start=(struct buffer_start_marker*)buf_ptr;
188 if(start->magic != BUF_MAGIC)
189 {
190 panicf("%s corrupted buffer %x start", name,(unsigned int)buf_ptr+sizeof(struct buffer_start_marker));
191 }
192 end=(struct buffer_end_marker*)(buf_ptr+sizeof(struct buffer_start_marker)+start->buffer_size);
193 if(end->magic != BUF_MAGIC)
194 {
195 panicf("%s corrupted %x end", name,(unsigned int)buf_ptr+sizeof(struct buffer_start_marker));
196 }
197 if(end->last)
198 break;
199 buf_ptr=((unsigned char *)end)+sizeof(struct buffer_end_marker);
200 }
201}
202#endif /* BUFFER_ALLOC_DEBUG */
diff --git a/firmware/buflib.c b/firmware/buflib.c
index 748e8a2378..d3f1455c99 100644
--- a/firmware/buflib.c
+++ b/firmware/buflib.c
@@ -30,7 +30,6 @@
30#include "buflib.h" 30#include "buflib.h"
31#include "string-extra.h" /* strlcpy() */ 31#include "string-extra.h" /* strlcpy() */
32#include "debug.h" 32#include "debug.h"
33#include "buffer.h"
34#include "system.h" /* for ALIGN_*() */ 33#include "system.h" /* for ALIGN_*() */
35 34
36/* The main goal of this design is fast fetching of the pointer for a handle. 35/* The main goal of this design is fast fetching of the pointer for a handle.
diff --git a/firmware/core_alloc.c b/firmware/core_alloc.c
index 21dd1319dd..34ed48b39f 100644
--- a/firmware/core_alloc.c
+++ b/firmware/core_alloc.c
@@ -1,21 +1,44 @@
1 1
2#include "config.h"
2#include <string.h> 3#include <string.h>
4#include "system.h"
3#include "core_alloc.h" 5#include "core_alloc.h"
4#include "buflib.h" 6#include "buflib.h"
5#include "buffer.h"
6 7
7/* not static so it can be discovered by core_get_data() */ 8/* not static so it can be discovered by core_get_data() */
8struct buflib_context core_ctx; 9struct buflib_context core_ctx;
9 10
11/* defined in linker script */
12#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
13#if defined(IPOD_VIDEO) && !defined(BOOTLOADER)
14extern unsigned char *audiobufend_lds[];
15unsigned char *audiobufend;
16#else /* !IPOD_VIDEO */
17extern unsigned char audiobufend[];
18#endif
19/* defined in linker script */
20extern unsigned char audiobuffer[];
21#else /* PLATFORM_HOSTED */
22unsigned char audiobuffer[(MEMORYSIZE*1024-256)*1024];
23unsigned char *audiobufend = audiobuffer + sizeof(audiobuffer);
24extern unsigned char *audiobufend;
25#endif
26
10/* debug test alloc */ 27/* debug test alloc */
11static int test_alloc; 28static int test_alloc;
12void core_allocator_init(void) 29void core_allocator_init(void)
13{ 30{
14 buffer_init(); 31 unsigned char *start = ALIGN_UP(audiobuffer, sizeof(intptr_t));
15 size_t size; 32
16 void *start = buffer_get_buffer(&size); 33#if defined(IPOD_VIDEO) && !defined(BOOTLOADER) && !defined(SIMULATOR)
17 buflib_init(&core_ctx, start, size); 34 audiobufend=(unsigned char *)audiobufend_lds;
18 buffer_release_buffer(size); 35 if(MEMORYSIZE==64 && probed_ramsize!=64)
36 {
37 audiobufend -= (32<<20);
38 }
39#endif
40
41 buflib_init(&core_ctx, start, audiobufend - start);
19 42
20 test_alloc = core_alloc("test", 112); 43 test_alloc = core_alloc("test", 112);
21} 44}
diff --git a/firmware/include/buffer.h b/firmware/include/buffer.h
deleted file mode 100644
index bdf91bcb3f..0000000000
--- a/firmware/include/buffer.h
+++ /dev/null
@@ -1,38 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef BUFFER_H
22#define BUFFER_H
23
24#include "config.h"
25
26void buffer_init(void) INIT_ATTR;
27
28void* buffer_get_buffer(size_t *size);
29void buffer_release_buffer(size_t size);
30size_t buffer_available(void);
31
32void *buffer_alloc(size_t size);
33
34#ifdef BUFFER_ALLOC_DEBUG
35void buffer_alloc_check(char *name);
36#endif
37
38#endif
diff --git a/firmware/thread.c b/firmware/thread.c
index cfedbbedba..a1886cbc07 100644
--- a/firmware/thread.c
+++ b/firmware/thread.c
@@ -27,7 +27,6 @@
27#include "kernel.h" 27#include "kernel.h"
28#include "cpu.h" 28#include "cpu.h"
29#include "string.h" 29#include "string.h"
30#include "buffer.h"
31#ifdef RB_PROFILE 30#ifdef RB_PROFILE
32#include <profile.h> 31#include <profile.h>
33#endif 32#endif
@@ -1168,16 +1167,6 @@ void switch_thread(void)
1168 if (UNLIKELY(thread->stack[0] != DEADBEEF) && thread->stack_size > 0) 1167 if (UNLIKELY(thread->stack[0] != DEADBEEF) && thread->stack_size > 0)
1169 thread_stkov(thread); 1168 thread_stkov(thread);
1170 1169
1171#ifdef BUFFER_ALLOC_DEBUG
1172 /* Check if the current thread just did bad things with buffer_alloc()ed
1173 * memory */
1174 {
1175 static char name[32];
1176 thread_get_name(name, 32, thread);
1177 buffer_alloc_check(name);
1178 }
1179#endif
1180
1181#if NUM_CORES > 1 1170#if NUM_CORES > 1
1182 /* Run any blocking operations requested before switching/sleeping */ 1171 /* Run any blocking operations requested before switching/sleeping */
1183 run_blocking_ops(core, thread); 1172 run_blocking_ops(core, thread);
diff --git a/flash/bootbox/main.c b/flash/bootbox/main.c
index e4be785beb..ff6b8374e9 100644
--- a/flash/bootbox/main.c
+++ b/flash/bootbox/main.c
@@ -39,7 +39,6 @@
39#include "panic.h" 39#include "panic.h"
40#include "power.h" 40#include "power.h"
41#include "file.h" 41#include "file.h"
42#include "buffer.h"
43#include "rolo.h" 42#include "rolo.h"
44#include "usb.h" 43#include "usb.h"
45#include "powermgmt.h" 44#include "powermgmt.h"
@@ -146,7 +145,6 @@ void main(void)
146 power_init(); 145 power_init();
147 system_init(); 146 system_init();
148 kernel_init(); 147 kernel_init();
149 buffer_init();
150 lcd_init(); 148 lcd_init();
151 show_logo(); 149 show_logo();
152 enable_irq(); 150 enable_irq();