rtapi_mutex(3rtapi)
π NAME π
okay so bestie, we're reading rtapi_mutex(3rtapi) β straight out of the RTAPI manual section, three-point-r-t-a-p-i, no cap. It's the page for mutex-related functions, and honestly it's short, it's sweet, and it's giving "small but mighty" π
rtapi_mutex β mutex-related functions. that's it, that's the name. iconic.
β¨ SYNTAX β¨
bestie, here's the vibe, verbatim, do not touch:
#include <rtapi_mutex.h>
int rtapi_mutex_try(unsigned long *mutex);
int rtapi_mutex_get(unsigned long *mutex);
int rtapi_mutex_give(unsigned long *mutex);
three little functions, all of them returning int, all of them taking one pointer. slay πΈ
π«Ά ARGUMENTS π«Ά
mutexβ a pointer to the mutex. that's the whole thing. just a pointer to it. lowkey the most straightforward argument in the whole library π¦
π DESCRIPTION π
rtapi_mutex_try makes a non-blocking attempt to get the mutex. so it's like, hey, is the mutex free? If the mutex is available, it returns 0, and the mutex is no longer available β meaning you got it, congrats, it's yours now π. Otherwise, it returns a nonzero value, which is the polite Unix way of saying "nope, somebody else is holding it, try again later" π
rtapi_mutex_get blocks until the mutex is available. so it just sits there, patiently, waiting for its turn, no drama, until the mutex frees up. main character energy but make it patient β¨
rtapi_mutex_give releases a mutex acquired by rtapi_mutex_try or rtapi_mutex_get. it's the "okay bestie, I'm done, it's all yours" move. please actually call it, the mutex will not release itself and we've all seen that movie π
π₯ REALTIME CONSIDERATIONS π₯
this part is important, so listen up fr fr:
rtapi_mutex_giveandrtapi_mutex_trymay be used from non-realtime, init/cleanup, and realtime code. flexible queens, we love them πrtapi_mutex_getmay not be used from realtime code.
okay so the get thing? that one is a hard no for realtime. it blocks, and blocking in realtime code is not the vibe. do not do it. the manpage says so, I say so, everybody says so π
π RETURN VALUE π
rtapi_mutex_tryreturns0if the mutex was claimed, and nonzero otherwise. (yes, the original prose literally says "returns 0 for if the mutex was claimed" β we're keeping the wording energy, it's cute, it stays π)rtapi_mutex_getandrtapi_mutex_gifhave no return value.
not me pointing out that the original page saysrtapi_mutex_gifthere π that's a typo bestie, it meansrtapi_mutex_give, but we're reporting it exactly as written because facts are facts. iykyk.
and that's the whole page, babe. nothing hidden, nothing skipped, every last line accounted for π
signing off with the receipts: this one's from the LinuxCNC Documentation, dated 2006-10-12 β and the page is rtapi_mutex(3rtapi). go forth and lock responsibly, bestie π«Άβ¨
π¦ where this page comes from
- debian trixie: linuxcnc-uspace-dev 1:2.9.4-2+deb13u1 Β· GFDL-1.1-or-later
- ubuntu questing: linuxcnc-uspace-dev 1:2.9.4-2ubuntu2
- ubuntu resolute: linuxcnc-uspace-dev 1:2.9.4-2ubuntu4 Β· GFDL-1.1-or-later
- ubuntu stonking: linuxcnc-uspace-dev 1:2.9.4-2ubuntu4 Β· GFDL-1.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms