日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

optee中mutex的实现方式

發布時間:2025/3/21 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 optee中mutex的实现方式 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

快速鏈接:
.
👉👉👉 個人博客筆記導讀目錄(全部) 👈👈👈


相關推薦:
optee中spinlock的實現原理詳解


說明: 在默認的情況下,本文講述的是armv8 aarch64體系,optee 3.12.0代碼

在optee中,mutex的實現方式是依賴REE測的completion完成量的,具體流程圖如下所示:

相關代碼:

static void __mutex_lock(struct mutex *m, const char *fname, int lineno) {assert_have_no_spinlock();assert(thread_get_id_may_fail() != THREAD_ID_INVALID);assert(thread_is_in_normal_mode());mutex_lock_check(m);while (true) {uint32_t old_itr_status;bool can_lock;struct wait_queue_elem wqe;/** If the mutex is locked we need to initialize the wqe* before releasing the spinlock to guarantee that we don't* miss the wakeup from mutex_unlock().** If the mutex is unlocked we don't need to use the wqe at* all.*/old_itr_status = cpu_spin_lock_xsave(&m->spin_lock);can_lock = !m->state;if (!can_lock) {wq_wait_init(&m->wq, &wqe, false /* wait_read */);} else {m->state = -1; /* write locked */}cpu_spin_unlock_xrestore(&m->spin_lock, old_itr_status);if (!can_lock) {/** Someone else is holding the lock, wait in normal* world for the lock to become available.*/wq_wait_final(&m->wq, &wqe, m, fname, lineno);} elsereturn;} } static void __mutex_unlock(struct mutex *m, const char *fname, int lineno) {uint32_t old_itr_status;assert_have_no_spinlock();assert(thread_get_id_may_fail() != THREAD_ID_INVALID);mutex_unlock_check(m);old_itr_status = cpu_spin_lock_xsave(&m->spin_lock);if (!m->state)panic();m->state = 0;cpu_spin_unlock_xrestore(&m->spin_lock, old_itr_status);wq_wake_next(&m->wq, m, fname, lineno); }

總結

以上是生活随笔為你收集整理的optee中mutex的实现方式的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。