Skip to content

Commit

Permalink
[REFACT] Moved custom Mutex class to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
hasherezade committed Jun 13, 2024
1 parent f54b294 commit 2898fdd
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 46 deletions.
47 changes: 1 addition & 46 deletions scanners/module_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,10 @@
#include <peconv.h>
#include <string>
#include <map>
#include "../utils/custom_mutex.h"

namespace pesieve
{
namespace util {
struct Mutex {
public:
Mutex()
{
InitializeCriticalSection(&cs);
}

void Lock()
{
EnterCriticalSection(&cs);
}

void Unlock()
{
LeaveCriticalSection(&cs);
}

~Mutex()
{
DeleteCriticalSection(&cs);
}

private:
CRITICAL_SECTION cs;
};

struct MutexLocker
{
public:
MutexLocker(Mutex& _mutex)
: mutex(_mutex)
{
mutex.Lock();
}

~MutexLocker()
{
mutex.Unlock();
}

private:
Mutex& mutex;
};
};

struct CachedModule {
public:
CachedModule()
Expand Down
54 changes: 54 additions & 0 deletions utils/custom_mutex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#pragma once
#include <peconv.h>

namespace pesieve
{
namespace util {

struct Mutex {
public:
Mutex()
{
InitializeCriticalSection(&cs);
}

void Lock()
{
EnterCriticalSection(&cs);
}

void Unlock()
{
LeaveCriticalSection(&cs);
}

~Mutex()
{
DeleteCriticalSection(&cs);
}

private:
CRITICAL_SECTION cs;
};

struct MutexLocker
{
public:
MutexLocker(Mutex& _mutex)
: mutex(_mutex)
{
mutex.Lock();
}

~MutexLocker()
{
mutex.Unlock();
}

private:
Mutex& mutex;
};

}; //namespace util

}; //namespace pesieve

0 comments on commit 2898fdd

Please sign in to comment.