MCPcopy Create free account
hub / github.com/RPCSX/rpcsx / do_lock_normal

Function do_lock_normal

kernel/orbis/src/umtx.cpp:235–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

233 }
234}
235static ErrorCode do_lock_normal(Thread *thread, ptr<umutex> m, uint flags,
236 std::uint64_t ut, umutex_lock_mode mode) {
237 ORBIS_LOG_TRACE(__FUNCTION__, thread->tid, m, flags, ut, mode);
238
239 auto [chain, key, lock] = umtxStorage->getUmtxChain1(thread, flags, m);
240 ErrorCode error = {};
241 while (true) {
242 int owner = m->owner.load(std::memory_order_acquire);
243 if (mode == umutex_lock_mode::wait) {
244 if (owner == kUmutexUnowned || owner == kUmutexContested)
245 return {};
246 } else {
247 owner = kUmutexUnowned;
248 if (m->owner.compare_exchange_strong(owner, thread->tid))
249 return {};
250 if (owner == kUmutexContested) {
251 if (m->owner.compare_exchange_strong(owner,
252 thread->tid | kUmutexContested))
253 return {};
254 continue;
255 }
256 }
257
258 if ((flags & kUmutexErrorCheck) != 0 &&
259 (owner & ~kUmutexContested) == thread->tid)
260 return ErrorCode::DEADLK;
261
262 if (mode == umutex_lock_mode::try_)
263 return ErrorCode::BUSY;
264
265 if (error != ErrorCode{})
266 return error;
267
268 auto node = chain.enqueue(key, thread);
269 if (m->owner.compare_exchange_strong(owner, owner | kUmutexContested)) {
270 {
271 orbis::scoped_unblock unblock;
272 error = orbis::toErrorCode(node->second.cv.wait(chain.mtx, ut));
273 }
274 if (error == ErrorCode{} && node->second.thr == thread &&
275 m->owner.load() != 0) {
276 error = ErrorCode::TIMEDOUT;
277 }
278 }
279 if (node->second.thr == thread)
280 chain.erase(node);
281 }
282}
283static ErrorCode do_lock_pi(Thread *thread, ptr<umutex> m, uint flags,
284 std::uint64_t ut, umutex_lock_mode mode) {
285 // ORBIS_LOG_TODO(__FUNCTION__, m, flags, ut, mode);

Callers 5

do_lock_piFunction · 0.85
do_lock_ppFunction · 0.85
umtx_trylock_umutexMethod · 0.85
umtx_lock_umutexMethod · 0.85
umtx_wait_umutexMethod · 0.85

Calls 6

toErrorCodeFunction · 0.85
getUmtxChain1Method · 0.80
loadMethod · 0.45
enqueueMethod · 0.45
waitMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected