summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/pdbox.c
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2009-07-23 21:37:35 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2009-07-23 21:37:35 +0000
commit840cd1069292e3f29d18e57f2274ec1e979f858b (patch)
tree0ee1d43fa3863de53c99432dc32001e625703d1c /apps/plugins/pdbox/pdbox.c
parent0d9b7ec73e71188632a4fd584dfd745aeb7571b3 (diff)
downloadrockbox-840cd1069292e3f29d18e57f2274ec1e979f858b.zip
rockbox-840cd1069292e3f29d18e57f2274ec1e979f858b.tar.gz
rockbox-840cd1069292e3f29d18e57f2274ec1e979f858b.tar.bz2
rockbox-840cd1069292e3f29d18e57f2274ec1e979f858b.tar.xz
Another pdbox patch by Wincent Balin (FS #10416): switch to using TLSF as memory allocator. Probably the last patch I commit for him, next changes are for him :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22017 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/pdbox.c')
-rw-r--r--apps/plugins/pdbox/pdbox.c93
1 files changed, 60 insertions, 33 deletions
diff --git a/apps/plugins/pdbox/pdbox.c b/apps/plugins/pdbox/pdbox.c
index 38c12c2..dd848de 100644
--- a/apps/plugins/pdbox/pdbox.c
+++ b/apps/plugins/pdbox/pdbox.c
@@ -58,14 +58,17 @@ rates we expect to see: 32000, 44100, 48000, 88200, 96000. */
/* Quit flag. */
bool quit = false;
+/* Stack sizes for threads. */
+#define CORESTACKSIZE (8 * 1024 * 1024)
+#define GUISTACKSIZE (512 * 1024)
+
+/* Thread stacks. */
+void* core_stack;
+void* gui_stack;
+
/* Thread IDs. */
+unsigned int core_thread_id;
unsigned int gui_thread_id;
-unsigned int time_thread_id;
-
-/* Stacks for threads. */
-#define STACK_SIZE 16384
-uint32_t gui_stack[STACK_SIZE / sizeof(uint32_t)];
-uint32_t time_stack[256 / sizeof(uint32_t)];
/* GUI thread */
@@ -102,20 +105,33 @@ void gui_thread(void)
rb->thread_exit();
}
-/* Running time thread. */
-void time_thread(void)
+/* Core thread */
+void core_thread(void)
{
+ /* Add the directory the called .pd resides in to lib directories. */
+ sys_findlibdir(filename);
+
+ /* Open the PD design file. */
+ sys_openlist = namelist_append(sys_openlist, filename);
+
+ /* Fake a GUI start. */
+ sys_startgui(NULL);
+
+ /* Core scheduler loop */
while(!quit)
{
- /* Add time slice in milliseconds. */
- runningtime += (1000 / HZ);
- rb->sleep(1);
+ /* Use sys_send_dacs() function as timer. */
+ while(sys_send_dacs() != SENDDACS_NO)
+ sched_tick(sys_time + sys_time_per_dsp_tick);
+
+ yield();
}
rb->thread_exit();
}
+
/* Plug-in entry point */
enum plugin_status plugin_start(const void* parameter)
{
@@ -133,14 +149,19 @@ enum plugin_status plugin_start(const void* parameter)
return PLUGIN_ERROR;
}
- /* Allocate memory; check it's size; add to the pool. */
+ /* Initialize memory pool. */
mem_pool = rb->plugin_get_audio_buffer(&mem_size);
if(mem_size < MIN_MEM_SIZE)
{
rb->splash(HZ, "Not enough memory!");
return PLUGIN_ERROR;
}
- add_pool(mem_pool, mem_size);
+#if 1
+ init_memory_pool(mem_size, mem_pool);
+#endif
+#if 0
+ set_memory_pool(mem_pool, mem_size);
+#endif
/* Initialize net. */
net_init();
@@ -164,36 +185,36 @@ enum plugin_status plugin_start(const void* parameter)
DEFAULTADVANCE, /* Scheduler advance */
1 /* Enable */);
- /* Add the directory the called .pd resides in to lib directories. */
- sys_findlibdir(filename);
-
- /* Open the parameter file. */
- sys_openlist = namelist_append(sys_openlist, filename);
-
- /* Fake a GUI start. */
- sys_startgui(NULL);
+ /* Create stacks for threads. */
+ core_stack = getbytes(CORESTACKSIZE);
+ gui_stack = getbytes(GUISTACKSIZE);
+ if(core_stack == NULL || gui_stack == NULL)
+ {
+ rb->splash(HZ, "Not enough memory!");
+ return PLUGIN_ERROR;
+ }
/* Start threads. */
- time_thread_id =
- rb->create_thread(&time_thread,
- time_stack,
- sizeof(time_stack),
+ core_thread_id =
+ rb->create_thread(&core_thread,
+ core_stack,
+ CORESTACKSIZE,
0, /* FIXME Which flags? */
- "PD running time"
+ "PD core"
IF_PRIO(, PRIORITY_REALTIME)
IF_COP(, COP));
gui_thread_id =
rb->create_thread(&gui_thread,
gui_stack,
- sizeof(gui_stack),
+ GUISTACKSIZE,
0, /* FIXME Which flags? */
"PD GUI"
IF_PRIO(, PRIORITY_USER_INTERFACE)
IF_COP(, CPU));
/* If having an error creating threads, bail out. */
- if(time_thread_id == 0 || gui_thread_id == 0)
+ if(core_thread_id == 0 || gui_thread_id == 0)
return PLUGIN_ERROR;
/* Initialize scheduler time variables. */
@@ -205,9 +226,8 @@ enum plugin_status plugin_start(const void* parameter)
/* Main loop. */
while(!quit)
{
- /* Use sys_send_dacs() function as timer. */
- while(sys_send_dacs() != SENDDACS_NO)
- sched_tick(sys_time + sys_time_per_dsp_tick);
+ /* Add time slice in milliseconds. */
+ runningtime += (1000 / HZ);
/* Sleep to the next time slice. */
rb->sleep(1);
@@ -215,7 +235,7 @@ enum plugin_status plugin_start(const void* parameter)
/* Wait for threads to complete. */
rb->thread_wait(gui_thread_id);
- rb->thread_wait(time_thread_id);
+ rb->thread_wait(core_thread_id);
/* Close audio subsystem. */
sys_close_audio();
@@ -223,6 +243,13 @@ enum plugin_status plugin_start(const void* parameter)
/* Destroy net. */
net_destroy();
+ /* Clear memory pool. */
+#if 1
+ destroy_memory_pool(mem_pool);
+#endif
+#if 0
+ clear_memory_pool();
+#endif
+
return PLUGIN_OK;
}
-