Blame view

circus/src/jcircus/classesdescompiladas/AltingBarrierBase.java 5.78 KB
8d0dc533f   Madiel de Souza Conserva Filho   first
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
  // Decompiled by DJ v3.11.11.95 Copyright 2009 Atanas Neshkov  Date: 26/10/2010 13:57:43
  // Home Page: http://members.fortunecity.com/neshkov/dj.html  http://www.neshkov.com/dj.html - Check often for new version!
  // Decompiler options: packimports(3) 
  
  package jcircus.classesdescompiladas;
  
  
  // Referenced classes of package org.jcsp.lang:
  //            AltingBarrier, AltingBarrierError, JCSP_InternalError, AltingBarrierCoordinate
  
  class AltingBarrierBase
  {
  
      AltingBarrierBase()
      {
          frontEnds = null;
          enrolled = 0;
          countdown = 0;
      }
  
      AltingBarrier[] expand(int i)
      {
          AltingBarrier aaltingbarrier[] = new AltingBarrier[i];
          for(int j = 0; j < i; j++)
          {
              frontEnds = new AltingBarrier(this, frontEnds);
              aaltingbarrier[j] = frontEnds;
          }
  
          enrolled += i;
          countdown += i;
          return aaltingbarrier;
      }
  
      AltingBarrier expand()
      {
          enrolled++;
          countdown++;
          frontEnds = new AltingBarrier(this, frontEnds);
          return frontEnds;
      }
  
      void contract(AltingBarrier aaltingbarrier[])
      {
          AltingBarrier altingbarrier = aaltingbarrier[0];
          int i = 0;
          AltingBarrier altingbarrier1 = null;
          AltingBarrier altingbarrier2;
          for(altingbarrier2 = frontEnds; altingbarrier2 != null && altingbarrier2 != altingbarrier; altingbarrier2 = altingbarrier2.next)
              altingbarrier1 = altingbarrier2;
  
          if(altingbarrier2 == null)
              throw new AltingBarrierError("
  *** Could not find first front-end in AltingBarrier contract.");
          aaltingbarrier[0].base = null;
          aaltingbarrier[0] = null;
          for(int j = 1; j < aaltingbarrier.length; j++)
          {
              if(altingbarrier2.enrolled)
                  i++;
              altingbarrier2 = altingbarrier2.next;
              if(altingbarrier2 == null)
                  throw new AltingBarrierError("
  *** Could not find second (or later) front-end in AltingBarrier contract.");
              if(altingbarrier2 != aaltingbarrier[j])
                  throw new AltingBarrierError("
  *** Removal array in AltingBarrier contract not one delivered by expand.");
              aaltingbarrier[j].base = null;
              aaltingbarrier[j] = null;
          }
  
          if(altingbarrier2.enrolled)
              i++;
          if(altingbarrier1 == null)
              frontEnds = altingbarrier2.next;
          else
              altingbarrier1.next = altingbarrier2.next;
          enrolled -= i;
          countdown -= i;
          if(countdown == 0)
          {
              countdown = enrolled;
              if(enrolled > 0)
              {
                  AltingBarrierCoordinate.startEnable();
                  AltingBarrierCoordinate.startDisable(enrolled);
                  for(AltingBarrier altingbarrier3 = frontEnds; altingbarrier3 != null; altingbarrier3 = altingbarrier3.next)
                      altingbarrier3.schedule();
  
              }
          } else
          if(countdown < 0)
              throw new JCSP_InternalError("Please report the circumstances to jcsp-team@kent.ac.uk - thanks!");
      }
  
      void contract(AltingBarrier altingbarrier)
      {
          AltingBarrier altingbarrier1 = null;
          AltingBarrier altingbarrier2;
          for(altingbarrier2 = frontEnds; altingbarrier2 != null && altingbarrier2 != altingbarrier; altingbarrier2 = altingbarrier2.next)
              altingbarrier1 = altingbarrier2;
  
          if(altingbarrier2 == null)
              throw new AltingBarrierError("
  *** Could not find front-end in AltingBarrier contract.");
          if(altingbarrier1 == null)
              frontEnds = altingbarrier2.next;
          else
              altingbarrier1.next = altingbarrier2.next;
          altingbarrier.base = null;
          if(altingbarrier.enrolled)
          {
              enrolled--;
              countdown--;
          }
          if(countdown == 0)
          {
              countdown = enrolled;
              if(enrolled > 0)
              {
                  AltingBarrierCoordinate.startEnable();
                  AltingBarrierCoordinate.startDisable(enrolled);
                  for(AltingBarrier altingbarrier3 = frontEnds; altingbarrier3 != null; altingbarrier3 = altingbarrier3.next)
                      altingbarrier3.schedule();
  
              }
          } else
          if(countdown < 0)
              throw new JCSP_InternalError("Please report the circumstances to jcsp-team@kent.ac.uk - thanks!");
      }
  
      boolean enable()
      {
          countdown--;
          if(countdown == 0)
          {
              countdown = enrolled;
              AltingBarrierCoordinate.startDisable(enrolled);
              for(AltingBarrier altingbarrier = frontEnds; altingbarrier != null; altingbarrier = altingbarrier.next)
                  altingbarrier.schedule();
  
              return true;
          } else
          {
              return false;
          }
      }
  
      boolean disable()
      {
          if(countdown == enrolled)
          {
              return true;
          } else
          {
              countdown++;
              return false;
          }
      }
  
      void resign()
      {
          enrolled--;
          countdown--;
          if(countdown == 0)
          {
              countdown = enrolled;
              if(enrolled > 0)
              {
                  AltingBarrierCoordinate.startEnable();
                  AltingBarrierCoordinate.startDisable(enrolled);
                  for(AltingBarrier altingbarrier = frontEnds; altingbarrier != null; altingbarrier = altingbarrier.next)
                      altingbarrier.schedule();
  
              }
          }
      }
  
      void enroll()
      {
          enrolled++;
          countdown++;
      }
  
      private AltingBarrier frontEnds;
      private int enrolled;
      private int countdown;
  }