Optimize struct element initialization
[hiphop-php.git] / hphp / runtime / vm / treadmill.h
blobe9380d0b1f05991163839f49e74f7ae833578699
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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 +----------------------------------------------------------------------+
17 #pragma once
19 #include <stdint.h>
20 #include <memory>
22 namespace HPHP { namespace Treadmill {
24 //////////////////////////////////////////////////////////////////////
27 * List of potentiall users of the treadmill, useful for debugging halts
29 enum class SessionKind {
30 None,
31 DebuggerClient,
32 PreloadRepo,
33 Watchman,
34 Vsdebug,
35 FactsWorker,
36 CLIServer,
37 AdminPort,
38 HttpRequest,
39 RpcRequest,
40 TranslateWorker,
41 Retranslate,
42 RetranslateAll,
43 ProfData,
44 UnitTests,
45 CompileRepo,
46 HHBBC,
47 CompilerEmit,
48 CompilerAnalysis,
49 CLISession,
50 UnitReaper
54 * An invalid request index.
56 constexpr int64_t kInvalidRequestIdx = -1;
58 * Return the current thread's index.
60 int64_t requestIdx();
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);
68 void finishRequest();
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"