xenia-canary/src/xenia/kernel/xsemaphore.h

56 lines
1.6 KiB
C
Raw Normal View History

2014-01-04 21:56:38 +00:00
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
2015-09-07 01:07:52 +00:00
#ifndef XENIA_KERNEL_XSEMAPHORE_H_
#define XENIA_KERNEL_XSEMAPHORE_H_
2014-01-04 21:56:38 +00:00
#include "xenia/base/threading.h"
2015-02-01 06:49:47 +00:00
#include "xenia/kernel/xobject.h"
#include "xenia/xbox.h"
2014-01-04 21:56:38 +00:00
namespace xe {
namespace kernel {
struct X_KSEMAPHORE {
2015-06-13 03:43:37 +00:00
X_DISPATCH_HEADER header;
xe::be<uint32_t> limit;
2015-06-13 02:31:00 +00:00
};
static_assert_size(X_KSEMAPHORE, 0x14);
2015-06-13 02:31:00 +00:00
2014-01-04 21:56:38 +00:00
class XSemaphore : public XObject {
2014-08-17 20:13:03 +00:00
public:
static const Type kType = kTypeSemaphore;
2015-08-08 04:29:03 +00:00
explicit XSemaphore(KernelState* kernel_state);
~XSemaphore() override;
2014-01-04 21:56:38 +00:00
void Initialize(int32_t initial_count, int32_t maximum_count);
2015-08-08 04:29:03 +00:00
void InitializeNative(void* native_ptr, X_DISPATCH_HEADER* header);
2014-01-04 21:56:38 +00:00
int32_t ReleaseSemaphore(int32_t release_count);
2015-12-12 01:51:47 +00:00
bool Save(ByteStream* stream) override;
static object_ref<XSemaphore> Restore(KernelState* kernel_state,
ByteStream* stream);
protected:
xe::threading::WaitHandle* GetWaitHandle() override {
return semaphore_.get();
}
2014-08-17 20:13:03 +00:00
private:
std::unique_ptr<xe::threading::Semaphore> semaphore_;
2015-12-12 01:51:47 +00:00
uint32_t maximum_count_ = 0;
2014-01-04 21:56:38 +00:00
};
} // namespace kernel
} // namespace xe
2015-09-07 01:07:52 +00:00
#endif // XENIA_KERNEL_XSEMAPHORE_H_