| 1 | /* $Id: gen_object.cpp,v 1.2 1999-11-01 19:11:39 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::DestroyAll(GenericObject *head)
|
|---|
| 71 | {
|
|---|
| 72 | GenericObject *cur, *next;
|
|---|
| 73 |
|
|---|
| 74 | cur = head;
|
|---|
| 75 | while(cur) {
|
|---|
| 76 | next = cur->next;
|
|---|
| 77 | delete cur;
|
|---|
| 78 | cur = next;
|
|---|
| 79 | }
|
|---|
| 80 | }
|
|---|
| 81 | //******************************************************************************
|
|---|
| 82 | //******************************************************************************
|
|---|
| 83 | void GenericObject::enterMutex()
|
|---|
| 84 | {
|
|---|
| 85 | genMutex[objType].enter();
|
|---|
| 86 | }
|
|---|
| 87 | //******************************************************************************
|
|---|
| 88 | //******************************************************************************
|
|---|
| 89 | void GenericObject::leaveMutex()
|
|---|
| 90 | {
|
|---|
| 91 | genMutex[objType].leave();
|
|---|
| 92 | }
|
|---|
| 93 | //******************************************************************************
|
|---|
| 94 | //******************************************************************************
|
|---|
| 95 | void GenericObject::enterMutex(DWORD objType)
|
|---|
| 96 | {
|
|---|
| 97 | genMutex[objType].enter();
|
|---|
| 98 | }
|
|---|
| 99 | //******************************************************************************
|
|---|
| 100 | //******************************************************************************
|
|---|
| 101 | void GenericObject::leaveMutex(DWORD objType)
|
|---|
| 102 | {
|
|---|
| 103 | genMutex[objType].leave();
|
|---|
| 104 | }
|
|---|
| 105 | //******************************************************************************
|
|---|
| 106 | //******************************************************************************
|
|---|