newbie_wince
2010-05-13 16:20:01 UTC
Hi,
I have to create a recursive critical section using wince 5.0 API. Here is
the following code that I tried. Is the logic right?
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#define MAX 25
int count = 0;
CRITICAL_SECTION cs[MAX];
CRITICAL_SECTION guard;
void os_enter_cs(void);
void os_exit_cs(void);
int _tmain(void)
{
InitializeCriticalSection(&guard);
return 0;
}
void os_enter_cs(void)
{
// guard it
EnterCriticalSection(&guard); // guard
{
count++;
InitializeCriticalSection(&cs[count]);
}
LeaveCriticalSection(&guard); // guard
EnterCriticalSection(&cs[count]);
}
void os_exit_cs(void)
{
EnterCriticalSection(&guard); // guard
{
count--;
LeaveCriticalSection(&cs[count+1]);
DeleteCriticalSection(&cs[count+1]);
}
LeaveCriticalSection(&guard); // guard
}
I have to create a recursive critical section using wince 5.0 API. Here is
the following code that I tried. Is the logic right?
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#define MAX 25
int count = 0;
CRITICAL_SECTION cs[MAX];
CRITICAL_SECTION guard;
void os_enter_cs(void);
void os_exit_cs(void);
int _tmain(void)
{
InitializeCriticalSection(&guard);
return 0;
}
void os_enter_cs(void)
{
// guard it
EnterCriticalSection(&guard); // guard
{
count++;
InitializeCriticalSection(&cs[count]);
}
LeaveCriticalSection(&guard); // guard
EnterCriticalSection(&cs[count]);
}
void os_exit_cs(void)
{
EnterCriticalSection(&guard); // guard
{
count--;
LeaveCriticalSection(&cs[count+1]);
DeleteCriticalSection(&cs[count+1]);
}
LeaveCriticalSection(&guard); // guard
}