{"id":2245,"date":"2014-04-27T06:41:09","date_gmt":"2014-04-27T06:41:09","guid":{"rendered":"http:\/\/blog.bachi.net\/?p=2245"},"modified":"2014-05-08T12:17:21","modified_gmt":"2014-05-08T12:17:21","slug":"embedded-implementation-of-mutexes-and-semaphores","status":"publish","type":"post","link":"https:\/\/blog.bachi.net\/?p=2245","title":{"rendered":"Embedded Implementation of Mutexes and Semaphores"},"content":{"rendered":"<p><a href=\"http:\/\/www.barrgroup.com\/Embedded-Systems\/How-To\/RTOS-Mutex-Semaphore\">Mutexes and Semaphores Demystified<\/a><br \/>\n<a href=\"http:\/\/www.e-reading.ws\/book.php?book=129272\">Programming Embedded Systems in C and C++<\/a><\/p>\n<h3>ChibiOS\/RT<\/h3>\n<p><a href=\"http:\/\/www.chibios.org\/dokuwiki\/doku.php?id=chibios:articles:semaphores_mutexes\">Counting Semaphores, Binary Semaphores and Mutexes explained<\/a><br \/>\n<a href=\"http:\/\/www.chibios.org\/dokuwiki\/doku.php?id=chibios:guides:mutual_exclusion_guide\">Mutual Exclusion guide<\/a><\/p>\n<h4>System Locks<\/h4>\n<p>This is the lowest level mechanism, the system is locked by invoking the chSysLock() API and then unlocked by invoking chSysUnlock(). The implementation is architecture dependent but it is guaranteed to, at least, disable the interrupt sources with hardware priority below or equal the kernel level.<\/p>\n<h4>Mutexes<\/h4>\n<p>The mutexes are the mechanism intended as the most general solution for Mutual Exclusion.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\/**\r\n* @brief Locks the specified mutex.\r\n* @post The mutex is locked and inserted in the per-thread stack of owned\r\n* mutexes.\r\n*\r\n* @param&#x5B;in] mp pointer to the @p Mutex structure\r\n*\r\n* @api\r\n*\/\r\nvoid chMtxLock(Mutex *mp) {\r\n\r\n  chSysLock();\r\n\r\n  chMtxLockS(mp);\r\n\r\n  chSysUnlock();\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Mutexes and Semaphores Demystified Programming Embedded Systems in C and C++ ChibiOS\/RT Counting Semaphores, Binary Semaphores and Mutexes explained Mutual Exclusion guide System Locks This is the lowest level mechanism, the system is locked by invoking the chSysLock() API and then unlocked by invoking chSysUnlock(). The implementation is architecture dependent but it is guaranteed to, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2245","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/2245","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2245"}],"version-history":[{"count":4,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/2245\/revisions"}],"predecessor-version":[{"id":2310,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/2245\/revisions\/2310"}],"wp:attachment":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}