216 lines
4.8 KiB
C#
216 lines
4.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Concurrent;
|
|
using System.Threading;
|
|
|
|
namespace Assets.Scripts.Devices.Ble.Win
|
|
{
|
|
internal abstract class WclBleThread
|
|
{
|
|
// Token: 0x170005E2 RID: 1506
|
|
// (get) Token: 0x06002114 RID: 8468 RVA: 0x000890FE File Offset: 0x000872FE
|
|
public bool IsRunning
|
|
{
|
|
get
|
|
{
|
|
return this.started || this.IsTerminating;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170005E3 RID: 1507
|
|
// (get) Token: 0x06002115 RID: 8469 RVA: 0x00089112 File Offset: 0x00087312
|
|
public bool IsTerminating
|
|
{
|
|
get
|
|
{
|
|
return this.terminating;
|
|
}
|
|
}
|
|
|
|
// Token: 0x170005E4 RID: 1508
|
|
// (get) Token: 0x06002116 RID: 8470 RVA: 0x0008911C File Offset: 0x0008731C
|
|
public bool CanLoadWork
|
|
{
|
|
get
|
|
{
|
|
return this.IsRunning && !this.IsTerminating;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06002117 RID: 8471
|
|
protected abstract void SetUpWorkerThread();
|
|
|
|
// Token: 0x06002118 RID: 8472
|
|
protected abstract void CleanUpWorkerThread();
|
|
|
|
// Token: 0x06002119 RID: 8473 RVA: 0x00089131 File Offset: 0x00087331
|
|
protected void TreadProcInitialized()
|
|
{
|
|
this.sEvent.Set();
|
|
}
|
|
|
|
// Token: 0x0600211A RID: 8474 RVA: 0x0008913F File Offset: 0x0008733F
|
|
protected void ProcessPendingAPCMessages()
|
|
{
|
|
while (WclAlertableWait.FlushApc() != 0U)
|
|
{
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600211B RID: 8475 RVA: 0x00089148 File Offset: 0x00087348
|
|
protected void InternalCleanUp()
|
|
{
|
|
this.sEvent.Close();
|
|
this.sEvent.Dispose();
|
|
this.sEvent = null;
|
|
this.aEvent.Close();
|
|
this.aEvent.Dispose();
|
|
this.aEvent = null;
|
|
this.tEvent.Close();
|
|
this.tEvent.Dispose();
|
|
this.tEvent = null;
|
|
this.terminating = false;
|
|
}
|
|
|
|
// Token: 0x0600211C RID: 8476 RVA: 0x000891B5 File Offset: 0x000873B5
|
|
private void ThreadProc()
|
|
{
|
|
this.SetUpWorkerThread();
|
|
this.sEvent.Set();
|
|
this.DoWorkerLoop();
|
|
this.CleanUpWorkerThread();
|
|
this.InternalCleanUp();
|
|
}
|
|
|
|
// Token: 0x0600211D RID: 8477 RVA: 0x000891DC File Offset: 0x000873DC
|
|
private void DoWorkerLoop()
|
|
{
|
|
IntPtr[] handle = new IntPtr[]
|
|
{
|
|
this.tEvent.SafeWaitHandle.DangerousGetHandle(),
|
|
this.aEvent.SafeWaitHandle.DangerousGetHandle()
|
|
};
|
|
while (WclAlertableWait.Wait(handle, 2U, 4294967295U) != 0U && !this.terminating)
|
|
{
|
|
this.InvokeQueuedActions();
|
|
if (this.terminating)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600211E RID: 8478 RVA: 0x0008923C File Offset: 0x0008743C
|
|
public virtual bool Start()
|
|
{
|
|
if (this.IsRunning)
|
|
{
|
|
return false;
|
|
}
|
|
this.sEvent = new ManualResetEvent(false);
|
|
this.tEvent = new ManualResetEvent(false);
|
|
this.aEvent = new AutoResetEvent(false);
|
|
this.wThread = new Thread(new ThreadStart(this.ThreadProc));
|
|
this.wThread.Start();
|
|
this.sEvent.WaitOne();
|
|
this.started = true;
|
|
return true;
|
|
}
|
|
|
|
// Token: 0x0600211F RID: 8479 RVA: 0x000892B0 File Offset: 0x000874B0
|
|
public virtual bool Stop()
|
|
{
|
|
if (!this.started || this.IsTerminating)
|
|
{
|
|
return false;
|
|
}
|
|
this.terminating = true;
|
|
this.tEvent.Set();
|
|
this.wThread = null;
|
|
this.ClearActionQueue();
|
|
this.started = false;
|
|
return true;
|
|
}
|
|
|
|
// Token: 0x06002120 RID: 8480 RVA: 0x000892FD File Offset: 0x000874FD
|
|
protected bool EnqueueAction(Action action)
|
|
{
|
|
if (this.CanLoadWork)
|
|
{
|
|
this.aQueue.Enqueue(action);
|
|
this.aEvent.Set();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Token: 0x06002121 RID: 8481 RVA: 0x00089324 File Offset: 0x00087524
|
|
protected void ClearActionQueue()
|
|
{
|
|
Action action;
|
|
while (this.aQueue.TryDequeue(out action))
|
|
{
|
|
}
|
|
}
|
|
|
|
// Token: 0x06002122 RID: 8482 RVA: 0x00089340 File Offset: 0x00087540
|
|
protected void InvokeQueuedActions()
|
|
{
|
|
while (this.DequeueAdnInvokeAction())
|
|
{
|
|
}
|
|
}
|
|
|
|
// Token: 0x06002123 RID: 8483 RVA: 0x0008934C File Offset: 0x0008754C
|
|
protected bool DequeueAdnInvokeAction()
|
|
{
|
|
Action action = this.TryDequActione();
|
|
if (action == null)
|
|
{
|
|
return false;
|
|
}
|
|
action();
|
|
return true;
|
|
}
|
|
|
|
// Token: 0x06002124 RID: 8484 RVA: 0x0008936C File Offset: 0x0008756C
|
|
private Action TryDequActione()
|
|
{
|
|
if (!this.CanLoadWork)
|
|
{
|
|
return null;
|
|
}
|
|
Action result;
|
|
if (!this.aQueue.TryDequeue(out result))
|
|
{
|
|
return null;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Token: 0x04001341 RID: 4929
|
|
protected ManualResetEvent tEvent;
|
|
|
|
// Token: 0x04001342 RID: 4930
|
|
protected AutoResetEvent aEvent;
|
|
|
|
// Token: 0x04001343 RID: 4931
|
|
private readonly ConcurrentQueue<Action> aQueue = new ConcurrentQueue<Action>();
|
|
|
|
// Token: 0x04001344 RID: 4932
|
|
protected ManualResetEvent sEvent;
|
|
|
|
// Token: 0x04001345 RID: 4933
|
|
protected Thread wThread;
|
|
|
|
// Token: 0x04001346 RID: 4934
|
|
protected volatile bool terminating;
|
|
|
|
// Token: 0x04001347 RID: 4935
|
|
private volatile bool started;
|
|
}
|
|
}
|