Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

LOW_link.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           LOW_link.cpp  -  description
00003                              -------------------
00004     begin                : Sun Jul 7 2002
00005     copyright            : (C) 2002 by Harald Roelle, Helmut Reiser
00006     email                : roelle@informatik.uni-muenchen.de, reiser@informatik.uni-muenchen.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018  
00019 #include "LOW_link.h"
00020 #include "LOW_helper_msglog.h"
00021 
00022 
00023 //=====================================================================================
00024 //
00025 // static attributes
00026 //
00027 
00028 LOW_link::linkID_t  LOW_link::linkCounter = 0;
00029 
00030 
00031 
00032 //=====================================================================================
00033 //
00034 // constructors
00035 //
00036 
00037 LOW_link::LOW_link( const bool inHasProgramPulse, const bool inHasOverDrive,
00038                     const bool inHasExternalPower, const bool inAllowProgPulse) :
00039   linkID(linkCounter++),
00040   hasProgramPulse( inHasProgramPulse),
00041   hasOverDrive( inHasOverDrive),
00042   hasExternalPower( inHasExternalPower),
00043   allowProgPulse( inAllowProgPulse)
00044 {
00045   aquireCount = 0;
00046   aquirePID   = 0;
00047 }
00048 
00049 
00050 LOW_link::~LOW_link()
00051 {
00052 }
00053 
00054 
00055 
00056 //=====================================================================================
00057 //
00058 // locks
00059 //
00060 
00061 LOW_link::commLock::commLock( LOW_link &inLink) :
00062   link( inLink)
00063 {
00064   link.semSet->decSem( counterSemNo);
00065   if ( link.aquirePID==LOW_platformMisc::getThreadID() && link.aquireCount>0 ) {  // we already have the lock semaphore
00066     ++link.aquireCount;
00067     link.semSet->incSem( counterSemNo);
00068     return;
00069   }
00070   link.semSet->incSem( counterSemNo);
00071 
00072   link.semSet->decSem( lockSemNo);
00073 
00074   link.semSet->decSem( counterSemNo);
00075   ++link.aquireCount;
00076   link.aquirePID = LOW_platformMisc::getThreadID();
00077   link.semSet->incSem( counterSemNo);
00078   
00079   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkLock_dl, "Lock aquired", __FILE__, __LINE__);
00080 }
00081 
00082 
00083 LOW_link::commLock::~commLock()
00084 {
00085   link.semSet->decSem( counterSemNo);
00086 
00087   if ( link.aquirePID!=LOW_platformMisc::getThreadID() ) {
00088     link.semSet->incSem( counterSemNo);
00089     throw internal_error( "FATAL: foreign process trying to releaseLock()", __FILE__, __LINE__);
00090   }
00091   
00092   if ( link.aquireCount == 0 ) {
00093     link.semSet->incSem( counterSemNo);
00094     throw internal_error( "FATAL: unbalanced releaseLock()", __FILE__, __LINE__);
00095   }
00096 
00097   --link.aquireCount;
00098   if ( link.aquireCount == 0 ) {
00099     link.aquirePID = 0;
00100     link.semSet->incSem( lockSemNo);
00101     LOW_helper_msglog::printDebug( LOW_helper_msglog::linkLock_dl, "Lock released", __FILE__, __LINE__);
00102   }
00103   
00104   link.semSet->incSem( counterSemNo);
00105 }
00106 
00107 
00108 
00109 
00110 //=====================================================================================
00111 //
00112 // operator overloading
00113 //
00114   
00115 bool LOW_link::operator==(LOW_link &inLink) const
00116 {
00117   return (linkID==inLink.linkID);
00118 }
00119 
00120 
00121   
00122 //=====================================================================================
00123 //
00124 // methods
00125 //
00126 
00127 uint32_t LOW_link::getID() const
00128 {
00129   return linkID;
00130 }
00131 
00132 
00133 bool LOW_link::getHasExternalPower() const
00134 {
00135   return hasExternalPower;
00136 }
00137 

Generated on Sun Jan 12 21:07:43 2003 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001