CK_EPOCH_RECYCLE(3)

πŸ“¦
version 0.7.2 Β· 2 versions
, in alpine 3.24, debian trixie, epel 10, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– CK_EPOCH_RECYCLE(3) πŸ’–

okay bestie, welcome to the Concurrency Kit manual, section 3, page ck_epoch_recycle ✨ this one lives in libck (that's the library you link with -lck, mwah 🫢)


🌸 NAME 🌸

ck_epoch_recycle β€” hand back an epoch record that's just sitting there unused so you can use it, no cap πŸ’…


πŸŽ€ LIBRARY πŸŽ€

Concurrency Kit (libck, link it with -lck) 🧚


✨ SYNOPSIS ✨

#include <ck_epoch.h>

ck_epoch_record_t *
ck_epoch_recycle(ck_epoch_t *epoch);

like. look at that. one include, one function call. iconic behavior honestly πŸ‘‘


πŸ’œ DESCRIPTION πŸ’œ

so, the ck_epoch_recycle(3) function attempts to return an unused epoch record object for the caller to use πŸ¦‹

and where do these free little records come from? they were associated with previous calls to the ck_epoch_unregister(3) function β€” so basically when someone dipped out of the epoch system, their record got parked, and this function is you pulling up like "hey is anyone sitting here πŸ‘€" 😌


🌈 EXAMPLE 🌈

here's the whole vibe, bestie:

#include <ck_epoch.h>
#include <stdlib.h>

/*
 * epoch was previously initialized with ck_epoch_init.
 */
ck_epoch_t *epoch;

void
function(void)
{
        ck_epoch_record_t *record;

        record = ck_epoch_recycle(&epoch);
        if (record == NULL) {
                record = malloc(sizeof *record);
                if (record == NULL)
                        return;

                ck_epoch_register(&epoch, record, NULL);
        }

        /*
         * After we are done, we will unregister the record so it
         * can be used by other new participants in the epoch system
         * provided by the object pointed to by "epoch".
         */
        ck_epoch_unregister(&epoch, record);
        return;
}

the way this works: you try to recycle, and if you get NULL back (😭) you just malloc your own and ck_epoch_register(&epoch, record, NULL) it into existence. then when you're done you ck_epoch_unregister(&epoch, record) so somebody else can snatch it up later. the circle of life fr fr πŸ“


🫢 RETURN VALUES 🫢

this function returns a pointer to a ck_epoch_record_t object ⭐

but if no unused record was found to be associated with the object pointed to by epoch? then it just returns NULL and you're on your own bestie πŸ’€


πŸ‘‘ ERRORS πŸ‘‘

Behavior is undefined if the object pointed to by epoch is not a valid epoch object. not "a little weird", not "probably fine" β€” undefined. do not pass it garbage, i am begging πŸ™ˆ

πŸ¦‹ SEE ALSO πŸ¦‹

more lore available at http://concurrencykit.org/ πŸ’–


okay that's the whole page, you ate it, go recycle some records πŸ’… this one was dated September 2, 2012 and filed under CK_EPOCH_RECYCLE(3) β€” mwah, ily, bye πŸŽ€πŸŒΈβœ¨

πŸ“¦ where this page comes from