MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / UnLock

Method UnLock

src/task/mutex.cpp:74–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74auto Mutex::UnLock() -> Expected<void> {
75 auto current_task = TaskManagerSingleton::instance().GetCurrentTask();
76 if (current_task == nullptr) {
77 klog::Err("Mutex::UnLock: Cannot unlock mutex '{}' outside task context",
78 name);
79 return std::unexpected(Error{ErrorCode::kMutexNoTaskContext});
80 }
81
82 Pid current_pid = current_task->pid;
83
84 if (!IsLockedByCurrentTask()) {
85 klog::Warn(
86 "Mutex::UnLock: Task {} tried to unlock mutex '{}' it doesn't own",
87 current_pid, name);
88 return std::unexpected(Error{ErrorCode::kMutexNotOwned});
89 }
90
91 owner_.store(std::numeric_limits<Pid>::max(), std::memory_order_release);
92 locked_.store(false, std::memory_order_release);
93
94 klog::Debug("Mutex::UnLock: Task {} released mutex '{}'", current_pid, name);
95
96 TaskManagerSingleton::instance().WakeupOne(resource_id_);
97
98 return {};
99}
100
101auto Mutex::TryLock() -> Expected<void> {
102 auto current_task = TaskManagerSingleton::instance().GetCurrentTask();

Callers 15

ScheduleMethod · 0.45
UnlockMethod · 0.45
test_basic_lockFunction · 0.45
test_recursive_lockFunction · 0.45
test_interrupt_restoreFunction · 0.45
spinlock_smp_testFunction · 0.45
spinlock_smp_buffer_testFunction · 0.45
spinlock_smp_string_testFunction · 0.45
trylock_holderFunction · 0.45
test_mutex_trylockFunction · 0.45
contention_workerFunction · 0.45

Calls 5

ErrFunction · 0.85
WarnFunction · 0.85
DebugFunction · 0.85
GetCurrentTaskMethod · 0.80
WakeupOneMethod · 0.80

Tested by 15

test_basic_lockFunction · 0.36
test_recursive_lockFunction · 0.36
test_interrupt_restoreFunction · 0.36
spinlock_smp_testFunction · 0.36
spinlock_smp_buffer_testFunction · 0.36
spinlock_smp_string_testFunction · 0.36
trylock_holderFunction · 0.36
test_mutex_trylockFunction · 0.36
contention_workerFunction · 0.36
ordering_firstFunction · 0.36
ordering_secondFunction · 0.36