#ifndef _KERNEL_PROC_RESOURCE_H
#define _KERNEL_PROC_RESOURCE_H

#include <libk/list.h>
#include <libk/rbtree.h>
#include <libk/std.h>
#include <proc/mail.h>
#include <proc/mutex.h>
#include <sync/spin_lock.h>

#define PR_MUTEX 0
#define PR_MAIL  1

struct proc;
struct procgroup;
struct cpu;
struct reschedule_ctx;

struct proc_resource {
  int type;
  int rid;
  spin_lock_t lock;
  struct rb_node_link resource_tree_link;
  union {
    struct proc_mutex mutex;
    struct proc_mail mail;
  } u;
  struct {
    void (*cleanup) (struct proc_resource* resource, struct reschedule_ctx* rctx);
  } ops;
};

struct proc_resource* proc_find_resource (struct procgroup* procgroup, int rid);

struct proc_resource* proc_create_resource_mutex (struct procgroup* procgroup);

struct proc_resource* proc_create_resource_mail (struct procgroup* procgroup);

void proc_delete_resource (struct procgroup* procgroup, struct proc_resource* resource,
                           struct reschedule_ctx* rctx);

#endif // _KERNEL_PROC_RESOURCE_H
