Skip to content

Commit

Permalink
Fea #29, 消除Chromium项目中Windows XP不支持的线程池创建API
Browse files Browse the repository at this point in the history
  - 添加 CreateThreadpool
  - 添加 CloseThreadpool
  - 添加 SetThreadpoolThreadMaximum
  - 添加 SetThreadpoolThreadMinimum
  - 添加 CallbackMayRunLong
  • Loading branch information
mingkuang-Chuyu committed May 20, 2024
1 parent 0bce0d8 commit 3f59f23
Show file tree
Hide file tree
Showing 7 changed files with 590 additions and 52 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/Build&Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ jobs:
$RunFaild = 0
&vstest.console src\Release\YY-Thunks.UnitTest.dll "/logger:trx;LogFileName=UnitTestWin32.trx" --Parallel "/Blame:CollectDump;CollectAlways=false;DumpType=full"
&vstest.console src\Release\YY-Thunks.UnitTest.dll "/logger:trx;LogFileName=UnitTestWin32.trx" "/Blame:CollectDump;CollectAlways=false;DumpType=full /Diag:TestResults\Win32.log"
if($lastexitcode -ne 0)
{
$RunFaild = 1
}
&vstest.console src\x64\Release\YY-Thunks.UnitTest.dll "/logger:trx;LogFileName=UnitTestWin64.trx" --Parallel "/Blame:CollectDump;CollectAlways=false;DumpType=full"
&vstest.console src\x64\Release\YY-Thunks.UnitTest.dll "/logger:trx;LogFileName=UnitTestWin64.trx" "/Blame:CollectDump;CollectAlways=false;DumpType=full /Diag:TestResults\Win64.log"
if($lastexitcode -ne 0)
{
$RunFaild = 1
Expand Down Expand Up @@ -179,8 +179,7 @@ jobs:
with:
name: ErrorLog
path: |
TestResults/**/*.dmp
TestResults/**/Sequence_*.xml
TestResults\**\*.*
src\Release\YY-Thunks.UnitTest.dll
src\Release\YY-Thunks.UnitTest.pdb
src\Release\*.log
Expand Down
5 changes: 5 additions & 0 deletions ThunksList.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
| StartThreadpoolIo | 不存在时,内部实现。
| CancelThreadpoolIo | 不存在时,内部实现。
| WaitForThreadpoolIoCallbacks | 不存在时,调用WaitForSingleObject。
| CreateThreadpool | 不存在时,内部实现。
| CloseThreadpool | 不存在时,内部实现。
| SetThreadpoolThreadMaximum | 不存在时,内部实现,自己控制最大并行数量。
| SetThreadpoolThreadMinimum | 不存在时,忽略,并总是返回成功。
| CallbackMayRunLong | 不存在时,自己估算系统剩余可用线程数。

## api-ms-win-core-winrt-l1-1-0.dll
| 函数 | Fallback
Expand Down
80 changes: 80 additions & 0 deletions src/Shared/InterlockedQueue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#pragma once

namespace YY::Thunks::internal
{
namespace
{
template<class Entry, size_t kMaxBlockSize>
class InterlockedQueue
{
private:
struct Block
{
size_t uLastReadIndex = 0;
size_t uLastWriteIndex = 0;
Block* pNextBlock = nullptr;
Entry* arrLoopBuffer[kMaxBlockSize];

bool IsEmpty()
{
return uLastReadIndex == uLastWriteIndex;
}

bool IsFull()
{
return uLastReadIndex + kMaxBlockSize == uLastWriteIndex;
}
};

Block* pFirstReadBlock = nullptr;
Block* pLastWriteBlock = nullptr;

public:
Entry* Pop() noexcept
{
if (!pFirstReadBlock)
return nullptr;

for (;;)
{
// 当前块任然有元素?
if (!pFirstReadBlock->IsEmpty())
{
auto _pTmp = pFirstReadBlock->arrLoopBuffer[pFirstReadBlock->uLastReadIndex % kMaxBlockSize];
pFirstReadBlock->uLastReadIndex += 1;
return _pTmp;
}

// 尝试流转到下一块
if (!pFirstReadBlock->pNextBlock)
return nullptr;

auto _pPendingDelete = pFirstReadBlock;
pFirstReadBlock = pFirstReadBlock->pNextBlock;
Delete(_pPendingDelete);
}

return nullptr;
}

void Push(_In_ Entry* _pEntry)
{
if (!pLastWriteBlock)
{
pFirstReadBlock = pLastWriteBlock = New<Block>();
}

// 如果满了就尝试链接到下一块
if (pLastWriteBlock->IsFull())
{
auto _pNextBlock = New<Block>();
pLastWriteBlock->pNextBlock = _pNextBlock;
pLastWriteBlock = _pNextBlock;
}

pLastWriteBlock->arrLoopBuffer[pLastWriteBlock->uLastWriteIndex % kMaxBlockSize] = _pEntry;
pLastWriteBlock->uLastWriteIndex += 1;
}
};
}
}
Loading

0 comments on commit 3f59f23

Please sign in to comment.