| 1 | /* $Id: gen_object.cpp,v 1.1 1999-09-15 23:18:50 sandervl Exp $ */ | 
|---|
| 2 | /* | 
|---|
| 3 | * Generic Object Class for OS/2 | 
|---|
| 4 | * | 
|---|
| 5 | * Allocated in shared memory, so other processes can access the objects | 
|---|
| 6 | * | 
|---|
| 7 | * NOTE: Requires safety precautions to use objects in multiple threads or processes | 
|---|
| 8 | * | 
|---|
| 9 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl) | 
|---|
| 10 | * | 
|---|
| 11 | */ | 
|---|
| 12 | #define  INCL_DOSSEMAPHORES | 
|---|
| 13 | #include <os2.h> | 
|---|
| 14 | #include <os2wrap.h> | 
|---|
| 15 | #include <stdlib.h> | 
|---|
| 16 | #include <win32type.h> | 
|---|
| 17 | #include <gen_object.h> | 
|---|
| 18 | #include <misc.h> | 
|---|
| 19 | #include <vmutex.h> | 
|---|
| 20 |  | 
|---|
| 21 | VMutex genMutex[OBJTYPE_MAX]; | 
|---|
| 22 |  | 
|---|
| 23 | //****************************************************************************** | 
|---|
| 24 | //****************************************************************************** | 
|---|
| 25 | GenericObject::GenericObject(GenericObject **head, DWORD objType) | 
|---|
| 26 | { | 
|---|
| 27 | this->objType = objType; | 
|---|
| 28 | this->head    = head; | 
|---|
| 29 | this->next    = NULL; | 
|---|
| 30 |  | 
|---|
| 31 | genMutex[objType].enter(); | 
|---|
| 32 | if(*head == NULL) { | 
|---|
| 33 | *head = this; | 
|---|
| 34 | } | 
|---|
| 35 | else { | 
|---|
| 36 | GenericObject *cur = *head; | 
|---|
| 37 | while(cur->next) | 
|---|
| 38 | { | 
|---|
| 39 | cur = cur->next; | 
|---|
| 40 | } | 
|---|
| 41 | cur->next = this; | 
|---|
| 42 | } | 
|---|
| 43 | genMutex[objType].leave(); | 
|---|
| 44 | } | 
|---|
| 45 | //****************************************************************************** | 
|---|
| 46 | //****************************************************************************** | 
|---|
| 47 | GenericObject::~GenericObject() | 
|---|
| 48 | { | 
|---|
| 49 | //remove from linked list | 
|---|
| 50 | genMutex[objType].enter(); | 
|---|
| 51 | if(*head == this) { | 
|---|
| 52 | *head = next; | 
|---|
| 53 | } | 
|---|
| 54 | else { | 
|---|
| 55 | GenericObject *cur = *head; | 
|---|
| 56 | while(cur->next != this) | 
|---|
| 57 | { | 
|---|
| 58 | cur = cur->next; | 
|---|
| 59 | if(cur == NULL) { | 
|---|
| 60 | dprintf(("GenericObject dtor: cur == NULL!!")); | 
|---|
| 61 | DebugInt3(); | 
|---|
| 62 | } | 
|---|
| 63 | } | 
|---|
| 64 | cur->next = next; | 
|---|
| 65 | } | 
|---|
| 66 | genMutex[objType].leave(); | 
|---|
| 67 | } | 
|---|
| 68 | //****************************************************************************** | 
|---|
| 69 | //****************************************************************************** | 
|---|
| 70 | void GenericObject::enterMutex() | 
|---|
| 71 | { | 
|---|
| 72 | genMutex[objType].enter(); | 
|---|
| 73 | } | 
|---|
| 74 | //****************************************************************************** | 
|---|
| 75 | //****************************************************************************** | 
|---|
| 76 | void GenericObject::leaveMutex() | 
|---|
| 77 | { | 
|---|
| 78 | genMutex[objType].leave(); | 
|---|
| 79 | } | 
|---|
| 80 | //****************************************************************************** | 
|---|
| 81 | //****************************************************************************** | 
|---|
| 82 | void GenericObject::enterMutex(DWORD objType) | 
|---|
| 83 | { | 
|---|
| 84 | genMutex[objType].enter(); | 
|---|
| 85 | } | 
|---|
| 86 | //****************************************************************************** | 
|---|
| 87 | //****************************************************************************** | 
|---|
| 88 | void GenericObject::leaveMutex(DWORD objType) | 
|---|
| 89 | { | 
|---|
| 90 | genMutex[objType].leave(); | 
|---|
| 91 | } | 
|---|
| 92 | //****************************************************************************** | 
|---|
| 93 | //****************************************************************************** | 
|---|