source: trunk/src/user32/win32wndhandle.cpp@ 3207

Last change on this file since 3207 was 3207, checked in by sandervl, 25 years ago

shared mutex fixes

File size: 3.1 KB
Line 
1/* $Id: win32wndhandle.cpp,v 1.7 2000-03-23 19:24:26 sandervl Exp $ */
2/*
3 * Win32 Handle Management Code for OS/2
4 *
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * TODO: The table should be dynamically increased when necessary
10 * This is just a quick and dirty implementation
11 * TODO: Probably need to clean up the table when app closes
12 * (also store PID and remove all handles with PID of terminating app)
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 */
17
18#include <os2win.h>
19#include <vmutex.h>
20#include "win32wndhandle.h"
21
22#define DBG_LOCALLOG DBG_win32wndhandle
23#include "dbglocal.h"
24
25//******************************************************************************
26
27//NOTE: This must be in the local data segment -> if a shared semaphore was
28// created by a different process, the handle returned by DosOpenMutexSem
29// will be returned in hGlobalTableMutex
30HMTX hGlobalTableMutex = 0;
31
32//Global DLL Data
33#pragma data_seg(_GLOBALDATA)
34ULONG WindowHandleTable[MAX_WINDOW_HANDLES] = {0};
35VMutex tableMutex(VMUTEX_SHARED, &hGlobalTableMutex);
36ULONG lowestFreeIndex = 0;
37#pragma data_seg()
38
39//******************************************************************************
40//******************************************************************************
41BOOL HwAllocateWindowHandle(HWND *hwnd, DWORD dwUserData)
42{
43 tableMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalTableMutex);
44 if(lowestFreeIndex == -1) {
45 //oops, out of handles
46 dprintf(("USER32: HwAllocateWindowHandle OUT OF WINDOW HANDLES!!"));
47 tableMutex.leave(&hGlobalTableMutex);
48 DebugInt3();
49 return FALSE;
50 }
51 *hwnd = lowestFreeIndex;
52 *hwnd |= WNDHANDLE_MAGIC_HIGHWORD;
53 WindowHandleTable[lowestFreeIndex] = dwUserData;
54
55 lowestFreeIndex = -1;
56
57 //find next free handle
58 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
59 if(WindowHandleTable[i] == 0) {
60 lowestFreeIndex = i;
61 break;
62 }
63 }
64 tableMutex.leave(&hGlobalTableMutex);
65 return TRUE;
66}
67//******************************************************************************
68//******************************************************************************
69void HwFreeWindowHandle(HWND hwnd)
70{
71 hwnd &= WNDHANDLE_MAGIC_MASK;
72 if(hwnd < MAX_WINDOW_HANDLES) {
73 tableMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalTableMutex);
74 WindowHandleTable[hwnd] = 0;
75 if(lowestFreeIndex == -1 || hwnd < lowestFreeIndex)
76 lowestFreeIndex = hwnd;
77
78 tableMutex.leave(&hGlobalTableMutex);
79 }
80}
81//******************************************************************************
82//******************************************************************************
83BOOL HwGetWindowHandleData(HWND hwnd, DWORD *pdwUserData)
84{
85 if((hwnd & 0xFFFF0000) != WNDHANDLE_MAGIC_HIGHWORD) {
86 return FALSE; //unknown window (PM?)
87 }
88 hwnd &= WNDHANDLE_MAGIC_MASK;
89 if(hwnd < MAX_WINDOW_HANDLES) {
90 *pdwUserData = WindowHandleTable[hwnd];
91 return TRUE;
92 }
93 *pdwUserData = 0;
94 return FALSE;
95}
96//******************************************************************************
97//******************************************************************************
Note: See TracBrowser for help on using the repository browser.