| 1 | /* $Id: gen_object.cpp,v 1.7 2001-02-10 10:31:31 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 <os2wrap.h>
|
|---|
| 14 | #include <stdlib.h>
|
|---|
| 15 | #include <misc.h>
|
|---|
| 16 | #include <win32type.h>
|
|---|
| 17 | #include <gen_object.h>
|
|---|
| 18 | #include <vmutex.h>
|
|---|
| 19 |
|
|---|
| 20 | #define DBG_LOCALLOG DBG_gen_object
|
|---|
| 21 | #include "dbglocal.h"
|
|---|
| 22 |
|
|---|
| 23 | VMutex genMutex[OBJTYPE_MAX];
|
|---|
| 24 |
|
|---|
| 25 | //******************************************************************************
|
|---|
| 26 | //******************************************************************************
|
|---|
| 27 | GenericObject::GenericObject(GenericObject **head, DWORD objType)
|
|---|
| 28 | {
|
|---|
| 29 | this->objType = objType;
|
|---|
| 30 | this->head = head;
|
|---|
| 31 | this->next = NULL;
|
|---|
| 32 |
|
|---|
| 33 | genMutex[objType].enter();
|
|---|
| 34 | if(*head == NULL) {
|
|---|
| 35 | *head = this;
|
|---|
| 36 | }
|
|---|
| 37 | else {
|
|---|
| 38 | GenericObject *cur = *head;
|
|---|
| 39 | while(cur->next)
|
|---|
| 40 | {
|
|---|
| 41 | cur = cur->next;
|
|---|
| 42 | }
|
|---|
| 43 | cur->next = this;
|
|---|
| 44 | }
|
|---|
| 45 | genMutex[objType].leave();
|
|---|
| 46 | }
|
|---|
| 47 | //******************************************************************************
|
|---|
| 48 | //******************************************************************************
|
|---|
| 49 | GenericObject::~GenericObject()
|
|---|
| 50 | {
|
|---|
| 51 | //remove from linked list
|
|---|
| 52 | genMutex[objType].enter();
|
|---|
| 53 | if(*head == this) {
|
|---|
| 54 | *head = next;
|
|---|
| 55 | }
|
|---|
| 56 | else {
|
|---|
| 57 | GenericObject *cur = *head;
|
|---|
| 58 | while(cur->next != this)
|
|---|
| 59 | {
|
|---|
| 60 | cur = cur->next;
|
|---|
| 61 | if(cur == NULL) {
|
|---|
| 62 | dprintf(("GenericObject dtor: cur == NULL!!"));
|
|---|
| 63 | DebugInt3();
|
|---|
| 64 | }
|
|---|
| 65 | }
|
|---|
| 66 | cur->next = next;
|
|---|
| 67 | }
|
|---|
| 68 | genMutex[objType].leave();
|
|---|
| 69 | }
|
|---|
| 70 | //******************************************************************************
|
|---|
| 71 | //******************************************************************************
|
|---|
| 72 | void GenericObject::DestroyAll(GenericObject *head)
|
|---|
| 73 | {
|
|---|
| 74 | GenericObject *cur, *next;
|
|---|
| 75 |
|
|---|
| 76 | cur = head;
|
|---|
| 77 | while(cur) {
|
|---|
| 78 | next = cur->next;
|
|---|
| 79 | delete cur;
|
|---|
| 80 | cur = next;
|
|---|
| 81 | }
|
|---|
| 82 | }
|
|---|
| 83 | //******************************************************************************
|
|---|
| 84 | //******************************************************************************
|
|---|
| 85 | void GenericObject::enterMutex()
|
|---|
| 86 | {
|
|---|
| 87 | genMutex[objType].enter();
|
|---|
| 88 | }
|
|---|
| 89 | //******************************************************************************
|
|---|
| 90 | //******************************************************************************
|
|---|
| 91 | void GenericObject::leaveMutex()
|
|---|
| 92 | {
|
|---|
| 93 | genMutex[objType].leave();
|
|---|
| 94 | }
|
|---|
| 95 | //******************************************************************************
|
|---|
| 96 | //******************************************************************************
|
|---|
| 97 | void GenericObject::enterMutex(DWORD objType)
|
|---|
| 98 | {
|
|---|
| 99 | genMutex[objType].enter();
|
|---|
| 100 | }
|
|---|
| 101 | //******************************************************************************
|
|---|
| 102 | //******************************************************************************
|
|---|
| 103 | void GenericObject::leaveMutex(DWORD objType)
|
|---|
| 104 | {
|
|---|
| 105 | genMutex[objType].leave();
|
|---|
| 106 | }
|
|---|
| 107 | //******************************************************************************
|
|---|
| 108 | //******************************************************************************
|
|---|