-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fea #29, 消除Chromium项目中Windows XP不支持的线程池创建API
- 添加 CreateThreadpool - 添加 CloseThreadpool - 添加 SetThreadpoolThreadMaximum - 添加 SetThreadpoolThreadMinimum - 添加 CallbackMayRunLong
- Loading branch information
1 parent
0bce0d8
commit 3f59f23
Showing
7 changed files
with
590 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.