summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorGravatar Subv2014-12-03 18:49:51 -0500
committerGravatar Subv2014-12-13 13:40:09 -0500
commit82c84883a5d10bd6c9a3516fe16b996c5333360e (patch)
tree79016ba73405e93affa092432c8c0b86bd917aac /src/core/hle/kernel
parentMerge pull request #274 from lioncash/kernel (diff)
downloadyuzu-82c84883a5d10bd6c9a3516fe16b996c5333360e.tar.gz
yuzu-82c84883a5d10bd6c9a3516fe16b996c5333360e.tar.xz
yuzu-82c84883a5d10bd6c9a3516fe16b996c5333360e.zip
SVC: Implemented svcCreateSemaphore
ToDo: Implement svcReleaseSemaphore * Some testing against hardware needed
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/semaphore.cpp76
-rw-r--r--src/core/hle/kernel/semaphore.h22
2 files changed, 98 insertions, 0 deletions
diff --git a/src/core/hle/kernel/semaphore.cpp b/src/core/hle/kernel/semaphore.cpp
new file mode 100644
index 000000000..73ffbe3cf
--- /dev/null
+++ b/src/core/hle/kernel/semaphore.cpp
@@ -0,0 +1,76 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2+
3// Refer to the license.txt file included.
4
5#include <map>
6#include <vector>
7
8#include "common/common.h"
9
10#include "core/hle/kernel/kernel.h"
11#include "core/hle/kernel/semaphore.h"
12#include "core/hle/kernel/thread.h"
13
14namespace Kernel {
15
16class Semaphore : public Object {
17public:
18 std::string GetTypeName() const override { return "Semaphore"; }
19 std::string GetName() const override { return name; }
20
21 static Kernel::HandleType GetStaticHandleType() { return Kernel::HandleType::Semaphore; }
22 Kernel::HandleType GetHandleType() const override { return Kernel::HandleType::Semaphore; }
23
24 u32 initial_count; ///< Number of reserved entries
25 u32 max_count; ///< Maximum number of simultaneous holders the semaphore can have
26 u32 current_usage; ///< Number of currently used entries in the semaphore
27 std::vector<Handle> waiting_threads; ///< Threads that are waiting for the semaphore
28 std::string name; ///< Name of semaphore (optional)
29
30 ResultVal<bool> SyncRequest() override {
31 // TODO(Subv): ImplementMe
32 return MakeResult<bool>(false);
33 }
34
35 ResultVal<bool> WaitSynchronization() override {
36 bool wait = current_usage == max_count;
37
38 if (wait) {
39 Kernel::WaitCurrentThread(WAITTYPE_SEMA, GetHandle());
40 waiting_threads.push_back(GetCurrentThreadHandle());
41 } else {
42 ++current_usage;
43 }
44
45 return MakeResult<bool>(wait);
46 }
47};
48
49////////////////////////////////////////////////////////////////////////////////////////////////////
50
51/**
52 * Creates a semaphore
53 * @param handle Reference to handle for the newly created semaphore
54 * @param initial_count initial amount of times the semaphore is held
55 * @param max_count maximum number of holders the semaphore can have
56 * @param name Optional name of semaphore
57 * @return Pointer to new Semaphore object
58 */
59Semaphore* CreateSemaphore(Handle& handle, u32 initial_count, u32 max_count, const std::string& name) {
60 Semaphore* semaphore = new Semaphore;
61 handle = Kernel::g_object_pool.Create(semaphore);
62
63 semaphore->initial_count = semaphore->current_usage = initial_count;
64 semaphore->max_count = max_count;
65 semaphore->name = name;
66
67 return semaphore;
68}
69
70Handle CreateSemaphore(u32 initial_count, u32 max_count, const std::string& name) {
71 Handle handle;
72 Semaphore* semaphore = CreateSemaphore(handle, initial_count, max_count, name);
73 return handle;
74}
75
76} // namespace
diff --git a/src/core/hle/kernel/semaphore.h b/src/core/hle/kernel/semaphore.h
new file mode 100644
index 000000000..6a686db2e
--- /dev/null
+++ b/src/core/hle/kernel/semaphore.h
@@ -0,0 +1,22 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2+
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common_types.h"
8
9#include "core/hle/kernel/kernel.h"
10
11namespace Kernel {
12
13/**
14 * Creates a semaphore
15 * @param initial_count number of reserved entries in the semaphore
16 * @param max_count maximum number of holders the semaphore can have
17 * @param name Optional name of semaphore
18 * @return Handle to newly created object
19 */
20Handle CreateSemaphore(u32 initial_count, u32 max_count, const std::string& name = "Unknown");
21
22} // namespace