phys.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* $Header$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. /* Algorithms to manipulate the doubly-linked list of physical
  7. chunks.
  8. */
  9. publicdata mallink *ml_last;
  10. #define __free_of(ml) ((size_type)_phys_prev_of(ml) & 01)
  11. #define __phys_prev_of(ml) (mallink *)((size_type)_phys_prev_of(ml) & ~01)
  12. #define prev_size_of(ml) ((char *)(ml) - \
  13. (char *)__phys_prev_of(ml) - \
  14. mallink_size() \
  15. )
  16. #define set_phys_prev(ml,e) \
  17. (_phys_prev_of(ml) = (mallink *) ((char *)e + __free_of(ml)))
  18. #ifdef CHECK
  19. public Error();
  20. #define phys_prev_of(ml) (mallink *) \
  21. (first_mallink(ml) ? \
  22. (char *)Error("phys_prev_of first_mallink %ld", "somewhere", ml) : \
  23. (char *)__phys_prev_of(ml) \
  24. )
  25. #else ndef CHECK
  26. #define phys_prev_of(ml) __phys_prev_of(ml)
  27. #endif CHECK
  28. #define first_mallink(ml) (int) (__phys_prev_of(ml) == 0)
  29. #define last_mallink(ml) (int) ((ml) == ml_last)
  30. /* There is an ambiguity in the semantics of phys_next_of: sometimes
  31. one wants it to return MAL_NULL if there is no next chunk, at
  32. other times one wants the address of the virtual chunk at the
  33. end of memory. The present version returns the address of the
  34. (virtual) chunk and relies on the user to test last_mallink(ml)
  35. first.
  36. */
  37. #define size_of(ml) (_this_size_of(ml) - mallink_size())
  38. #define set_phys_next(ml,e) \
  39. (_this_size_of(ml) = (unsigned int)((char *)(e) - (char *)(ml)))
  40. #define phys_next_of(ml) (mallink *) ((char *)(ml) + _this_size_of(ml))
  41. #define set_free(ml,e) \
  42. (_phys_prev_of(ml) = (mallink *) \
  43. ((e) ? (size_type) _phys_prev_of(ml) | 01 : \
  44. (size_type) _phys_prev_of(ml) & ~01))
  45. #define free_of(ml) (__free_of(ml))
  46. #define coalesce_forw(ml,nxt) ( unlink_free_chunk(nxt), \
  47. combine_chunks((ml), (nxt)))
  48. #define coalesce_backw(ml,prv) ( unlink_free_chunk(prv), \
  49. stopped_working_on(ml), \
  50. combine_chunks((prv), (ml)), \
  51. started_working_on(prv))
  52. #ifdef CHECK
  53. #define set_print(ml,e) (_print_of(ml) = (e))
  54. #define print_of(ml) (_print_of(ml))
  55. #endif CHECK
  56. public truncate(), combine_chunks();
  57. public mallink *create_chunk();