summaryrefslogtreecommitdiff
path: root/XSlock.h
blob: 0b2c8299b917fd32dfadfbf523b94f67bcd13361 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef __XSlock_h__
#define __XSlock_h__

class XSLockManager
{
public:
	XSLockManager() { InitializeCriticalSection(&cs); };
	~XSLockManager() { DeleteCriticalSection(&cs); };
	void Enter(void) { EnterCriticalSection(&cs); };
	void Leave(void) { LeaveCriticalSection(&cs); };
protected:
	CRITICAL_SECTION cs;
};

XSLockManager g_XSLock;
CPerlObj* pPerl;

class XSLock
{
public:
	XSLock(CPerlObj *p) {
	    g_XSLock.Enter();
	    ::pPerl = p;
	};
	~XSLock() { g_XSLock.Leave(); };
};

/* PERL_CAPI does its own locking in xs_handler() */
#if defined(PERL_OBJECT) && !defined(PERL_CAPI)
#undef dXSARGS
#define dXSARGS	\
	XSLock localLock(pPerl);			\
	dSP; dMARK;					\
	I32 ax = mark - PL_stack_base + 1;		\
	I32 items = sp - mark
#endif	/* PERL_OBJECT && !PERL_CAPI */

#endif