2019-12-09 11:57:37 +00:00
|
|
|
/*
|
2020-01-24 10:10:40 +00:00
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
2019-12-09 11:57:37 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* 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
|
2020-04-08 10:21:35 +01:00
|
|
|
#include <stratosphere/os/os_semaphore_types.hpp>
|
|
|
|
#include <stratosphere/os/os_semaphore_api.hpp>
|
2019-12-09 11:57:37 +00:00
|
|
|
|
|
|
|
namespace ams::os {
|
|
|
|
|
|
|
|
class Semaphore {
|
|
|
|
NON_COPYABLE(Semaphore);
|
|
|
|
NON_MOVEABLE(Semaphore);
|
|
|
|
private:
|
2020-04-08 10:21:35 +01:00
|
|
|
SemaphoreType sema;
|
2019-12-09 11:57:37 +00:00
|
|
|
public:
|
2020-04-08 10:21:35 +01:00
|
|
|
explicit Semaphore(s32 count, s32 max_count) {
|
|
|
|
InitializeSemaphore(std::addressof(this->sema), count, max_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
~Semaphore() { FinalizeSemaphore(std::addressof(this->sema)); }
|
|
|
|
|
|
|
|
void Acquire() {
|
|
|
|
return os::AcquireSemaphore(std::addressof(this->sema));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TryAcquire() {
|
|
|
|
return os::TryAcquireSemaphore(std::addressof(this->sema));
|
|
|
|
}
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2020-04-08 10:21:35 +01:00
|
|
|
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);
|
|
|
|
}
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2020-04-08 10:21:35 +01:00
|
|
|
s32 GetCurrentCount() const {
|
|
|
|
return os::GetCurrentSemaphoreCount(std::addressof(this->sema));
|
|
|
|
}
|
|
|
|
|
|
|
|
operator SemaphoreType &() {
|
|
|
|
return this->sema;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator const SemaphoreType &() const {
|
|
|
|
return this->sema;
|
|
|
|
}
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2020-04-08 10:21:35 +01:00
|
|
|
SemaphoreType *GetBase() {
|
|
|
|
return std::addressof(this->sema);
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|