2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
22 namespace HPHP
{ namespace Treadmill
{
24 //////////////////////////////////////////////////////////////////////
27 * List of potentiall users of the treadmill, useful for debugging halts
29 enum class SessionKind
{
54 * An invalid request index.
56 constexpr int64_t kInvalidRequestIdx
= -1;
58 * Return the current thread's index.
63 * The Treadmill allows us to defer work until all currently
64 * outstanding requests have finished. We hook request start and
65 * finish to know when these events happen.
67 void startRequest(SessionKind session_kind
);
71 * Returns the unique GenCount identifying the oldest request in
72 * flight (or zero if there is none).
74 int64_t getOldestRequestGenCount();
77 * Returns the oldest start time in seconds of all requests in flight.
78 * If there are no requests in flight the return value is 0.
79 * The value returned should be used as a conservative and true value
80 * for the oldest start time of any request in flight. In that sense
81 * the value is safe to compare against in a less-than relationship.
83 int64_t getOldestStartTime();
86 * Returns for how long (wall time) the oldest request in flight has
87 * been running, in seconds.
89 int64_t getAgeOldestRequest();
92 * Returns the unique GenCount identifying this request.
94 int64_t getRequestGenCount();
97 * Ask for memory to be freed (as in free, not delete) by the next
98 * appropriate treadmill round.
100 void deferredFree(void*);
103 * Used to get debug information about the treadmill.
105 std::string
dumpTreadmillInfo();
108 * Schedule a function to run on the next appropriate treadmill round.
110 * The function will be called from the base mutex rank.
112 * Note: the function passed here escapes (naturally). If you use a
113 * lambda here, copy things into the lambda by value.
115 * Important: f() must not throw an exception.
117 template<class F
> void enqueue(F
&& f
);
119 struct Session final
{
120 Session(SessionKind session_kind
) { startRequest(session_kind
); }
121 ~Session() { finishRequest(); }
122 Session(Session
&&) = delete;
123 Session
& operator=(Session
&&) = delete;
126 //////////////////////////////////////////////////////////////////////
130 #include "hphp/runtime/vm/treadmill-inl.h"