mem_allocator.c 621 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // SPDX-License-Identifier: GPL-2.0+
  2. #include "mem_allocator.h"
  3. #include "linux/gfp.h"
  4. struct alloc_event *get_next_event(void)
  5. {
  6. struct alloc_event *e;
  7. spin_lock(&events_lock);
  8. e = list_first_entry(&events_list, struct alloc_event, head);
  9. if (e)
  10. list_del(&e->head);
  11. spin_unlock(&events_lock);
  12. return e;
  13. }
  14. int mem_allocator_f(void *data)
  15. {
  16. struct alloc_event *e;
  17. while (true) {
  18. wait_event(wq, (e = get_next_event()));
  19. if (e == NULL)
  20. continue;
  21. e->addr = kmalloc(e->size, GFP_KERNEL);
  22. arch_atomic_set(&e->solved, true);
  23. if (arch_atomic_read(&e->stop) == true)
  24. break;
  25. }
  26. do_exit(0);
  27. }