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.

69 lines
2.0 KiB

  1. //--------------------------------------------------------------------
  2. // AtomicInt64 - inline
  3. // Copyright (C) Microsoft Corporation, 1999
  4. //
  5. // Created by: Louis Thomas (louisth), 10-14-99
  6. //
  7. // Inlines to do atomic int64s
  8. // Suck these into a .cpp if you need them.
  9. //
  10. // This int64 can have multiple readers
  11. // and ONE writer, NOT MULTIPLE WRITERS.
  12. //
  13. //####################################################################
  14. //--------------------------------------------------------------------
  15. struct auint64 {
  16. private:
  17. volatile DWORD m_dwHi1;
  18. volatile DWORD m_dwLo;
  19. volatile DWORD m_dwHi2;
  20. public:
  21. //----------------------------------------------------------------
  22. unsigned __int64 getValue(void) {
  23. DWORD dwHi;
  24. DWORD dwLo;
  25. do {
  26. dwHi=m_dwHi1;
  27. dwLo=m_dwLo;
  28. } while (dwHi!=m_dwHi2);
  29. return (((unsigned __int64)dwHi)<<32)+dwLo;
  30. }
  31. //----------------------------------------------------------------
  32. void setValue(unsigned __int64 qw) {
  33. m_dwHi1=(DWORD)(qw>>32);
  34. m_dwLo= (DWORD) qw;
  35. m_dwHi2=(DWORD)(qw>>32);
  36. }
  37. };
  38. //####################################################################
  39. //--------------------------------------------------------------------
  40. struct asint64 {
  41. private:
  42. volatile DWORD m_dwHi1;
  43. volatile DWORD m_dwLo;
  44. volatile DWORD m_dwHi2;
  45. public:
  46. //----------------------------------------------------------------
  47. signed __int64 getValue(void) {
  48. DWORD dwHi;
  49. DWORD dwLo;
  50. do {
  51. dwHi=m_dwHi1;
  52. dwLo=m_dwLo;
  53. } while (dwHi!=m_dwHi2);
  54. return (signed __int64)((((unsigned __int64)dwHi)<<32)+dwLo);
  55. }
  56. //----------------------------------------------------------------
  57. void setValue(signed __int64 qw) {
  58. m_dwHi1=(DWORD)(((unsigned __int64)qw)>>32);
  59. m_dwLo= (DWORD) ((unsigned __int64)qw);
  60. m_dwHi2=(DWORD)(((unsigned __int64)qw)>>32);
  61. }
  62. };