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

Last change on this file since 759 was 732, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 2.3 KB
Line 
1#include "sdolist.h"
2
3#include <iostream.h>
4
5PendingSDOList::PendingSDOList()
6{
7 fFirst = new PendingSDO;
8 fLast = fFirst;
9
10 pthread_mutex_init(&fMux, NULL);
11}
12
13PendingSDOList::~PendingSDOList()
14{
15 // pthread_mutex_lock(&fMux);
16
17 DelAll();
18 delete fFirst;
19
20 pthread_mutex_destroy(&fMux);
21}
22
23void PendingSDOList::DelAll()
24{
25 pthread_mutex_lock(&fMux);
26
27 PendingSDO *prev = fFirst;
28 PendingSDO *sdo;
29
30 do
31 {
32 sdo = prev->Next;
33 delete prev;
34
35 } while((prev=sdo));
36
37 fFirst = new PendingSDO;
38 fLast = fFirst;
39
40 pthread_mutex_unlock(&fMux);
41}
42
43void PendingSDOList::Add(BYTE_t node, WORD_t idx, BYTE_t subidx)
44{
45 PendingSDO *sdo = fFirst;
46
47 pthread_mutex_lock(&fMux);
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 pthread_mutex_unlock(&fMux);
60}
61
62void PendingSDOList::Del(BYTE_t node, WORD_t idx, BYTE_t subidx)
63{
64 PendingSDO *prev = fFirst;
65 PendingSDO *sdo;
66
67 pthread_mutex_lock(&fMux);
68 while ((sdo=prev->Next))
69 {
70 if (sdo->Node!=node || sdo->Idx!=idx || sdo->Subidx!=subidx)
71 {
72 prev = sdo;
73 continue;
74 }
75
76 prev->Next = sdo->Next;
77
78 delete sdo;
79
80 if (!prev->Next)
81 fLast = prev;
82
83 break;
84 }
85 pthread_mutex_unlock(&fMux);
86}
87
88int PendingSDOList::IsPending()
89{
90 return (int)fFirst->Next;
91}
92
93int PendingSDOList::IsPending(BYTE_t node)
94{
95 int rc = FALSE;
96 PendingSDO *sdo = fFirst;
97
98 pthread_mutex_lock(&fMux);
99 while ((sdo=sdo->Next))
100 if (sdo->Node==node)
101 {
102 rc = TRUE;
103 break;
104 }
105 pthread_mutex_unlock(&fMux);
106
107 return rc;
108}
109
110int PendingSDOList::IsPending(BYTE_t node, WORD_t idx, BYTE_t subidx)
111{
112 int rc = FALSE;
113 PendingSDO *sdo = fFirst;
114
115 pthread_mutex_lock(&fMux);
116 while ((sdo=sdo->Next))
117 if (sdo->Node==node && sdo->Idx==idx && sdo->Subidx==subidx)
118 {
119 rc = TRUE;
120 break;
121 }
122 pthread_mutex_unlock(&fMux);
123
124 return rc;
125}
Note: See TracBrowser for help on using the repository browser.