kernel-interface: Add method to increase refcount for allocated reqid

This commit is contained in:
Tobias Brunner 2023-10-02 14:58:50 +02:00
parent 02180ae2ff
commit e623f5792b
2 changed files with 30 additions and 0 deletions

View File

@ -433,6 +433,23 @@ METHOD(kernel_interface_t, alloc_reqid, status_t,
return SUCCESS;
}
METHOD(kernel_interface_t, ref_reqid, status_t,
private_kernel_interface_t *this, uint32_t reqid)
{
reqid_entry_t *entry, tmpl = {
.reqid = reqid,
};
this->mutex->lock(this->mutex);
entry = this->reqids->get(this->reqids, &tmpl);
if (entry)
{
entry->refs++;
}
this->mutex->unlock(this->mutex);
return entry ? SUCCESS : NOT_FOUND;
}
METHOD(kernel_interface_t, release_reqid, status_t,
private_kernel_interface_t *this, uint32_t reqid)
{
@ -1039,6 +1056,7 @@ kernel_interface_t *kernel_interface_create()
.get_spi = _get_spi,
.get_cpi = _get_cpi,
.alloc_reqid = _alloc_reqid,
.ref_reqid = _ref_reqid,
.release_reqid = _release_reqid,
.add_sa = _add_sa,
.update_sa = _update_sa,

View File

@ -158,6 +158,18 @@ struct kernel_interface_t {
uint32_t if_id_out, sec_label_t *label,
uint32_t *reqid);
/**
* Increase the reference count for the given reqid that was previously
* allocated by alloc_reqid().
*
* The reference must be released with a call to release_reqid().
*
* @param reqid previously allocated reqid
* @return SUCCESS if refcount increased, NOT_FOUND if reqid is
* unknown (shouldn't happen)
*/
status_t (*ref_reqid)(kernel_interface_t *this, uint32_t reqid);
/**
* Release a previously allocated reqid.
*