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.

67 lines
1.3 KiB

  1. /*
  2. * A T O M C A C H E . C P P
  3. *
  4. * atom cache
  5. *
  6. * Copyright 1986-1997 Microsoft Corporation, All Rights Reserved
  7. */
  8. #include "_xmllib.h"
  9. // CXAtomCache::GetCachedAtom ------------------------------------------------
  10. //
  11. SCODE
  12. CXAtomCache::ScGetCachedAtom (CRCWszN& key, LPCWSTR* pwszAtom)
  13. {
  14. LPCWSTR wszCommitted;
  15. LPCWSTR* pwsz;
  16. SCODE sc = S_OK;
  17. // First look to see if it is already there.
  18. //
  19. {
  20. CSynchronizedReadBlock srb(m_lock);
  21. pwsz = m_cache.Lookup (key);
  22. }
  23. // If it wasn't there, do our best to add it
  24. //
  25. if (NULL == pwsz)
  26. {
  27. CSynchronizedWriteBlock swb(m_lock);
  28. // There is a small window where it could
  29. // have shown up, so do a second quick peek
  30. //
  31. pwsz = m_cache.Lookup (key);
  32. if (NULL == pwsz)
  33. {
  34. // Commit the string to perm. storage
  35. //
  36. wszCommitted = m_csb.Append(key.m_cch*sizeof(WCHAR), key.m_pwsz);
  37. if (NULL == wszCommitted)
  38. {
  39. sc = E_OUTOFMEMORY;
  40. goto ret;
  41. }
  42. // Add the atom to the cache, but before it
  43. // gets added, swap out the key's string pointer
  44. // to the committed version.
  45. //
  46. key.m_pwsz = wszCommitted;
  47. m_cache.FAdd (key, wszCommitted);
  48. // Setup for the return
  49. //
  50. pwsz = &wszCommitted;
  51. }
  52. }
  53. Assert (pwsz);
  54. Assert (pwszAtom);
  55. *pwszAtom = *pwsz;
  56. ret:
  57. return sc;
  58. }