libluna: Document Bitset.h
This commit is contained in:
parent
3f1e6fc2ff
commit
798a6d63aa
@ -24,13 +24,16 @@ Result<void> check_pledge(Thread* thread, Promise promise)
|
||||
// Thread::process_pending_signals().
|
||||
thread->signal_handlers[SIGABRT - 1].sa_handler = SIG_DFL;
|
||||
|
||||
// Unblock SIGABRT.
|
||||
thread->signal_mask.set(SIGABRT - 1, false);
|
||||
|
||||
// If there are any other pending signals, they might be processed before SIGABRT. Avoid that by resetting the
|
||||
// thread's pending signals.
|
||||
thread->pending_signals = 0;
|
||||
thread->pending_signals.clear();
|
||||
|
||||
thread->send_signal(SIGABRT);
|
||||
|
||||
// This should never arrive to userspace.
|
||||
// This should never arrive to userspace, unless we're init and have ignored SIGABRT.
|
||||
return err(ENOSYS);
|
||||
}
|
||||
|
||||
|
@ -1,27 +1,66 @@
|
||||
/**
|
||||
* @file Bitset.h
|
||||
* @author apio (cloudapio.eu)
|
||||
* @brief A wrapper class to modify/inspect specific bits of an integer type.
|
||||
*
|
||||
* @copyright Copyright (c) 2023, the Luna authors.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <luna/Check.h>
|
||||
|
||||
/**
|
||||
* @brief A wrapper class to modify/inspect specific bits of an integer type, to avoid manual error-prone bit shifting.
|
||||
*
|
||||
* @tparam T The integer type to use.
|
||||
*/
|
||||
template <typename T> class Bitset
|
||||
{
|
||||
public:
|
||||
Bitset() : m_value()
|
||||
/**
|
||||
* @brief Construct a new empty Bitset object.
|
||||
*/
|
||||
Bitset() : m_value(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Construct a new Bitset object with a value.
|
||||
*
|
||||
* @param value The value to use.
|
||||
*/
|
||||
Bitset(T value) : m_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Construct a copy of another Bitset object.
|
||||
*
|
||||
* @param other The original object.
|
||||
*/
|
||||
Bitset(const Bitset<T>& other) : m_value(other.m_value)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update the internal value of this bitset.
|
||||
*
|
||||
* @param value The new value.
|
||||
* @return Bitset<T>& A reference to this itset.
|
||||
*/
|
||||
Bitset<T>& operator=(T value)
|
||||
{
|
||||
m_value = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set this bitset to the same value as another bitset.
|
||||
*
|
||||
* @param other The pther bitset.
|
||||
* @return Bitset<T>& A reference to this bitset.
|
||||
*/
|
||||
Bitset<T>& operator=(const Bitset<T>& other)
|
||||
{
|
||||
if (&other == this) return *this;
|
||||
@ -29,11 +68,23 @@ template <typename T> class Bitset
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the value contained in this bitset.
|
||||
*
|
||||
* @return T The contained value.
|
||||
*/
|
||||
T value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Modify one of the individual bits in this bitset.
|
||||
*
|
||||
* @param index The index of the bit (this will set/unset 1 << index). It must be less than the bit width of the
|
||||
* underlying type.
|
||||
* @param b The value to set the bit to.
|
||||
*/
|
||||
void set(int index, bool b)
|
||||
{
|
||||
check((usize)index < (sizeof(T) * 8));
|
||||
@ -42,12 +93,22 @@ template <typename T> class Bitset
|
||||
m_value &= ~(((T)1) << index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the value of one of the individual bits in this bitset.
|
||||
*
|
||||
* @param index The index of the bit (this will read 1 << index). It must be less than the bit width of the
|
||||
* underlying type.
|
||||
* @return bool The value of the requested bit.
|
||||
*/
|
||||
bool get(int index)
|
||||
{
|
||||
check((usize)index < (sizeof(T) * 8));
|
||||
return m_value & (((T)1) << index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear all the bits in this bitset.
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
m_value = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user