Android and iOS compatible wakelock implementation.

Refactored thanks to dkovalev@.
768900
function AndroidWakeLock() {
  var video = document.createElement('video');

  video.addEventListener('ended', function() {
    video.play();
  });

  this.request = function() {
    if (video.paused) {
      // Base64 version of videos_src/no-sleep-60s.webm.
      video.src = Util.base64('video/webm', 'GkXfowEAAAAAAAAfQoaBAUL3gQFC8oEEQvOBCEKChHdlYm1Ch4ECQoWBAhhTgGcBAAAAAAAH4xFNm3RALE27i1OrhBVJqWZTrIHfTbuMU6uEFlSua1OsggEwTbuMU6uEHFO7a1OsggfG7AEAAAAAAACkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmAQAAAAAAAEUq17GDD0JATYCNTGF2ZjU2LjQwLjEwMVdBjUxhdmY1Ni40MC4xMDFzpJAGSJTMbsLpDt/ySkipgX1fRImIQO1MAAAAAAAWVK5rAQAAAAAAADuuAQAAAAAAADLXgQFzxYEBnIEAIrWcg3VuZIaFVl9WUDmDgQEj44OEO5rKAOABAAAAAAAABrCBsLqBkB9DtnUBAAAAAAAAo+eBAKOmgQAAgKJJg0IAAV4BHsAHBIODCoAACmH2MAAAZxgz4dPSTFi5JACjloED6ACmAECSnABMQAADYAAAWi0quoCjloEH0ACmAECSnABNwAADYAAAWi0quoCjloELuACmAECSnABNgAADYAAAWi0quoCjloEPoACmAECSnABNYAADYAAAWi0quoCjloETiACmAECSnABNIAADYAAAWi0quoAfQ7Z1AQAAAAAAAJTnghdwo5aBAAAApgBAkpwATOAAA2AAAFotKrqAo5aBA+gApgBAkpwATMAAA2AAAFotKrqAo5aBB9AApgBAkpwATIAAA2AAAFotKrqAo5aBC7gApgBAkpwATEAAA2AAAFotKrqAo5aBD6AApgDAkpwAQ2AAA2AAAFotKrqAo5aBE4gApgBAkpwATCAAA2AAAFotKrqAH0O2dQEAAAAAAACU54Iu4KOWgQAAAKYAQJKcAEvAAANgAABaLSq6gKOWgQPoAKYAQJKcAEtgAANgAABaLSq6gKOWgQfQAKYAQJKcAEsAAANgAABaLSq6gKOWgQu4AKYAQJKcAEqAAANgAABaLSq6gKOWgQ+gAKYAQJKcAEogAANgAABaLSq6gKOWgROIAKYAQJKcAEnAAANgAABaLSq6gB9DtnUBAAAAAAAAlOeCRlCjloEAAACmAECSnABJgAADYAAAWi0quoCjloED6ACmAECSnABJIAADYAAAWi0quoCjloEH0ACmAMCSnABDYAADYAAAWi0quoCjloELuACmAECSnABI4AADYAAAWi0quoCjloEPoACmAECSnABIoAADYAAAWi0quoCjloETiACmAECSnABIYAADYAAAWi0quoAfQ7Z1AQAAAAAAAJTngl3Ao5aBAAAApgBAkpwASCAAA2AAAFotKrqAo5aBA+gApgBAkpwASAAAA2AAAFotKrqAo5aBB9AApgBAkpwAR8AAA2AAAFotKrqAo5aBC7gApgBAkpwAR4AAA2AAAFotKrqAo5aBD6AApgBAkpwAR2AAA2AAAFotKrqAo5aBE4gApgBAkpwARyAAA2AAAFotKrqAH0O2dQEAAAAAAACU54J1MKOWgQAAAKYAwJKcAENgAANgAABaLSq6gKOWgQPoAKYAQJKcAEbgAANgAABaLSq6gKOWgQfQAKYAQJKcAEagAANgAABaLSq6gKOWgQu4AKYAQJKcAEaAAANgAABaLSq6gKOWgQ+gAKYAQJKcAEZAAANgAABaLSq6gKOWgROIAKYAQJKcAEYAAANgAABaLSq6gB9DtnUBAAAAAAAAlOeCjKCjloEAAACmAECSnABF4AADYAAAWi0quoCjloED6ACmAECSnABFwAADYAAAWi0quoCjloEH0ACmAECSnABFoAADYAAAWi0quoCjloELuACmAECSnABFgAADYAAAWi0quoCjloEPoACmAMCSnABDYAADYAAAWi0quoCjloETiACmAECSnABFYAADYAAAWi0quoAfQ7Z1AQAAAAAAAJTngqQQo5aBAAAApgBAkpwARUAAA2AAAFotKrqAo5aBA+gApgBAkpwARSAAA2AAAFotKrqAo5aBB9AApgBAkpwARQAAA2AAAFotKrqAo5aBC7gApgBAkpwARQAAA2AAAFotKrqAo5aBD6AApgBAkpwAROAAA2AAAFotKrqAo5aBE4gApgBAkpwARMAAA2AAAFotKrqAH0O2dQEAAAAAAACU54K7gKOWgQAAAKYAQJKcAESgAANgAABaLSq6gKOWgQPoAKYAQJKcAESAAANgAABaLSq6gKOWgQfQAKYAwJKcAENgAANgAABaLSq6gKOWgQu4AKYAQJKcAERgAANgAABaLSq6gKOWgQ+gAKYAQJKcAERAAANgAABaLSq6gKOWgROIAKYAQJKcAEQgAANgAABaLSq6gB9DtnUBAAAAAAAAlOeC0vCjloEAAACmAECSnABEIAADYAAAWi0quoCjloED6ACmAECSnABEAAADYAAAWi0quoCjloEH0ACmAECSnABD4AADYAAAWi0quoCjloELuACmAECSnABDwAADYAAAWi0quoCjloEPoACmAECSnABDoAADYAAAWi0quoCjloETiACmAECSnABDgAADYAAAWi0quoAcU7trAQAAAAAAABG7j7OBALeK94EB8YIBd/CBAw==');
      video.play();
    }
  };

  this.release = function() {
    video.pause();
    video.src = '';
  };
}
1049665
function Waterlock(){
  events.EventEmitter.call(this);

  this.sails      = global.sails; 

  this.engine     = _.bind(this.engine, this)();
  this.config     = _.bind(this.config, this)();
  this.methods    = _.bind(this.methods, this)().collect();
  this.models     = _.bind(this.models, this)();
  this.actions    = _.bind(this.actions, this)();
  this.cycle      = _.bind(this.cycle, this)();

  // expose jwt so the implementing 
  // app doesn't need to require it.
  this.jwt        = require('jwt-simple');

  this.validator  = _.bind(this.validator, this)();
}
417623
public void wakeup() {    	
        synchronized(worker) {
            if (!started) {            	
                return;
            }
            
            if (!this.isSynchronized) {
                this.isSynchronized = true;
                scheduler.submit(worker,worker.getQueueNumber());
            }
        }
    }
1082047
private void handleAlarm()
  {
    AlarmListener listener = getListener();

    if (listener == null) {
      return;
    }

    Thread thread = Thread.currentThread();
    ClassLoader loader = getContextLoader();

    if (loader != null) {
      thread.setContextClassLoader(loader);
    }
    else {
      thread.setContextClassLoader(_systemLoader);
    }

    try {
      listener.handleAlarm(this);
    } finally {
      thread.setContextClassLoader(_systemLoader);
    }
  }
58958
function(state) {
            if (wakeup !== undefined) {
              midDuration = wakeup.ts - prevSlice.end;
            }

            if (blocked_reason !== undefined) {
              var args = {
                'kernel callsite when blocked:' : blocked_reason.caller
              };
              if (blocked_reason.iowait) {
                switch (state) {
                  case SCHEDULING_STATE.UNINTR_SLEEP:
                    state = SCHEDULING_STATE.UNINTR_SLEEP_IO;
                    break;
                  case SCHEDULING_STATE.UNINTR_SLEEP_WAKE_KILL:
                    state = SCHEDULING_STATE.UNINTR_SLEEP_WAKE_KILL_IO;
                    break;
                  case SCHEDULING_STATE.UNINTR_SLEEP_WAKING:
                    state = SCHEDULING_STATE.UNINTR_SLEEP_WAKE_KILL_IO;
                    break;
                  default:
                }
              }
              slices.push(new tr.model.ThreadTimeSlice(
                  thread,
                  state, '', prevSlice.end, args, midDuration));
            } else {
              slices.push(new tr.model.ThreadTimeSlice(
                  thread,
                  state, '', prevSlice.end, {}, midDuration));
            }
            if (wakeup !== undefined) {
              var wakeupDuration = nextSlice.start - wakeup.ts;
              var args = {'wakeup from tid': wakeup.fromTid};
              slices.push(new tr.model.ThreadTimeSlice(
                  thread, SCHEDULING_STATE.RUNNABLE, '',
                  wakeup.ts, args, wakeupDuration));
              wakeup = undefined;
            }
          }
815852
def on_idle(op, *args)
      @idle_mutex.synchronize {
        @idle.insert(0, Act.new(op, args))
      }
      @loop.wakeup() if RUNNING == @state
    end
892450
def pause_knocks(obj):
    
    if not hasattr(_thread_locals, 'knock_enabled'):
        _thread_locals.knock_enabled = {}
    obj.__class__._disconnect()
    _thread_locals.knock_enabled[obj.__class__] = False
    yield
    _thread_locals.knock_enabled[obj.__class__] = True
    obj.__class__._connect()
908488
public boolean queueAt(Alarm alarm, long wakeTime)
  {
    boolean isEarliest = false;
    
    long prevNextAlarmTime;
    
    do {
      prevNextAlarmTime = _nextAlarmTime.get();
    } while (wakeTime > 0 && wakeTime < prevNextAlarmTime 
             && ! _nextAlarmTime.compareAndSet(prevNextAlarmTime, wakeTime));
    
    if (wakeTime < prevNextAlarmTime) {
      isEarliest = true;
    }
    
    long oldWakeTime = alarm.getAndSetWakeTime(wakeTime);
    
    if (oldWakeTime == wakeTime) {
      return false;
    }
    
    if (oldWakeTime > 0) {
      if (! dequeueImpl(alarm)) {
        /*
        System.out.println("FAIL: " + oldWakeTime + " " + wakeTime
                           + " " + alarm);
                           */
      }
    }
    
    if (wakeTime <= 0) {
      return false;
    }
    
    long now = _now.get();
    
    if (wakeTime <= now) {
      queueCurrent(alarm);
      
      return true;
    }
    
    synchronized (_lock) {
      if (alarm.getBucket() >= 0) {
        return false;
      }
      
      int bucket = getBucket(wakeTime);
      alarm.setBucket(bucket);
    
      Alarm top = _clockArray[bucket];
      alarm.setNext(top);
      _clockArray[bucket] = alarm;
    }
    
    now = _now.get();
    
    long nextWakeTime = alarm.getWakeTime();
    
    if (nextWakeTime != wakeTime || wakeTime < now) {
      dequeueImpl(alarm);
      queueCurrent(alarm);
    }
    
    return isEarliest;
  }
845225
public void tick() throws InterruptedException {
    try (LockResource r = new LockResource(mLock)) {
      HeartbeatScheduler.addTimer(this);
      // Wait in a loop to handle spurious wakeups
      while (!mScheduled) {
        mTickCondition.await();
      }

      mScheduled = false;
    }
  }
1235703
def broadcast
      synchronize do
        @threads.dup.each do |t|
          t.wakeup if t.alive? && t.stop?
        end
      end
    end
659686
def _get_sleep(self, poller, timeout, block, rsock, wsock, cookie):
        
        _vv and IOLOG.debug(
            '%r._get_sleep(timeout=%r, block=%r, rfd=%d, wfd=%d)',
            self, timeout, block, rsock.fileno(), wsock.fileno()
        )

        e = None
        woken = None
        try:
            woken = list(poller.poll(timeout))
        except Exception:
            e = sys.exc_info()[1]

        self._lock.acquire()
        try:
            i = self._sleeping.index((wsock, cookie))
            del self._sleeping[i]
            if not woken:
                raise e or TimeoutError()

            got_cookie = rsock.recv(self.COOKIE_SIZE)
            self._cls_idle_socketpairs.append((rsock, wsock))

            assert cookie == got_cookie, (
                "Cookie incorrect; got %r, expected %r" \
                % (binascii.hexlify(got_cookie),
                   binascii.hexlify(cookie))
            )
            assert i < self._waking, (
                "Cookie correct, but no queue element assigned."
            )
            self._waking -= 1
            if self.closed:
                raise LatchError()
            _vv and IOLOG.debug('%r.get() wake -> %r', self, self._queue[i])
            return self._queue.pop(i)
        finally:
            self._lock.release()
1118442
function() {
            var self = $(this),
                start,
                target;

            /**
             * There's a major bug in Android devices where `touchend` events do not fire
             * without calling `preventDefault()` in `touchstart` or `touchmove`.
             * Because of this, we have to hack-ily implement functionality into `touchmove`.
             * We also can't use `touchcancel` as that fires prematurely and unbinds our move event.
             * More information on these bugs can be found here:
             *
             * https://code.google.com/p/android/issues/detail?id=19827
             * https://code.google.com/p/chromium/issues/detail?id=260732
             *
             * Using `touchcancel` is also rather unpredictable, as described here:
             *
             * http://alxgbsn.co.uk/2011/12/23/different-ways-to-trigger-touchcancel-in-mobile-browsers/
             */
            function move(e) {
                var to = coords(e);

                // Trigger `preventDefault()` if `x` is larger than `y` (scrolling horizontally).
                // If we `preventDefault()` while scrolling vertically, the window will not scroll.
                if (abs(start.x - to.x) > abs(start.y - to.y)) {
                    e.preventDefault();
                }
            }

            /**
             * When `touchend` or `touchcancel` is triggered, clean up the swipe state.
             * Also unbind `touchmove` events until another swipe occurs.
             */
            function cleanup() {
                start = target = null;
                swiping = false;

                self.off(moveEvent, move);
            }

            // Initialize the state when a touch occurs
            self.on(startEvent, function(e) {

                // Calling `preventDefault()` on start will disable clicking of elements (links, inputs, etc)
                // So only do it on an `img` element so it cannot be dragged
                if (!isTouch && e.target.tagName.toLowerCase() === 'img') {
                    e.preventDefault();
                }

                // Exit early if another swipe is occurring
                if (swiping) {
                    return;
                }

                start = coords(e);
                target = e.target;
                swiping = true;

                // Non-touch devices don't make use of the move event
                if (isTouch) {
                    self.on(moveEvent, move);
                }
            });

            // Trigger the swipe event when the touch finishes
            self.on(stopEvent, function(e) {
                swipe(start, coords(e), self, target);
                cleanup();
            });

            // Reset the state when the touch is cancelled
            self.on('touchcancel', cleanup);
        }
155696
function() {
			if ( this.locked ) {
				// Decrease level of lock and check if equals 0, what means that undoM is completely unlocked.
				if ( !--this.locked.level ) {
					var update = this.locked.update;

					this.locked = null;

					// forceUpdate was passed to lock().
					if ( update === true )
						this.update();
					// update is instance of Image.
					else if ( update ) {
						var newImage = new Image( this.editor, true );

						if ( !update.equalsContent( newImage ) )
							this.update();
					}
				}
			}
		}
1054779
def wake(self):
        
        configuration = self._read_configuration()
        self._configuration_register(configuration | 0x0007)
        # 40us delay to recover from powerdown (p14 of spec)
        time.sleep(0.00004)
974073
private void blockMe(int cyclesToBlock) {
	long unblock = cycles + cyclesToBlock;

	BlockedEntry newEntry = new BlockedEntry(unblock);
	blockedCollection.add(newEntry);

	while (unblock > cycles) {
	    try {
		newEntry.getSync().acquire(); // blocks
	    } catch (InterruptedException exc) {
		log.error("[temporaryBlock] Spurious wakeup", exc);
	    }
	}

    }
1104402
@VisibleForTesting
  void setNanoClock(NanoClock clock) {
    Preconditions.checkArgument(clock != null, "clock must not be null!");
    this.clock = clock;
  }
631958
void wakeOut()
  {
    OnAvailable outFlow = _outFlow;
    
    if (outFlow == null) {
      return;
    }
    
    if (_creditsIn <= _queue.head()) {
      return;
    }

    StateOutPipe stateOld;
    StateOutPipe stateNew;
    
    do {
      stateOld = _stateOutRef.get();
      
      if (! stateOld.isFull()) {
        return;
      }
      
      stateNew = stateOld.toWake();
    } while (! _stateOutRef.compareAndSet(stateOld, stateNew));
      
    try (OutboxAmp outbox = OutboxAmp.currentOrCreate(_outRef.services())) {
      Objects.requireNonNull(outbox);
    
      PipeWakeOutMessage<T> msg = new PipeWakeOutMessage<>(outbox, _outRef, this, outFlow);
    
      outbox.offer(msg);
    }
  }