X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/0f73e6cc9945f9b4a074bb62b9708d1751fa3723..8c06c883e7b13c115d5ff207f79d4b68fccd5ad6:/lunaix-os/kernel/kprint/kp_records.c diff --git a/lunaix-os/kernel/kprint/kp_records.c b/lunaix-os/kernel/kprint/kp_records.c new file mode 100644 index 0000000..d323bc1 --- /dev/null +++ b/lunaix-os/kernel/kprint/kp_records.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include + +#include "kp_records.h" + +struct kp_records* +kp_rec_create(int max_recs) +{ + struct kp_records* recs = (struct kp_records*)valloc(KP_RECS_SIZE); + + *recs = (struct kp_records){ .max_recs = max_recs, + .log_lvl = KLOG_DEBUG, + .kp_ent_wp = &recs->kp_ents.ents }; + + llist_init_head(&recs->kp_ents.ents); + + return recs; +} + +static inline int +kp_recs_full(struct kp_records* recs) +{ + return recs->cur_recs >= recs->max_recs; +} + +void +kp_rec_put(struct kp_records* recs, int lvl, char* content, size_t len) +{ + assert(len < 256); + + struct kp_entry* ent; + if (!kp_recs_full(recs)) { + assert(recs->kp_ent_wp == &recs->kp_ents.ents); + + ent = (struct kp_entry*)vzalloc(KP_ENT_SIZE); + llist_append(&recs->kp_ents.ents, &ent->ents); + recs->cur_recs++; + } else { + recs->kp_ent_wp = recs->kp_ent_wp->next; + ent = container_of(recs->kp_ent_wp, struct kp_entry, ents); + } + + vfree_safe(ent->content); + + char* _content = valloc(len); + memcpy(_content, content, len); + + ent->lvl = lvl; + ent->content = _content; + ent->time = clock_systime(); +} \ No newline at end of file