Skip to content

Commit

Permalink
Address Thread Synchronization Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
NoMoreFood committed Mar 2, 2022
1 parent a740958 commit 950f90b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 6 deletions.
Binary file modified Build/Release/x64/repacls.exe
Binary file not shown.
Binary file modified Build/Release/x86/repacls.exe
Binary file not shown.
Binary file modified Build/Repacls.zip
Binary file not shown.
13 changes: 10 additions & 3 deletions Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ VOID BeginScan(Processor & oProcessor)
if (OperationPathMode::GetPathMode() == SE_REGISTRY_KEY) oObject = new ObjectRegistry(oProcessor);
if (OperationPathMode::GetPathMode() == SE_DS_OBJECT) oObject = new ObjectAds(oProcessor);

// to track threads that are running
bool ProcessingStarted = false;

// startup some threads for processing
std::vector<std::thread> oThreads;
oProcessor.GetQueue().SetWaiterCounter(InputOutput::MaxThreads());
for (USHORT iNum = 0; iNum < InputOutput::MaxThreads(); iNum++)
oThreads.push_back(std::thread([&oProcessor,oObject]() {
oThreads.push_back(std::thread([&ProcessingStarted,&oProcessor,oObject]() {
for (;;)
{
ObjectEntry oEntry = oProcessor.GetQueue().Pop();
ProcessingStarted = true;

// break out if entry flags a termination
if (oEntry.ObjectType == SE_UNKNOWN_OBJECT_TYPE) return;
Expand All @@ -62,8 +66,11 @@ VOID BeginScan(Processor & oProcessor)
}

// wait for queue to be completely empty
oProcessor.GetQueue().WaitForEmptyQueues();

while (!ProcessingStarted)
{
oProcessor.GetQueue().WaitForEmptyQueues();
}

// send in some empty entries to tell the thread to stop waiting
for (USHORT iNum = 0; iNum < InputOutput::MaxThreads(); iNum++)
{
Expand Down
1 change: 1 addition & 0 deletions ObjectAds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void ObjectAds::GetChildObjects(ObjectEntry& oEntry)
// enumerate the object as a container
ULONG iFetched = 0L;
VARIANT vVar;
VariantInit(&vVar);
while (SUCCEEDED(ADsEnumerateNext(pEnumerator, 1, &vVar, &iFetched)) && (iFetched > 0))
{
CComPtr<IADs> pADs = nullptr;
Expand Down
9 changes: 6 additions & 3 deletions OperationDepth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ OperationDepth::OperationDepth(std::queue<std::wstring> & oArgList, const std::w
// exit if there are not enough arguments to parse
std::vector<std::wstring> sSubArgs = ProcessAndCheckArgs(1, oArgList);

// store off the argument
OperationDepth::MaxDepth() = _wtoi(sSubArgs.at(0).c_str());
if (OperationDepth::MaxDepth() < 0)
// parse the argument off the argument
const int iDepth = _wtoi(sSubArgs.at(0).c_str());
if (iDepth < 0)
{
// complain
wprintf(L"ERROR: Invalid depth specified for parameter '%s'.\n", GetCommand().c_str());
exit(-1);
}

// store for dynamic lookup
OperationDepth::MaxDepth() = iDepth;
};
Binary file modified Resource.rc
Binary file not shown.

0 comments on commit 950f90b

Please sign in to comment.