forked from len0rd/rockbox
buflib: Add pinned get/put data functions
These are more efficient than separate pin/unpin calls because pin count increment and decrement can be done cheaply when the data pointer is known. Secondly, pinned access can be made safe against preemption by hardware interrupts or other CPU cores; buflib_get_data() can't. This makes it more useful under different threading models and for SMP targets; both of which are not particularly relevant to Rockbox now, but might be in the future. Change-Id: I09284251b83bbbc59ef88a494c8fda26a7f7ef26
This commit is contained in:
parent
92565e9246
commit
800bc000a0
5 changed files with 109 additions and 35 deletions
|
|
@ -316,6 +316,32 @@ void *buflib_get_data(struct buflib_context *ctx, int handle);
|
|||
static inline void *buflib_get_data(struct buflib_context *ctx, int handle);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Get a pinned pointer to a buflib allocation
|
||||
* \param ctx Buflib context of the allocation
|
||||
* \param handle Handle identifying the allocation
|
||||
* \return Pointer to the allocation's memory.
|
||||
*
|
||||
* Functionally equivalent to buflib_pin() followed by buflib_get_data(),
|
||||
* but this call is more efficient and should be preferred over separate
|
||||
* calls.
|
||||
*
|
||||
* To unpin the data, call buflib_put_data_pinned() and pass the pointer
|
||||
* returned by this function.
|
||||
*/
|
||||
static inline void *buflib_get_data_pinned(struct buflib_context *ctx, int handle);
|
||||
|
||||
/**
|
||||
* \brief Release a pinned pointer to a buflib allocation
|
||||
* \param ctx Buflib context of the allocation
|
||||
* \param data Pointer returned by buflib_get_data()
|
||||
*
|
||||
* Decrements the pin count, allowing the buffer to be moved once the
|
||||
* pin count drops to zero. This is more efficient than buflib_unpin()
|
||||
* and should be preferred when you have a pointer to the buflib data.
|
||||
*/
|
||||
static inline void buflib_put_data_pinned(struct buflib_context *ctx, void *data);
|
||||
|
||||
/**
|
||||
* \brief Shift allocations up to free space at the start of the pool
|
||||
* \param ctx Context to operate on
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue