Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.

Static field objects are now created on constructor. #72

Merged
merged 1 commit into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion source/Windows.Devices.Gpio/GpioController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class Gpio​Controller : IGpioController
{
// this is used as the lock object
// a lock is required because multiple threads can access the I2C controller
readonly static object _syncLock = new object();
static object _syncLock;

// we can have only one instance of the GpioController
// need to do a lazy initialization of this field to make sure it exists when called elsewhere.
Expand Down Expand Up @@ -56,6 +56,11 @@ public extern int PinCount
{
if (s_instance == null)
{
if (_syncLock == null)
{
_syncLock = new object();
}

lock (_syncLock)
{
if (s_instance == null)
Expand Down
7 changes: 5 additions & 2 deletions source/Windows.Devices.Gpio/GpioPin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public delegate void GpioPinValueChangedEventHandler(
/// </summary>
public sealed class Gpio​Pin : IGpioPin, IDisposable
{
private static GpioPinEventListener s_eventListener = new GpioPinEventListener();
private static GpioPinEventListener s_eventListener;

// this is used as the lock object
// a lock is required because multiple threads can access the GpioPin
private object _syncLock = new object();
private object _syncLock;

private readonly int _pinNumber;
private GpioPinDriveMode _driveMode = GpioPinDriveMode.Input;
Expand All @@ -40,6 +40,9 @@ public sealed class Gpio​Pin : IGpioPin, IDisposable
internal Gpio​Pin(int pinNumber)
{
_pinNumber = pinNumber;

s_eventListener = new GpioPinEventListener();
_syncLock = new object();
}

internal bool Init()
Expand Down