phys.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* $Id$ */
  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_BIT 01
  11. #ifdef STORE
  12. #define STORE_BIT 02
  13. #define BITS (FREE_BIT|STORE_BIT)
  14. #else
  15. #define BITS (FREE_BIT)
  16. #endif
  17. #define __bits(ml) ((int)((size_type)_phys_prev_of(ml) & BITS))
  18. #define __free_of(ml) ((int)((size_type)_phys_prev_of(ml) & FREE_BIT))
  19. #define __phys_prev_of(ml) ((mallink *)((size_type)_phys_prev_of(ml) & ~BITS))
  20. #define prev_size_of(ml) ((char *)(ml) - \
  21. (char *)__phys_prev_of(ml) - \
  22. mallink_size() \
  23. )
  24. #define set_phys_prev(ml,e) \
  25. (_phys_prev_of(ml) = (mallink *) ((char *)e + __bits(ml)))
  26. #ifdef CHECK
  27. public Error();
  28. #define phys_prev_of(ml) (mallink *) \
  29. (first_mallink(ml) ? \
  30. (char *)Error("phys_prev_of first_mallink %lx", "somewhere", (long)ml) : \
  31. (char *)__phys_prev_of(ml) \
  32. )
  33. #else /* ndef CHECK */
  34. #define phys_prev_of(ml) __phys_prev_of(ml)
  35. #endif /* CHECK */
  36. #define first_mallink(ml) (int) (__phys_prev_of(ml) == 0)
  37. #define last_mallink(ml) (int) ((ml) == ml_last)
  38. /* There is an ambiguity in the semantics of phys_next_of: sometimes
  39. one wants it to return MAL_NULL if there is no next chunk, at
  40. other times one wants the address of the virtual chunk at the
  41. end of memory. The present version returns the address of the
  42. (virtual) chunk and relies on the user to test last_mallink(ml)
  43. first.
  44. */
  45. #define size_of(ml) (_this_size_of(ml) - mallink_size())
  46. #define set_phys_next(ml,e) \
  47. (_this_size_of(ml) = (size_type)((char *)(e) - (char *)(ml)))
  48. #define phys_next_of(ml) (mallink *) ((char *)(ml) + _this_size_of(ml))
  49. #define set_free(ml,e) \
  50. (_phys_prev_of(ml) = (mallink *) \
  51. ((e) ? (size_type) _phys_prev_of(ml) | FREE_BIT : \
  52. (size_type) _phys_prev_of(ml) & ~FREE_BIT))
  53. #define free_of(ml) (__free_of(ml))
  54. #define coalesce_forw(ml,nxt) ( unlink_free_chunk(nxt), \
  55. combine_chunks((ml), (nxt)))
  56. #define coalesce_backw(ml,prv) ( unlink_free_chunk(prv), \
  57. stopped_working_on(ml), \
  58. combine_chunks((prv), (ml)), \
  59. started_working_on(prv))
  60. #ifdef CHECK
  61. #define set_print(ml,e) (_print_of(ml) = (e))
  62. #define print_of(ml) (_print_of(ml))
  63. #endif /* CHECK */
  64. public truncate(), combine_chunks();
  65. public mallink *create_chunk();