mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 03:28:20 +02:00
Improve BeefCon cpu usage
This commit is contained in:
parent
db449ed5a5
commit
d5024964c8
2 changed files with 17 additions and 2 deletions
|
@ -48,7 +48,7 @@ class Program
|
|||
{
|
||||
while (true)
|
||||
{
|
||||
switch (mPipe.ReadMessage(-1))
|
||||
switch (mPipe.ReadMessage(20))
|
||||
{
|
||||
case .Ok(let msg):
|
||||
uint8* ptr = msg.Ptr + 1;
|
||||
|
|
|
@ -903,6 +903,7 @@ class BeefConConsoleProvider : ConsoleProvider
|
|||
public bool mConnected;
|
||||
public Thread mThread ~ delete _;
|
||||
public Monitor mDataMonitor = new .() ~ delete _;
|
||||
public WaitEvent mDataEvent = new .() ~ delete _;
|
||||
public int mPendingReadClear;
|
||||
public bool mExiting;
|
||||
|
||||
|
@ -949,6 +950,7 @@ class BeefConConsoleProvider : ConsoleProvider
|
|||
using (mDataMonitor.Enter())
|
||||
{
|
||||
mRecvStream.TryWrite(.(&data, len));
|
||||
mDataEvent.Set(true);
|
||||
}
|
||||
case .Err(let err):
|
||||
if ((err == .PipeListening) && (!mConnected))
|
||||
|
@ -1022,7 +1024,7 @@ class BeefConConsoleProvider : ConsoleProvider
|
|||
}
|
||||
}
|
||||
|
||||
public Result<Span<uint8>> ReadMessage(int timeoutMS)
|
||||
Result<Span<uint8>> DoReadMessage()
|
||||
{
|
||||
using (mDataMonitor.Enter())
|
||||
{
|
||||
|
@ -1044,6 +1046,19 @@ class BeefConConsoleProvider : ConsoleProvider
|
|||
return .Ok(.(mRecvStream.Memory.Ptr + 4, wantTotalLen - 4));
|
||||
}
|
||||
}
|
||||
|
||||
public Result<Span<uint8>> ReadMessage(int timeoutMS)
|
||||
{
|
||||
if (timeoutMS != 0)
|
||||
mDataEvent.WaitFor(timeoutMS);
|
||||
using (mDataMonitor.Enter())
|
||||
{
|
||||
var result = DoReadMessage();
|
||||
if (result case .Err)
|
||||
mDataEvent.Reset();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int sConId = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue