Skip to content

Commit

Permalink
Check the queue before waiting for new items
Browse files Browse the repository at this point in the history
  • Loading branch information
hawku committed Jan 25, 2019
1 parent b6ae971 commit d53eb54
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
12 changes: 11 additions & 1 deletion TabletDriverService/BufferQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ void BufferQueue::Clear()
void BufferQueue::Wait()
{
std::unique_lock<std::mutex> mlock(lockWait);
conditionBuffer.wait(mlock);

// Check if the queue is empty
bool isQueueEmpty = false;
lockQueue.lock();
isQueueEmpty = queue.empty();
lockQueue.unlock();

// Wait for items if queue is empty
if (isQueueEmpty) {
conditionBuffer.wait(mlock);
}
}

//
Expand Down
19 changes: 14 additions & 5 deletions TabletDriverService/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,17 @@ void Logger::NotifyNewItem()
void Logger::WaitNewItem()
{
std::unique_lock<std::mutex> mlock(lockNewItem);
conditionNewItem.wait(mlock);

// Check if the queue is empty
bool isQueueEmpty = false;
lockQueue.lock();
isQueueEmpty = logQueue.empty();
lockQueue.unlock();

// Wait for items if queue is empty
if (isQueueEmpty) {
conditionNewItem.wait(mlock);
}
}


Expand All @@ -292,15 +302,14 @@ void Logger::run() {

while (true) {

// Shutdown the thread
if (!IsRunning()) break;

// Wait for the new item
WaitNewItem();

// Process item queue
ProcessQueue();

// Shutdown the thread
if (!IsRunning()) break;

}

printf("Logger thread exit!\n");
Expand Down

2 comments on commit d53eb54

@GexorHD
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

soo i have veikk 50, and how do i use the apps to configure my veikk A50, because the apps doesn't support Veikk50 and i look at this file named .gitignore and it says support A50 but i can't open it. please help, thanks.

@7mochi
Copy link

@7mochi 7mochi commented on d53eb54 Oct 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GexorHD
I recommend you migrate to OpenTabletDriver
According to this your tablet is compatible.
And in case you had any problem in the installation you could enter their discord server and they'll help you.

Please sign in to comment.