summaryrefslogtreecommitdiff
path: root/firmware/buflib.c (follow)
Commit message (Collapse)AuthorAge
* buflib: Switch from term "cookie" to "metadata"Thomas Jarosch2015-01-02
| | | | | | | | | The documentation of buflib first mentions metadata and then changes to "cookie" without explaining it. Fix it by sticking to metadata. Change-Id: I0b36b18f4f2590132901c10326481975f8b9b9da
* Improve core_alloc() / buflib_alloc() documentationThomas Jarosch2015-01-02
| | | | | | | | | | | | | | | | | | | | Document the fact that buffers are movable by default. Care must be taken to not pass them to functions that yield(). Also clarify other things: - Passing NULL as "ops" to buflib_alloc_ex() causes buffers to be movable by default (but not shrinkable). - If you want shrinkable buffers during compaction, you have to provide a shrink callback. - To disable buffer movement, you have to pass NULL for the move_callback inside the callback structure. - The concept of default callbacks was removed long ago, remove the only reference of it. Change-Id: I3bf0ea6b08b507d80a19f3c2c835aca32b3f7800
* PictureFlow: Add move callback for buflib allocationsThomas Jarosch2015-01-01
| | | | | | | | | | If we don't provide a callback to buflib_alloc(), the buffer is always movable (to reduce fragmentation). Since we pass our buffer to functions that call yield(), this could lead to memory corruption on buflib compaction. Change-Id: Id1fad1822479d692551c55cb8bc87cea7b78f759
* Add missing newline in debug outputThomas Jarosch2014-12-30
| | | | Change-Id: Ifd67dbcc80db328391464ec93316c48f914bc590
* Document 'union buflib_data'Thomas Jarosch2014-12-29
| | | | Change-Id: Ia98fa8e7887338d6c0b7a5795a0ae5c7a13014ba
* buflib: Add a define telling the per-alloc overhead.Thomas Martitz2014-02-02
| | | | | | | | This allows buflib clients to more accurately estimate the total memory usage. It's still not 100% accurate because the handle table grows in blocks, thus buflib might use more memory that caused by allocations directly. Change-Id: I68338bb94f510ad188fcb588aebf895b5f9197c5
* buflib: Properly support allocations without any name, to avoid wasting spaceThomas Martitz2014-02-02
| | | | | | in micro-allocation scenarios. Change-Id: I97a065bcfba8e0fda9b1670445e839e267c769c8
* buflib: Check the validity of of handles passed to buflib_get_data() in ↵Thomas Martitz2014-02-02
| | | | | | DEBUG builds. Change-Id: Ic274bfb4a8e1a1a10f9a54186b9173dbc0faa4c8
* buflib: Abstract panicf() into buflib_panic().Thomas Martitz2014-02-02
| | | | Change-Id: I4968a9bc290e10e30a77c36c19f694e286e7ef22
* buflib: Add crc field protecting buflib cookie integrityMarcin Bukat2014-01-16
| | | | | | | | | | | | | | | This should catch the case of buffer misuse which results in corrupted cookie of next allocation. The check is performed on move_block() so it may be a bit late. There is buflib_check_valid() provided which checks the integrity of all cookies for given context. On DEBUG build with --sdl-thread this check is carried out for core_ctx on every context switch to catch problems earlier. Change-Id: I999d4576084592394e3dbd3bdf0f32935ff5f601 Reviewed-on: http://gerrit.rockbox.org/711 Reviewed-by: Thomas Martitz <kugel@rockbox.org>
* Do not include kernel.h in system.h.Thomas Martitz2014-01-05
| | | | | | | system.h doesn't need it on its own and this change makes it less dependant on Rockbox internals. Change-Id: I4e1e4108a52a7b599627a829204eb82b392fc6d6
* buflib: Add buflib_context_relocate().Thomas Martitz2013-12-22
| | | | | | | | | | | | | | This function relocates a buflib back buffer, updating pointers in struct buflib_context. It does not move any data by itself. The intended use-case is buflib-on-buflib, where a buflib back buffer is allocated with buflib and attempted to be moved. The move_callback() can call this and return BUFLIB_CB_OK on success. No move_callback() is called for the subordinate buflib buffer, therefore it must not contain non-movable allocations. The caller is generally responsible moving the data and all its implications. Change-Id: I869219f9cff786a172c9e917a5f34470073892e6
* buflib: Try harder in buflib_alloc_maximum().Thomas Martitz2013-12-22
| | | | | | | | This function will now ask shrinkable allocations to give up all of their memory. With future support of playback.c this can be used as a safe replacement for audio_get_buffer(). Change-Id: I290a51d2c75254e66baf5698c41dc444dea6247a
* buflib: Change buflib_available() and add buflib_allocatable().Thomas Martitz2013-07-07
| | | | | | | | | | | | | | | buflib_allocatable() is what buflib_available() was before (it was in fact simply renamed). It returns the largest contiguous block of memory. This can be allocated and will definitely succeed, although larger allocations may also succeed if the buffer can be compacted and shrinked. buflib_available() now counts all free bytes, contiguous or not. This better matches the description and how the caller use it. Change-Id: I511e4eb5f4cf1821d957b3f4ef8a685ce40fe289 Reviewed-on: http://gerrit.rockbox.org/481 Reviewed-by: Thomas Martitz <kugel@rockbox.org> Tested-by: Thomas Martitz <kugel@rockbox.org>
* buflib: Allow handle to be freed entirely during the shrink callback.Thomas Martitz2013-06-24
| | | | | | | Change-Id: I3a069dcb99bbd4022faf37596b03beb926d2ea82 Reviewed-on: http://gerrit.rockbox.org/480 Reviewed-by: Thomas Martitz <kugel@rockbox.org> Tested-by: Thomas Martitz <kugel@rockbox.org>
* buflib: Remove compulsory IRQ disable during buffer move.Michael Sevakis2013-05-23
| | | | | | | | | | | | | | | | | It can cause excessively long interrupt outages if moving a larger buffer and disrupt audio where DMA is not at a higher interrupt priority such as FIQ. Some targets, like Gigabeat S, have very low audio interrupt latency requirements and will even channel swap if they are missed. Pictureflow will make the issue very obvious. Even then, moves could take milliseconds or more depending on the buffer size which is far too long for any target. Change-Id: I8e7817213e901da67c36b7eb25d7cb1c1e3ba802 Reviewed-on: http://gerrit.rockbox.org/472 Reviewed-by: Michael Sevakis <jethead71@rockbox.org> Tested-by: Michael Sevakis <jethead71@rockbox.org>
* Stop the BDEBUGF format warnings in buflib.cMichael Sevakis2012-05-02
| | | | Change-Id: I63881da2b857cf4e462f7730f9cd54dc1743fc2f
* Stop lame warnings about braces and empty body of 'if' statement.Michael Sevakis2012-05-02
| | | | Change-Id: I9f0e3d047a91a8f49d5c64f961f8fff054f37099
* Use buflib for the allocation of voice PCM resources.Michael Sevakis2012-05-02
| | | | | | | | | | | | | Buffers are not allocated and thread is not created until the first call where voice is required. Adds a different callback (sync_callback) to buflib so that other sorts of synchonization are possible, such as briefly locking-out the PCM callback for a buffer move. It's sort of a messy addition but it is needed so voice decoding won't have to be stopped when its buffer is moved. Change-Id: I4d4d8c35eed5dd15fb7ee7df9323af3d036e92b3
* Buflib: Fix handles being possibly moved twiceThomas Martitz2011-12-19
| | | | | | | Author: Boris Gjenero Fixes: FS#12441, FS#12464 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31359 a1c6a512-1295-4272-9138-f99709370657
* Address some weaknesses and bugs of buflib_compact() and make the code ↵Thomas Martitz2011-12-01
| | | | | | | | | prettier. Thanks to Boris Gjenero for his great investigation. Flyspray: FS#12409 Author: myself git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31101 a1c6a512-1295-4272-9138-f99709370657
* FS#12412 : Delete old buffer allocation code which has been replaced by ↵Boris Gjenero2011-11-29
| | | | | | 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
* In buflib_buffer_shift(), properly update handle->alloc values, which are ↵Boris Gjenero2011-11-27
| | | | | | char * and not union buflib data * git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31066 a1c6a512-1295-4272-9138-f99709370657
* Buflib: Make shrinking and buflib_available() smarter.Thomas Martitz2011-11-17
| | | | | | | | | | | | | | | | | * shrinking now considers freespace just before the alloc-to-be-shrinked, that means less (or sometimes none at all) is taken from the audio buffer. * core_available() now searches for the best free space, instead of simply the end, i.e. it will not return 0 if the audio buffer is allocated and there's free space before it. It also runs a compaction to ensure maximum contiguous memory. audio_buffer_available() is also enhanced. It now considers the 256K reserve buffer, and returns free buflib space instead if the audio buffer is short. This all fixes the root problem of FS#12344 (Sansa Clip+: PANIC occurred when dircache is enabled), that alloced from the audio buffer, even if it was very short and buflib had many more available as free space before it. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31006 a1c6a512-1295-4272-9138-f99709370657
* Fix audio_get_buffer() implementation on hwcodec, to be similar to the ↵Thomas Martitz2011-10-09
| | | | | | swcodec one. Should make hwcodec bood again. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30737 a1c6a512-1295-4272-9138-f99709370657
* Protect the move operation of buflib against IRQs.Thomas Martitz2011-10-09
| | | | | | | This makes accessing the buffers with core_get_data() from interrupt context safe, other buflib functions aren't really safe (yet). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30736 a1c6a512-1295-4272-9138-f99709370657
* Buflib: Correct return value of handle_table_shrink() to match comment.Thomas Martitz2011-09-10
| | | | git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30495 a1c6a512-1295-4272-9138-f99709370657
* Remove obsolete commentThomas Martitz2011-09-09
| | | | git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30488 a1c6a512-1295-4272-9138-f99709370657
* Buflib: Stop caching the first unallocated block. It has little benefit but ↵Thomas Martitz2011-09-09
| | | | | | is complicated to keep up-to-date. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30487 a1c6a512-1295-4272-9138-f99709370657
* Buflib: Handle not having enough space for new handles (fixes FS#12265).Thomas Martitz2011-09-09
| | | | | | | | | | Handles are allocated at the end, growing downwards. The tiny allocations from r30478 broke buflib, since it was assumed that the only shrinkable allocation (the audiobuffer) is the very last allocation. The tiny allocations however fit into the reserve buffer for new handles, breaking the above assumption, and they can't shrink to make room for handles. Now, move any allocations before audiobuf (or shrink audiobuf like before) to make room for handles. This also unifies some duplicated code. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30486 a1c6a512-1295-4272-9138-f99709370657
* Remove unecessary castingThomas Martitz2011-09-07
| | | | git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30470 a1c6a512-1295-4272-9138-f99709370657
* Buflib: Clarification about invalid handlesThomas Martitz2011-09-07
| | | | | | | | * Enhance allocation function comments to better state the return value and what an invalid value is * Change clients to check for "< 0" instead of "<= 0" or "== 0" * Return -1 or -2 depending on the exact failure in buflib_alloc_ex. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30469 a1c6a512-1295-4272-9138-f99709370657
* Fix h100 red and other warnings.Thomas Martitz2011-08-30
| | | | git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30384 a1c6a512-1295-4272-9138-f99709370657
* GSoC/Buflib: Enable compaction in buflib.Thomas Martitz2011-08-30
| | | | | | | | | | | | | | | | | | | This enables the ability to allocate (and free) memory dynamically without fragmentation, through compaction. This means allocations can move and fragmentation be reduced. Most changes are preparing Rockbox for this, which many times means adding a move callback which can temporarily disable movement when the corresponding code is in a critical section. For now, the audio buffer allocation has a central role, because it's the one having allocated most. This buffer is able to shrink itself, for which it needs to stop playback for a very short moment. For this, audio_buffer_available() returns the size of the audio buffer which can possibly be used by other allocations because the audio buffer can shrink. lastfm scrobbling and timestretch can now be toggled at runtime without requiring a reboot. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30381 a1c6a512-1295-4272-9138-f99709370657
* GSoC/Buflib: Add buflib memory alocator to the core.Thomas Martitz2011-08-30
The buflib memory allocator is handle based and can free and compact, move or resize memory on demand. This allows to effeciently allocate memory dynamically without an MMU, by avoiding fragmentation through memory compaction. This patch adds the buflib library to the core, along with convinience wrappers to omit the context parameter. Compaction is not yet enabled, but will be in a later patch. Therefore, this acts as a replacement for buffer_alloc/buffer_get_buffer() with the benifit of a debug menu. See buflib.h for some API documentation. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30380 a1c6a512-1295-4272-9138-f99709370657