page_cache.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: page_cache.h /main/3 1996/06/11 17:44:27 cde-hal $ */
  24. #ifndef _page_cache_h
  25. #define _page_cache_h 1
  26. class page;
  27. class page_storage;
  28. #define MMDB_CACHED_PAGES 100
  29. #define MIN_MMDB_CACHED_PAGES 10
  30. #include "dstr/bset.h"
  31. class page_cache_local_part
  32. {
  33. protected:
  34. int f_num_cached_pages ; // number of cached pages
  35. heap f_free_space; // a heap recording free
  36. // space on each page
  37. bset f_page_pool_index; // index to pages in the pool
  38. int f_current_page_num;
  39. page* f_current_page_ptr;
  40. public:
  41. page_cache_local_part(unsigned int exp_cached_page);
  42. virtual ~page_cache_local_part();
  43. // init the heap
  44. Boolean init_heap(page_storage*);
  45. Boolean quit_heap(page_storage*);
  46. // does the cache hold page 'page_num'?
  47. page* in_cache(page_storage* st, int page_num);
  48. // get a non-empty page
  49. fbytes_t* find_host_page(page_storage*, Boolean& new_page, int len = 0);
  50. void adjust_heap(fbytes_t* v, Boolean new_page);
  51. friend class page_cache_global_part ;
  52. };
  53. class lru;
  54. class page_cache_global_part
  55. {
  56. public:
  57. //////////////////////////////////////////////////////////////////////
  58. // The default value (0) triggers the constructor to
  59. // search for the value in the shell variable MMDB_CACHED_PAGES.
  60. // If the varialble is undefind, the value set by const MMDB_CACHED_PAGES
  61. // will be used.
  62. //////////////////////////////////////////////////////////////////////
  63. page_cache_global_part(unsigned int total_allowed_pages = 0);
  64. virtual ~page_cache_global_part() ;
  65. void remove_pages(page_storage* st);
  66. // return a free page frame from cache
  67. page* load_new_page(page_storage*, int page_num, Boolean byteOrder);
  68. ostream& print_cached_pages(ostream&); // show cached pages.
  69. friend class page_cache_local_part;
  70. friend class page_storage;
  71. friend void remove_from_global_cache(const void*);
  72. protected:
  73. unsigned int f_total_allowed_pages;
  74. lru f_replace_policy;
  75. };
  76. #endif