Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.8 KiB

  1. /*
  2. * A T O M C A C H E . H
  3. *
  4. * atom cache
  5. *
  6. * Copyright 1986-1997 Microsoft Corporation, All Rights Reserved
  7. */
  8. #ifndef _EX_ATOMCACHE_H_
  9. #define _EX_ATOMCACHE_H_
  10. #include <crc.h>
  11. #include <crcsz.h>
  12. #include <singlton.h>
  13. #include <ex\buffer.h>
  14. #include <ex\synchro.h>
  15. class CXAtomCache : public OnDemandGlobal<CXAtomCache>
  16. {
  17. // Friend declarations required by Singleton template
  18. //
  19. friend class Singleton<CXAtomCache>;
  20. friend class RefCountedGlobal<CXAtomCache>;
  21. enum { CACHESIZE_START = 53 };
  22. // Cache of atoms
  23. //
  24. typedef CCache<CRCWszN, LPCWSTR> CSzCache;
  25. CSzCache m_cache;
  26. CMRWLock m_lock;
  27. // String data storage area.
  28. //
  29. ChainedStringBuffer<WCHAR> m_csb;
  30. // GetCachedAtom()
  31. //
  32. SCODE ScGetCachedAtom (CRCWszN& key, LPCWSTR* pwszAtom);
  33. // Declared private to ensure that arbitrary instances
  34. // of this class cannot be created. The Singleton
  35. // template (declared as a friend above) controls
  36. // the sole instance of this class.
  37. //
  38. CXAtomCache() : m_cache(CACHESIZE_START)
  39. {
  40. }
  41. // Initialize lock and cache
  42. //
  43. BOOL FInit()
  44. {
  45. // Initialize the MRWLock and the cache
  46. //
  47. return m_lock.FInitialize() && m_cache.FInit();
  48. }
  49. // non-implmented
  50. //
  51. CXAtomCache& operator=(const CXAtomCache&);
  52. CXAtomCache(const CXAtomCache&);
  53. public:
  54. using OnDemandGlobal<CXAtomCache>::FInitOnFirstUse;
  55. using OnDemandGlobal<CXAtomCache>::DeinitIfUsed;
  56. // CacheAtom()
  57. //
  58. static SCODE ScCacheAtom (LPCWSTR* pwszAtom, UINT cch)
  59. {
  60. Assert (pwszAtom);
  61. Assert (*pwszAtom);
  62. if (!FInitOnFirstUse())
  63. return E_OUTOFMEMORY;
  64. // Retrieve the string from the cache
  65. //
  66. CRCWszN key(*pwszAtom, cch);
  67. return Instance().ScGetCachedAtom (key, pwszAtom);
  68. }
  69. };
  70. #endif // _EX_ATOMCACHE_H_