source: trunk/MagicSoft/Cosy/candrv/sdolist.cc@ 8015

Last change on this file since 8015 was 4076, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 3.1 KB
Line 
1#include "sdolist.h"
2
3#include <iostream.h>
4
5ClassImp(PendingSDO);
6ClassImp(PendingSDOList);
7
8PendingSDOList::PendingSDOList()
9{
10 fFirst = new PendingSDO;
11 fLast = fFirst;
12}
13
14PendingSDOList::~PendingSDOList()
15{
16 DelAll();
17 delete fFirst;
18}
19
20void PendingSDOList::DelAll()
21{
22 if (fMux.Lock()==13)
23 cout << "PendingSDOList::DelAll - mutex is already locked by this thread" << endl;
24
25 PendingSDO *prev = fFirst;
26 PendingSDO *sdo;
27
28 do
29 {
30 sdo = prev->Next;
31 delete prev;
32
33 } while((prev=sdo));
34
35 fFirst = new PendingSDO;
36 fLast = fFirst;
37
38 if (fMux.UnLock()==13)
39 cout << "PendingSDOList::DelAll - tried to unlock mutex locked by other thread." << endl;
40}
41
42void PendingSDOList::Add(BYTE_t node, WORD_t idx, BYTE_t subidx)
43{
44 PendingSDO *sdo = fFirst;
45
46 if (fMux.Lock()==13)
47 cout << "PendingSDOList::Add - mutex is already locked by this thread" << endl;
48 while ((sdo=sdo->Next))
49 if (sdo->Node==node && sdo->Idx==idx && sdo->Subidx==subidx)
50 {
51 cout << "Warning: SDO Node #" << dec << (int)node << ", 0x";
52 cout << hex << idx << "/" << (int)subidx;
53 cout << " still pending." << endl;
54 break;
55 }
56
57 fLast->Next = new PendingSDO(node, idx, subidx);
58 fLast = fLast->Next;
59 if (fMux.UnLock()==13)
60 cout << "PendingSDOList::Add - tried to unlock mutex locked by other thread." << endl;
61}
62
63void PendingSDOList::Del(BYTE_t node, WORD_t idx, BYTE_t subidx)
64{
65 PendingSDO *prev = fFirst;
66 PendingSDO *sdo;
67
68 if (fMux.Lock()==13)
69 cout << "PendingSDOList::Del - mutex is already locked by this thread" << endl;
70 while ((sdo=prev->Next))
71 {
72 if (sdo->Node!=node || sdo->Idx!=idx || sdo->Subidx!=subidx)
73 {
74 prev = sdo;
75 continue;
76 }
77
78 prev->Next = sdo->Next;
79
80 delete sdo;
81
82 if (!prev->Next)
83 fLast = prev;
84
85 break;
86 }
87 if (fMux.UnLock()==13)
88 cout << "PendingSDOList::Del - tried to unlock mutex locked by other thread." << endl;
89}
90
91int PendingSDOList::IsPending() const
92{
93 return (int)fFirst->Next;
94}
95
96int PendingSDOList::IsPending(BYTE_t node)
97{
98 int rc = FALSE;
99 PendingSDO *sdo = fFirst;
100
101 if (fMux.Lock()==13)
102 cout << "PendingSDOList::IsPending(byte) - mutex is already locked by this thread" << endl;
103 while ((sdo=sdo->Next))
104 if (sdo->Node==node)
105 {
106 rc = TRUE;
107 break;
108 }
109 if (fMux.UnLock()==13)
110 cout << "PendingSDOList::IsPending(byte) - tried to unlock mutex locked by other thread." << endl;
111
112 return rc;
113}
114
115int PendingSDOList::IsPending(BYTE_t node, WORD_t idx, BYTE_t subidx)
116{
117 int rc = FALSE;
118 PendingSDO *sdo = fFirst;
119
120 if (fMux.Lock()==13)
121 cout << "PendingSDOList::IsPending - mutex is already locked by this thread" << endl;
122 while ((sdo=sdo->Next))
123 if (sdo->Node==node && sdo->Idx==idx && sdo->Subidx==subidx)
124 {
125 rc = TRUE;
126 break;
127 }
128 if (fMux.UnLock()==13)
129 cout << "PendingSDOList::IsPending - tried to unlock mutex locked by other thread." << endl;
130
131 return rc;
132}
Note: See TracBrowser for help on using the repository browser.