1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef PollableEvent_h__
8 #define PollableEvent_h__
10 #include "mozilla/Mutex.h"
11 #include "mozilla/TimeStamp.h"
18 // class must be called locked
24 // Signal/Clear return false only if they fail
26 // This is called only when we get non-null out_flags for the socket pair
28 bool Valid() { return mWriteFD
&& mReadFD
; }
30 // We want to detect if writing to one of the socket pair sockets takes
31 // too long to be received by the other socket from the pair.
32 // Hence, we remember the timestamp of the earliest write by a call to
33 // MarkFirstSignalTimestamp() from Signal(). After waking up from poll()
34 // we check how long it took get the 'readable' signal on the socket pair.
35 void MarkFirstSignalTimestamp();
36 // Called right before we enter poll() to exclude any possible delay between
37 // the earlist call to Signal() and entering poll() caused by processing
38 // of events dispatched to the socket transport thread.
39 void AdjustFirstSignalTimestamp();
40 // This returns false on following conditions:
41 // - PR_Write has failed
42 // - no out_flags were signalled on the socket pair for too long after
43 // the earliest Signal()
44 bool IsSignallingAlive(TimeDuration
const& timeout
);
46 PRFileDesc
* PollableFD() { return mReadFD
; }
49 PRFileDesc
* mWriteFD
{nullptr};
50 PRFileDesc
* mReadFD
{nullptr};
51 bool mSignaled
{false};
52 // true when PR_Write to the socket pair has failed (status < 1)
53 bool mWriteFailed
{false};
54 // Set true after AdjustFirstSignalTimestamp() was called
55 // Set false after Clear() was called
56 // Ensures shifting the timestamp before entering poll() only once
57 // between Clear()'ings.
58 bool mSignalTimestampAdjusted
{false};
59 // Timestamp of the first call to Signal() (or time we enter poll())
60 // that happened after the last Clear() call
61 TimeStamp mFirstSignalAfterClear
;
65 } // namespace mozilla