예제 #1
0
 public MarkerParallelPortWriter(LogicalParallelPort lpt, bool invertBits, bool reverseBits)
 {
     Port           = lpt;
     InvertBits     = invertBits;
     ReverseBits    = reverseBits;
     _fileHandle    = new AtomicPtr(Kernel32.CreateFile($"lpt{(byte)lpt}", FileAccess.ReadWrite, FileShare.None, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero));
     _oneByteBuffer = Marshal.AllocHGlobal(1);
 }
예제 #2
0
        public void API_IncrementDecrement()
        {
            const int InitialPtr = 0x12345000;

            var target = new AtomicPtr <DummySixteenByteVal>(new IntPtr(InitialPtr));
            var incRes = target.Increment();

            FastAssertEqual((DummySixteenByteVal *)(InitialPtr + sizeof(DummySixteenByteVal)), incRes.CurrentValue);
            FastAssertEqual((DummySixteenByteVal *)InitialPtr, incRes.PreviousValue);
            FastAssertEqual <IntPtr>((IntPtr)(InitialPtr + sizeof(DummySixteenByteVal)), incRes.AsUntyped.CurrentValue);
            FastAssertEqual <IntPtr>((IntPtr)InitialPtr, incRes.AsUntyped.PreviousValue);

            var decRes = target.Decrement();

            FastAssertEqual((DummySixteenByteVal *)(InitialPtr + sizeof(DummySixteenByteVal)), decRes.PreviousValue);
            FastAssertEqual((DummySixteenByteVal *)InitialPtr, decRes.CurrentValue);
            FastAssertEqual <IntPtr>((IntPtr)(InitialPtr + sizeof(DummySixteenByteVal)), decRes.AsUntyped.PreviousValue);
            FastAssertEqual <IntPtr>((IntPtr)InitialPtr, decRes.AsUntyped.CurrentValue);
        }
예제 #3
0
        public void API_AddSubtract()
        {
            const int InitialPtr = 0x12345000;

            var target = new AtomicPtr <DummySixteenByteVal>(new IntPtr(InitialPtr));

            AssertResult(target.Add(10), InitialPtr, InitialPtr + sizeof(DummySixteenByteVal) * 10);
            AssertResult(target.Subtract(10), InitialPtr + sizeof(DummySixteenByteVal) * 10, InitialPtr);
            AssertResult(target.Add(10L), InitialPtr, InitialPtr + sizeof(DummySixteenByteVal) * 10);
            AssertResult(target.Subtract(10L), InitialPtr + sizeof(DummySixteenByteVal) * 10, InitialPtr);
            AssertResult(target.Add(new IntPtr(10L)), InitialPtr, InitialPtr + sizeof(DummySixteenByteVal) * 10);
            AssertResult(target.Subtract(new IntPtr(10L)), InitialPtr + sizeof(DummySixteenByteVal) * 10, InitialPtr);

            void AssertResult(AtomicPtr <DummySixteenByteVal> .TypedPtrExchangeRes result, int expectedPreviousAddr, int expectedNewAddr)
            {
                FastAssertEqual((DummySixteenByteVal *)expectedPreviousAddr, result.PreviousValue);
                FastAssertEqual((DummySixteenByteVal *)expectedNewAddr, result.CurrentValue);
                FastAssertEqual <IntPtr>((IntPtr)expectedPreviousAddr, result.AsUntyped.PreviousValue);
                FastAssertEqual <IntPtr>((IntPtr)expectedNewAddr, result.AsUntyped.CurrentValue);
            }
        }