00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "LOW_link.h"
00020 #include "LOW_helper_msglog.h"
00021
00022
00023
00024
00025
00026
00027
00028 LOW_link::linkID_t LOW_link::linkCounter = 0;
00029
00030
00031
00032
00033
00034
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
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 ) {
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
00113
00114
00115 bool LOW_link::operator==(LOW_link &inLink) const
00116 {
00117 return (linkID==inLink.linkID);
00118 }
00119
00120
00121
00122
00123
00124
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