Arquivos
hhvm/hphp/runtime/ext/ext_asio.cpp
T
Philippe Ajoux e551d3918f add hooks to ASIO to allow building of dependency graphs in PHP
In order to build a dependency graph of continuation execution and data-fetching in PHP-land, we need a few instrumentation points in the asio_ext HHVM extension. There are 4 additions required:
   1. Callback when a continuation finishes successfully.
   2. Callback when a continuation blocks on a wait_handle.
   3. Get array of WaitHandles a GenArrayWaitHandle is waiting on.
   4. Get WaitHandle that the SetResultToRefWaitHandle is waiting on.
I don't think this should really affect performance, as in the normal case, nothing has changed, but you never know... I'm also not sure who should be reviewing this, so I've just added @jan for now. If you could pile other people on, that would be cool.

sandcastle appears to be broken.
2013-05-09 11:33:20 -07:00

69 linhas
2.7 KiB
C++

/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010- Facebook, Inc. (http://www.facebook.com) |
| Copyright (c) 1997-2010 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#include <runtime/ext/ext_asio.h>
#include <runtime/ext/ext_closure.h>
#include <runtime/ext/asio/asio_context.h>
#include <runtime/ext/asio/asio_session.h>
#include <system/lib/systemlib.h>
namespace HPHP {
///////////////////////////////////////////////////////////////////////////////
int f_asio_get_current_context_idx() {
return AsioSession::Get()->getCurrentContextIdx();
}
Object f_asio_get_running_in_context(int ctx_idx) {
auto session = AsioSession::Get();
if (ctx_idx <= 0) {
Object e(SystemLib::AllocInvalidArgumentExceptionObject(
"Expected ctx_idx to be a positive integer"));
throw e;
}
if (ctx_idx > session->getCurrentContextIdx()) {
Object e(SystemLib::AllocInvalidArgumentExceptionObject(
"Expected ctx_idx to be less than or equal to the current context index"));
throw e;
}
assert(session->getContext(ctx_idx));
assert(session->getContext(ctx_idx)->isRunning());
return session->getContext(ctx_idx)->getCurrent();
}
Object f_asio_get_running() {
return AsioSession::Get()->getCurrentWaitHandle();
}
void f_asio_set_on_failed_callback(CVarRef on_failed_cb) {
if (!on_failed_cb.isNull() && !on_failed_cb.instanceof(c_Closure::s_cls)) {
Object e(SystemLib::AllocInvalidArgumentExceptionObject(
"Unable to set asio on failed callback: on_failed_cb not a closure"));
throw e;
}
AsioSession::Get()->setOnFailedCallback(on_failed_cb.getObjectDataOrNull());
}
void f_asio_set_on_started_callback(CVarRef on_started_cb) {
c_ContinuationWaitHandle::ti_setoncreatecallback(on_started_cb);
}
///////////////////////////////////////////////////////////////////////////////
}