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.

103 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. intrlk.c
  5. Abstract:
  6. This module contains code to test the generation of code for interlocked
  7. intrinsics.
  8. Author:
  9. David N. Cutler (davec) 15-Feb-2001
  10. Environment:
  11. User mode.
  12. Revision History:
  13. None.
  14. --*/
  15. #include <ntos.h>
  16. //
  17. // Main program.
  18. //
  19. void
  20. test (
  21. void
  22. )
  23. {
  24. LONG Var1;
  25. LONG Cmp1;
  26. LONG64 Var2;
  27. LONG64 Cmp2;
  28. PVOID Ptr1;
  29. PVOID Ptr2;
  30. Cmp1 = InterlockedAnd(&Var1, 4);
  31. InterlockedAnd(&Cmp1, 4);
  32. Cmp1 = InterlockedOr(&Var1, 8);
  33. InterlockedOr(&Cmp1, 8);
  34. Cmp1 = InterlockedXor(&Var1, 16);
  35. InterlockedXor(&Cmp1, 16);
  36. Cmp2 = InterlockedAnd64(&Var2, 4);
  37. InterlockedAnd64(&Cmp2, 4);
  38. Cmp2 = InterlockedOr64(&Var2, 8);
  39. InterlockedOr64(&Cmp2, 8);
  40. Cmp2 = InterlockedXor64(&Var2, 16);
  41. InterlockedXor64(&Cmp2, 16);
  42. Cmp1 = InterlockedIncrement(&Var1);
  43. InterlockedIncrement(&Cmp1);
  44. Cmp1 = InterlockedDecrement(&Var1);
  45. InterlockedDecrement(&Cmp1);
  46. Cmp2 = InterlockedIncrement64(&Var2);
  47. InterlockedIncrement64(&Cmp2);
  48. Cmp2 = InterlockedDecrement64(&Var2);
  49. InterlockedDecrement64(&Var2);
  50. Cmp1 = InterlockedExchange(&Var1, 4);
  51. InterlockedExchange(&Cmp1, 8);
  52. Cmp2 = InterlockedExchange64(&Var2, 4);
  53. InterlockedExchange64(&Cmp2, 8);
  54. Cmp1 = InterlockedExchangeAdd(&Var1, 4);
  55. InterlockedExchangeAdd(&Cmp1, 8);
  56. Cmp2 = InterlockedExchangeAdd64(&Var2, 4);
  57. InterlockedExchangeAdd64(&Cmp2, 8);
  58. Cmp1 = InterlockedCompareExchange(&Var1, 4, Cmp1);
  59. InterlockedCompareExchange(&Cmp1, 8, Var1);
  60. Cmp2 = InterlockedCompareExchange64(&Var2, 4, Cmp2);
  61. InterlockedCompareExchange64(&Cmp2, 8, Var2);
  62. Ptr1 = InterlockedExchangePointer(&Ptr2, (PVOID)4);
  63. InterlockedExchangePointer(&Ptr1, Ptr2);
  64. Ptr1 = InterlockedCompareExchangePointer(&Ptr2, (PVOID)4, Ptr1);
  65. InterlockedCompareExchangePointer(&Ptr2, (PVOID)8, Ptr1);
  66. return;
  67. }