Add with_value_of and with_value to MSR

This commit is contained in:
apio 2022-09-25 17:28:38 +02:00
parent aee4e55fdd
commit 4e62566c48
2 changed files with 18 additions and 0 deletions

View File

@ -13,6 +13,9 @@ struct MSR
static void write_to(uint32_t msr_num, uint64_t value);
static uint64_t read_from(uint32_t msr_num);
static void with_value_of(uint32_t msr_num, void (*callback)(uint64_t&));
void with_value(void (*callback)(uint64_t&));
private:
uint32_t m_msr_num;
};

View File

@ -27,4 +27,19 @@ uint64_t MSR::read()
MSR::MSR(uint32_t msr_num) : m_msr_num(msr_num)
{
}
void MSR::with_value_of(uint32_t msr_num, void (*callback)(uint64_t&))
{
MSR msr(msr_num);
uint64_t value = msr.read();
callback(value);
msr.write(value);
}
void MSR::with_value(void (*callback)(uint64_t&))
{
uint64_t value = read();
callback(value);
write(value);
}