summaryrefslogtreecommitdiffstats
path: root/ta/ta.c
Commit message (Collapse)AuthorAgeFilesLines
* ALL: use new mp_thread abstractionKacper Michajłow2023-11-051-10/+10
|
* ta: don't hardcode alignment requirementNRK2023-10-231-6/+4
| | | | | | | | use standard C11 max_align_t instead. also sorts the standard header includes. ref: https://en.cppreference.com/w/c/types/max_align_t
* ta: increase size of names printedThomas Weißschuh2022-09-111-1/+1
| | | | | | | 30 characters are not a lot. Also when the name is calculated from the allocation site the line number will be the at the end of the name, so truncating it is especially inconvenient.
* ta: add ta_get_parent()wm42020-04-261-1/+11
| | | | Sometimes useful for debugging. Also fix a random typo elsewhere.
* ta: change debug ifdefferywm42020-04-261-4/+8
| | | | | TA_MEMORY_DEBUGGING always defined. But allow defining it from the compiler command line (-D), because maybe that's useful for someone?
* ta: fix logging of unfreed child allocationswm42020-02-291-1/+1
| | | | | | Broken since commit f6615f00eeb05f072a. This traversed the data structure incorrectly, and caused a stack overflow due to infinite recursion.
* ta: minor simplificationwm42020-02-231-2/+1
| | | | | Due to the ta_header.parent invariant, the "h->parent->child==h" check is always true.
* ta: change API; ta_set_parent() and ta_set_destructor() never failwm42020-02-231-21/+9
| | | | | | The previous change ensured that these cannot fail anymore (much like in original talloc). Change the APIs to not return a success value anymore, to "cement" this.
* ta: remove seperate internal "ext" headerwm42020-02-231-79/+54
| | | | | | | | | | | | | | | | | | | | | | | | The ta_ext_header was allocated on demand for allocations which have child-allocations or destructors. In theory, it saved 2 words for every TA leaf allocation. It had the very API-visible problem that setting a parent or destructor could fail. (Although in most cases, the failure was part of an allocation call anyway. Also, mpv code generally used the early-failure variants, so it didn't matter.) I think this was a bit too complex. These 2 words don't really matter; if you have memory allocations where you are worried about overhead, then these simply shouldn't use TA. Also, we never added new features to TA that would have needed more "optional" header fields, which would have justified the use of such a separately allocated header struct. This uses quite straight-forward data structures. The only strange thing is that ta_header.parent is NULL for most child allocations. That is because we don't want to iterate over all children when the parent is reallocated (yes, that is allowed, yes mpv makes use of it). The new code has a few more special cases, because the list sentinel concept isn't used anymore. Using it would have made the code more unnatural/complex, because ta_ext_header doesn't exist anymore.
* ta: remove ta_find_parent()wm42020-02-231-16/+0
| | | | Some mpv code once needed this, but it was removed in 2015.
* ta: destroy/free children in reverse orderwm42019-09-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | This matters when talloc allocations set destructors. Before this commit, destructors were called in the same order as they were added to the parent allocations. Now it happens in reverse order. I think this makes more sense. It's reasonable to assume that an allocation that was added later may depend on any of the previous allocations, so later additions should be destroyed first. (Of course other orders are entirely possible too.) Hopefully this doesn't fix or break anything, but I can't be sure (about either of those). It's risky. (Then why do it?) The destructor of a parent allocation is called before its children. It makes sense and must stay this way, because in most cases, the destructor wants to access the children. This is a reason why I don't really like talloc (it wasn't my idea to use talloc, is my excuse). Quite possible that destructors should be removed from talloc entirely. Actually, this project should probably be rewritten in Rust (or a better language), but that would be even more of a pain; also, I think this is just the right level of suffering and punishment.
* Fix use of ISC licensewm42017-04-151-1/+3
| | | | | | | | | | The license text refers a "above copyright notice", so I guess it'd be good to actually provide such a notice. Add the license to some files that were missing it (since in theory, our Copyright file says that such files are LGPL by default). Remove the questionable remarks about the license in the client API.
* ta: clarify a corner casewm42014-02-231-0/+4
|
* ta: fix compilation with NDEBUGwm42013-12-191-1/+2
|
* Replace tallocwm42013-10-131-0/+439
There are multiple reasons to do this. One big reason is the license: talloc is LGPLv3+, which forces mpv to be licensed as GPLv3+. Another one is that our talloc copy contains modifications, which makes it essentially incompatible with upstream talloc (in particular, our version aborts on out of memory conditions - well, it wasn't my idea). Updating from upstream is also a bit involved - the talloc source is not really organized in a way to allow copying it into projects (and this isn't an intended use-case). Finally, talloc is kind of big and bloated. The replacement halves the amount of code - mainly because we didn't use all talloc features. It's even more extreme if you compare upstream talloc (~4700 lines) and the new allocator without talloc compat (~900 lines). The replacement provides all features we need. It also doesn't clash with talloc. (The talloc compatibility wrapper uses macros to avoid introducing linker-level symbols which could clash with libtalloc.) It also tries to lower the overhead (only 4 words opposed to 10 words in talloc for leaf nodes in release mode). Debugging features like leak reporting can be enabled at compile time and add somewhat more overhead. Though I'm not sure whether the overhead reduction was actually successful: allocations with children need an "extra" header, which adds plenty of overhead, and it turns out that almost half of all allocations have children. Maybe the implementation could be simplified and the extra header removed - even then, overhead would be lower than talloc's. Currently, debugging features can be entirely deactivated by defining NDEBUG - I'm not sure if anything defines this directly yet, though. Unlike in talloc, the leak reporting stuff is thread-safe. (That's also why it's far less elegant, and requires extra list pointers.) Comes with a compatibility layer, so no changes to mpv source code are needed. The idea is that we will pretend to be using talloc for a while, so that we can revert to our old talloc implementation at any time for debugging purposes. Some inspiration was taken from Mesa's ralloc: http://cgit.freedesktop.org/mesa/mesa/tree/src/glsl/ralloc.h This is another talloc replacement, but lacks some features we need (getting size of an allocation, debugging features, being able to access children in the dtor). There's some information in ta/README what will happen next and how the transition is expected to progress.