Commit graph

16 commits

Author SHA1 Message Date
Aidan MacDonald
e8faf2f2ad buflib: add a common dummy callbacks struct & use it
There are various allocations that can't be moved or shrunk.
Provide a global callback struct for this use case instead of
making each caller declare its own dummy struct.

Also fixed ROLO and x1000 installer code which incorrectly
used movable allocations.

Change-Id: I00088396b9826e02e69a4a33477fe1a7816374f1
2022-02-12 10:24:32 -05:00
Thomas Jarosch
66df5f3891 Improve core_alloc() / buflib_alloc() documentation
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
2015-01-02 18:51:15 +01:00
Thomas Jarosch
da5a36d6d2 Document 'union buflib_data'
Change-Id: Ia98fa8e7887338d6c0b7a5795a0ae5c7a13014ba
2014-12-29 23:49:12 +01:00
Thomas Jarosch
d68262eede Two more typo fixes
Change-Id: Id3ec7c1da356cb7c617a1d9ad57c9e0ae9fa6611
2014-12-27 02:00:15 +01:00
Thomas Jarosch
91f1393f75 Fix typos in documentation
Change-Id: I3c7e204bcf67bf0004314fe4b2aec98cae145273
2014-12-27 01:38:11 +01:00
Thomas Martitz
4ce39f7e73 buflib: Add a define telling the per-alloc overhead.
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
2014-02-02 19:40:38 +01:00
Thomas Martitz
4ce1deacfd buflib: Properly support allocations without any name, to avoid wasting space
in micro-allocation scenarios.

Change-Id: I97a065bcfba8e0fda9b1670445e839e267c769c8
2014-02-02 19:40:38 +01:00
Thomas Martitz
d66346789c buflib: Check the validity of of handles passed to buflib_get_data() in DEBUG builds.
Change-Id: Ic274bfb4a8e1a1a10f9a54186b9173dbc0faa4c8
2014-02-02 16:59:29 +01:00
Marcin Bukat
7ab237b025 buflib: Add crc field protecting buflib cookie integrity
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>
2014-01-16 10:17:39 +01:00
Thomas Martitz
64b9e1fa7b buflib: Add buflib_context_relocate().
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
2013-12-22 23:11:32 +01:00
Thomas Martitz
d25a512caf buflib: Try harder in buflib_alloc_maximum().
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
2013-12-22 23:11:32 +01:00
Thomas Martitz
af4e408555 buflib: Change buflib_available() and add buflib_allocatable().
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>
2013-07-07 10:46:07 +02:00
Michael Sevakis
da6cebb6b0 Use buflib for the allocation of voice PCM resources.
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
2012-05-02 17:22:28 -04:00
Thomas Martitz
f7cff8bd69 Buflib: Stop caching the first unallocated block. It has little benefit but is complicated to keep up-to-date.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30487 a1c6a512-1295-4272-9138-f99709370657
2011-09-09 15:35:14 +00:00
Thomas Martitz
5296af838c Buflib: Clarification about invalid handles
* 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
2011-09-07 23:16:29 +00:00
Thomas Martitz
d0b72e2590 GSoC/Buflib: Add buflib memory alocator to the core.
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
2011-08-30 14:01:33 +00:00