Commit 93e3f905 authored by Francois Boisvert's avatar Francois Boisvert Committed by Alexandre Julliard

Adding of new functions to make the wnd struct thread safe. Adding of

irefCount in wnd struct.
parent f544507b
...@@ -79,6 +79,7 @@ typedef struct tagWND ...@@ -79,6 +79,7 @@ typedef struct tagWND
DWORD helpContext; /* Help context ID */ DWORD helpContext; /* Help context ID */
WORD flags; /* Misc. flags (see below) */ WORD flags; /* Misc. flags (see below) */
HMENU16 hSysMenu; /* window's copy of System Menu */ HMENU16 hSysMenu; /* window's copy of System Menu */
int irefCount; /* window's reference count*/
DWORD userdata; /* User private data */ DWORD userdata; /* User private data */
struct _WND_DRIVER *pDriver; /* Window driver */ struct _WND_DRIVER *pDriver; /* Window driver */
void *pDriverData; /* Window driver data */ void *pDriverData; /* Window driver data */
...@@ -133,7 +134,12 @@ typedef struct ...@@ -133,7 +134,12 @@ typedef struct
#define BWA_SKIPICONIC 0x0008 #define BWA_SKIPICONIC 0x0008
/* Window functions */ /* Window functions */
extern void WIN_LockWnds();
extern void WIN_UnlockWnds();
extern int WIN_SuspendWndsLock();
extern void WIN_RestoreWndsLock(int ipreviousLock);
extern WND* WIN_FindWndPtr( HWND32 hwnd ); extern WND* WIN_FindWndPtr( HWND32 hwnd );
extern void WIN_ReleaseWndPtr(WND *wndPtr);
extern WND* WIN_GetDesktop(void); extern WND* WIN_GetDesktop(void);
extern void WIN_DumpWindow( HWND32 hwnd ); extern void WIN_DumpWindow( HWND32 hwnd );
extern void WIN_WalkWindows( HWND32 hwnd, int indent ); extern void WIN_WalkWindows( HWND32 hwnd, int indent );
......
...@@ -52,6 +52,68 @@ static HWND32 hwndSysModal = 0; ...@@ -52,6 +52,68 @@ static HWND32 hwndSysModal = 0;
static WORD wDragWidth = 4; static WORD wDragWidth = 4;
static WORD wDragHeight= 3; static WORD wDragHeight= 3;
/* thread safeness */
static CRITICAL_SECTION WIN_CritSection;
static int ilockCounter = 0;
/***********************************************************************
* WIN_LockWnds
*
* Locks access to all WND structures for thread safeness
*/
void WIN_LockWnds()
{
EnterCriticalSection(&WIN_CritSection);
ilockCounter++;
TRACE(win,"All windows hinstances have been locked (lock #%i)\n",ilockCounter);
}
/***********************************************************************
* WIN_UnlockWnds
*
* Unlocks access to all WND structures
*/
void WIN_UnlockWnds()
{
TRACE(win,"Lock #%i been unlocked\n",ilockCounter+1);
ilockCounter--;
if(ilockCounter == 0)
{
LeaveCriticalSection(&WIN_CritSection);
TRACE(win,"All windows hinstances have been unlocked\n");
}
else if(ilockCounter < 0)
{
ERR(win,"Negative lock reference ==> missing call to WIN_Lock!\n");
}
}
/***********************************************************************
* WIN_SuspendWndsLock
*
* Suspend the lock on WND structures.
* Returns the number of locks suspended
*/
int WIN_SuspendWndsLock()
{
int isuspendedLocks = ilockCounter;
ilockCounter = 0;
LeaveCriticalSection(&WIN_CritSection);
TRACE(win,"All windows hinstances locks have been suspended\n");
return isuspendedLocks;
}
/***********************************************************************
* WIN_RestoreWndsLock
*
* Restore the suspended locks on WND structures
*/
void WIN_Unlock(int ipreviousLocks)
{
EnterCriticalSection(&WIN_CritSection);
ilockCounter = ipreviousLocks;
}
/*********************************************************************** /***********************************************************************
* WIN_FindWndPtr * WIN_FindWndPtr
* *
...@@ -61,8 +123,13 @@ WND * WIN_FindWndPtr( HWND32 hwnd ) ...@@ -61,8 +123,13 @@ WND * WIN_FindWndPtr( HWND32 hwnd )
{ {
WND * ptr; WND * ptr;
if (!hwnd || HIWORD(hwnd)) goto error; if (!hwnd || HIWORD(hwnd)) goto error2;
ptr = (WND *) USER_HEAP_LIN_ADDR( hwnd ); ptr = (WND *) USER_HEAP_LIN_ADDR( hwnd );
/* Lock all WND structures for thread safeness
WIN_LockWnds();
and increment destruction monitoring value
ptr->irefCount++;
*/
if (ptr->dwMagic != WND_MAGIC) goto error; if (ptr->dwMagic != WND_MAGIC) goto error;
if (ptr->hwndSelf != hwnd) if (ptr->hwndSelf != hwnd)
{ {
...@@ -72,10 +139,37 @@ WND * WIN_FindWndPtr( HWND32 hwnd ) ...@@ -72,10 +139,37 @@ WND * WIN_FindWndPtr( HWND32 hwnd )
} }
return ptr; return ptr;
error: error:
/* Unlock all WND structures for thread safeness
WIN_UnlockWnds();
and decrement destruction monitoring value
ptr->irefCount--;
*/
error2:
SetLastError( ERROR_INVALID_WINDOW_HANDLE ); SetLastError( ERROR_INVALID_WINDOW_HANDLE );
return NULL; return NULL;
} }
/***********************************************************************
* WIN_ReleaseWndPtr
*
* Release the pointer to the WND structure.
*/
void WIN_ReleaseWndPtr(WND *wndPtr)
{
/*Decrement destruction monitoring value
wndPtr->irefCount--;
Check if it's time to release the memory
if(wndPtr->irefCount == 0)
{
Add memory releasing code here
}
unlock all WND structures for thread safeness
WIN_UnlockWnds();
*/
}
/*********************************************************************** /***********************************************************************
* WIN_DumpWindow * WIN_DumpWindow
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment