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
|
|
|
|
2015-07-15 05:44:45 +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 {
|
|
|
|
|
2015-07-25 16:43:25 +00:00
|
|
|
struct X_KSEMAPHORE {
|
2015-06-13 03:43:37 +00:00
|
|
|
X_DISPATCH_HEADER header;
|
2015-07-25 16:43:25 +00:00
|
|
|
xe::be<uint32_t> limit;
|
2015-06-13 02:31:00 +00:00
|
|
|
};
|
2018-11-25 17:06:57 +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:
|
2015-11-13 01:01:55 +00:00
|
|
|
static const Type kType = kTypeSemaphore;
|
|
|
|
|
2015-08-08 04:29:03 +00:00
|
|
|
explicit XSemaphore(KernelState* kernel_state);
|
2015-07-15 05:44:45 +00:00
|
|
|
~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);
|
|
|
|
|
2015-12-18 00:32:45 +00:00
|
|
|
protected:
|
|
|
|
xe::threading::WaitHandle* GetWaitHandle() override {
|
|
|
|
return semaphore_.get();
|
|
|
|
}
|
|
|
|
|
2014-08-17 20:13:03 +00:00
|
|
|
private:
|
2015-07-15 05:44:45 +00:00
|
|
|
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_
|