CK_COHORT_TRYLOCK_PROTOTYPE(3)

πŸ’– NAME πŸ’–

CK_COHORT_TRYLOCK_PROTOTYPE β€” bestie, this is the macro that lets you define your very own cohort type with specified lock types, and it comes with trylock energy baked in. ✨


πŸ“š LIBRARY πŸ“š

Concurrency Kit β€” that's libck, and you link it with -lck. 🫢


✨ SYNOPSIS ✨

#include <ck_cohort.h>

CK_COHORT_TRYLOCK_PROTOTYPE(COHORT_NAME cohort_name,
    LOCK_FXN global_lock_method, LOCK_FXN global_unlock_method,
    BOOL_LOCK_FXN global_locked_method,
    BOOL_LOCK_FXN global_trylock_method, LOCK_FXN local_lock_method,
    LOCK_FXN local_unlock_method, BOOL_LOCK_FXN local_locked_method,
    BOOL_LOCK_FXN local_trylock_method);

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so here's the tea: ck_cohort.h does not define any cohort types for you. Not a single one. It's giving "you're the main character, you build it." πŸ’…

Instead, you β€” yes you, bestie β€” have to use the CK_COHORT_PROTOTYPE or CK_COHORT_TRYLOCK_PROTOTYPE macros to define whatever types you wanna use. And you specifically reach for CK_COHORT_TRYLOCK_PROTOTYPE when you want your cohort type to have support for trylock operations. No cap.

So CK_COHORT_TRYLOCK_PROTOTYPE takes these arguments, and yes, we're going through every single one because they all matter:

  • cohort_name β€” the identifier for this cohort type. You're gonna have to pass this bad boy to every other CK_COHORT macro, so remember its name like it's your bestie's birthday. πŸŽ‚
  • global_lock_method β€” the method that should be called to acquire the global lock. Grabby hands. πŸ™Œ
  • global_unlock_method β€” the method that should be called to relinquish the global lock. Let it gooo. πŸ•ŠοΈ
  • global_locked_method β€” this method should return true iff the global lock is acquired by a thread. Simple as that.
  • global_trylock_method β€” the method that should be called to try to acquire the global lock. Key detail: it should not block, and it returns true iff the lock was successfully acquired. It's the "hey are you free? no? cool cool cool" of locking. 😌
  • local_lock_method β€” the method that should be called to acquire the local lock. πŸŽ€
  • local_unlock_method β€” the method that should be called to relinquish the local lock. Bye boo. πŸ‘‹
  • global_locked_method β€” this method should return true iff the global lock is acquired by a thread. (Yes, it literally says global_locked_method again right here in the source, I'm just the messenger, reporting the lore exactly as it was handed to me. πŸ’€)
  • local_trylock_method β€” the method that should be called to try to acquire the local lock. Same rules as the global one: it should not block, and it returns true iff the lock was successfully acquired. πŸ”₯

🌸 Declaring an instance 🌸

Once you've defined your type, instances of the defined cohort type can be declared like this:

CK_COHORT_INSTANCE(cohort_name) cohort;

Look at that. Gorgeous. Iconic. Slay. πŸ‘‘


🌈 SEE ALSO 🌈

Go read these next, bestie, they're all in the fam:

Additional information available at http://concurrencykit.org/ β€” go be nosy, you deserve it. πŸ’œ


And that's the whole page, bestie! This one's from the <strong>Concurrency Kit (libck)</strong> era, dated <strong>March 9, 2013.</strong>, and it's filed under <strong>CK_COHORT_TRYLOCK_PROTOTYPE(3)</strong>. Periodt. πŸ’…βœ¨

πŸ“¦ where this page comes from