Skip to content

Commit

Permalink
Macros for manual critical sections
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa authored and luke-jr committed Feb 17, 2012
1 parent d52397b commit 43163a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/net.h
Expand Up @@ -277,7 +277,7 @@ class CNode

void BeginMessage(const char* pszCommand)
{
cs_vSend.Enter("cs_vSend", __FILE__, __LINE__);
ENTER_CRITICAL_SECTION(cs_vSend);
if (nHeaderStart != -1)
AbortMessage();
nHeaderStart = vSend.size();
Expand All @@ -296,7 +296,7 @@ class CNode
vSend.resize(nHeaderStart);
nHeaderStart = -1;
nMessageStart = -1;
cs_vSend.Leave();
LEAVE_CRITICAL_SECTION(cs_vSend);

if (fDebug)
printf("(aborted)\n");
Expand Down Expand Up @@ -334,7 +334,7 @@ class CNode

nHeaderStart = -1;
nMessageStart = -1;
cs_vSend.Leave();
LEAVE_CRITICAL_SECTION(cs_vSend);
}

void EndMessageAbortIfEmpty()
Expand Down
6 changes: 6 additions & 0 deletions src/util.h
Expand Up @@ -254,6 +254,12 @@ class CCriticalBlock
for (bool fcriticalblockonce=true; fcriticalblockonce; assert(("break caught by CRITICAL_BLOCK!" && !fcriticalblockonce)), fcriticalblockonce=false) \
for (CCriticalBlock criticalblock(cs, #cs, __FILE__, __LINE__); fcriticalblockonce; fcriticalblockonce=false)

#define ENTER_CRITICAL_SECTION(cs) \
(cs).Enter(#cs, __FILE__, __LINE__)

#define LEAVE_CRITICAL_SECTION(cs) \
(cs).Leave()

class CTryCriticalBlock
{
protected:
Expand Down

0 comments on commit 43163a5

Please sign in to comment.