Refactor back ends into implementations of BackEnd.
[hiphop-php.git] / hphp / runtime / vm / treadmill.h
blob6e9ae0346eaa649fa66ba7067118bccd599b00d1
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 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 #ifndef incl_HPHP_TREADMILL_H_
18 #define incl_HPHP_TREADMILL_H_
20 #include <stdint.h>
21 #include <memory>
23 namespace HPHP { namespace Treadmill {
25 //////////////////////////////////////////////////////////////////////
28 * The Treadmill allows us to defer work until all currently
29 * outstanding requests have finished. We hook request start and
30 * finish to know when these events happen.
32 void startRequest();
33 void finishRequest();
36 * Returns the oldest start time in seconds of all requests in flight.
37 * If there are no requests in flight the return value is 0.
38 * The value returned should be used as a conservative and true value
39 * for the oldest start time of any request in flight. In that sense
40 * the value is safe to compare against in a less-than relationship.
42 int64_t getOldestStartTime();
45 * Ask for memory to be freed (as in free, not delete) by the next
46 * appropriate treadmill round.
48 void deferredFree(void*);
51 * Schedule a function to run on the next appropriate treadmill round.
53 * The function will be called from the base mutex rank.
55 * Note: the function passed here escapes (naturally). If you use a
56 * lambda here, copy things into the lambda by value.
58 * Important: f() must not throw an exception.
60 template<class F> void enqueue(F&& f);
62 //////////////////////////////////////////////////////////////////////
66 #include "hphp/runtime/vm/treadmill-inl.h"
68 #endif