os: refactor/rewrite entire namespace.

This commit is contained in:
Michael Scire 2020-04-08 02:21:35 -07:00
parent 6193283f03
commit 065485b971
181 changed files with 5353 additions and 1929 deletions

View file

@ -13,43 +13,58 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "os_mutex.hpp"
#include "os_condvar.hpp"
#include <stratosphere/os/os_semaphore_types.hpp>
#include <stratosphere/os/os_semaphore_api.hpp>
namespace ams::os {
namespace impl {
class WaitableObjectList;
class WaitableHolderOfSemaphore;
}
class Semaphore {
friend class impl::WaitableHolderOfSemaphore;
NON_COPYABLE(Semaphore);
NON_MOVEABLE(Semaphore);
private:
util::TypedStorage<impl::WaitableObjectList, sizeof(util::IntrusiveListNode), alignof(util::IntrusiveListNode)> waitlist;
os::Mutex mutex;
os::ConditionVariable condvar;
int count;
int max_count;
SemaphoreType sema;
public:
explicit Semaphore(int c, int mc);
~Semaphore();
explicit Semaphore(s32 count, s32 max_count) {
InitializeSemaphore(std::addressof(this->sema), count, max_count);
}
void Acquire();
bool TryAcquire();
bool TimedAcquire(u64 timeout);
~Semaphore() { FinalizeSemaphore(std::addressof(this->sema)); }
void Release();
void Release(int count);
void Acquire() {
return os::AcquireSemaphore(std::addressof(this->sema));
}
constexpr inline int GetCurrentCount() const {
return this->count;
bool TryAcquire() {
return os::TryAcquireSemaphore(std::addressof(this->sema));
}
bool TimedAcquire(TimeSpan timeout) {
return os::TimedAcquireSemaphore(std::addressof(this->sema), timeout);
}
void Release() {
return os::ReleaseSemaphore(std::addressof(this->sema));
}
void Release(s32 count) {
return os::ReleaseSemaphore(std::addressof(this->sema), count);
}
s32 GetCurrentCount() const {
return os::GetCurrentSemaphoreCount(std::addressof(this->sema));
}
operator SemaphoreType &() {
return this->sema;
}
operator const SemaphoreType &() const {
return this->sema;
}
SemaphoreType *GetBase() {
return std::addressof(this->sema);
}
};