110 static const int _maxlevel = 8;
111 static const int _shift = 2;
112 static const int _mask = (1<<_shift) - 1;
113 static const int RAND_IA = 16807;
114 static const int RAND_IQ = 127773;
115 static const int RAND_IR = 2836;
128 : AsyncEventRef (event) {
136 _next[0] = _prev[0] =
this;
137 memset (&_prio, 0,
sizeof _prio);
143 inline void Insert (AsyncEvent *event, C prio) {
145 long int tmp = _rand/RAND_IQ;
146 _rand = tmp = RAND_IA*(_rand - tmp*RAND_IQ) - RAND_IR*tmp;
149 tmp ^= tmp >>_maxlevel*_shift;
153 while ( level < _maxlevel && level <= _level && (tmp & _mask) == _mask ) {
158 if ( level > _level ) {
162 _next[_level] = _prev[_level] =
this;
168 _freelist = newq->_next[0];
171 newq->_level = level;
185 while ( --level >= 0 ) {
194 if ( prev != pred ) {
199 while ( comp.preceeds (prev->_prio) ) {
201 prev = succ->_prev[level];
211 if ( level < newq->_level ) {
212 newq->_next[level] = succ;
213 newq->_prev[level] = prev;
214 succ->_prev[level] = newq;
215 pred->_next[level] = newq;
220 inline virtual void extract () {
222 while ( --level >= 0 ) {
223 _next[level]->_prev[level] = _prev[level];
224 _prev[level]->_next[level] = _next[level];
226 _next[0] = _freelist;
230 inline AsyncEvent *First (
const C prio) {
235 if ( _next[0] ==
this || comp.preceeds (_next[0]->_prio) )
238 return _next[0]->Extract();
241 inline AsyncEvent *First () {
244 if ( _next[0] ==
this )
247 return _next[0]->Extract();
250 inline bool HasEvents () {
251 return _next[0] !=
this;
254 inline const C *NextPrio () {
255 if ( _next[0] ==
this )
258 return &_next[0]->_prio;