Q_SEARCH(3)

πŸ’– NAME πŸ’–

q_search β€” bestie, this is how you go find an entry in a smolq queue πŸ”βœ¨


πŸŽ€ LIBRARY πŸŽ€

Librecast library (liblibrecast, -llibrecast) 🫢


🌸 SYNOPSIS 🌸

#include <librecast/q.h>

int  q_search(q_t *q, void *(*f)(void *), void *restrict arg);

Compile and link with -llibrecast. That's the whole vibe, no cap πŸ’…


✨ DESCRIPTION ✨

okay so q_search() goes digging through the queue q looking for an entry that matches both f and arg. like, both of them. not one or the other. both. πŸ’–

And here's the tea, bestie β€” there are no locks in here. So readers can read while we're searching, and writers can write, everyone just doing their thing at the same time, it's giving very chill πŸ¦‹

But wait. Consequence time 😭

  • If something gets read while we search, we'll still return a positive match for that item β€” even though it's literally not in the queue anymore. gone. bye. but we said yes anyway πŸ’€
  • If a writer writes, we will not notice that write. not even a little bit πŸ™ˆ
If that's a problem for your particular use-case, you're gonna need an external lock. That's the only way, fr fr πŸ”’

⭐ RETURN VALUE ⭐

The q_push() function returns 1 if found, 0 if not found. On error, -1 is returned and errno is set to indicate the error. that's it, that's the whole menu πŸŽ€


🌈 ERRORS 🌈

She can fail with any of the errors for sem_getvalue(3). go check that page, it's got the receipts πŸ‘‘


πŸ¦‹ SEE ALSO πŸ¦‹


LIBRECAST Β· 2023-07-27 Β· Q_SEARCH(3)

mwah, that's the page bestie, go forth and search responsibly πŸ’œπŸ§šβ€β™€οΈ

πŸ“¦ where this page comes from