2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 | Copyright (c) 1997-2010 The PHP Group |
7 +----------------------------------------------------------------------+
8 | This source file is subject to version 3.01 of the PHP license, |
9 | that is bundled with this package in the file LICENSE, and is |
10 | available through the world-wide-web at the following url: |
11 | http://www.php.net/license/3_01.txt |
12 | If you did not receive a copy of the PHP license and are unable to |
13 | obtain it through the world-wide-web, please send a note to |
14 | license@php.net so we can mail you a copy immediately. |
15 +----------------------------------------------------------------------+
18 #include "hphp/runtime/ext/asio/asio-external-thread-event.h"
20 #include "hphp/runtime/ext/asio/asio-session.h"
21 #include "hphp/runtime/ext/asio/ext_external-thread-event-wait-handle.h"
24 ///////////////////////////////////////////////////////////////////////////////
26 AsioExternalThreadEvent::AsioExternalThreadEvent(ObjectData
* priv_data
)
27 : m_queue(AsioSession::Get()->getExternalThreadEventQueue()),
30 c_ExternalThreadEventWaitHandle::Create(this, priv_data
).detach();
33 void AsioExternalThreadEvent::abandon() {
34 assertx(m_state
.load() == Waiting
);
35 assertx(m_waitHandle
->hasExactlyOneRef());
36 m_state
.store(Abandoned
);
37 m_waitHandle
->abandon(false);
40 bool AsioExternalThreadEvent::cancel() {
41 uint32_t/*state_t*/ expected(Waiting
);
42 if (m_state
.compare_exchange_strong(expected
, Canceled
)) {
46 assertx(expected
== Finished
);
50 void AsioExternalThreadEvent::markAsFinished() {
51 uint32_t/*state_t*/ expected(Waiting
);
52 if (m_state
.compare_exchange_strong(expected
, Finished
)) {
53 m_finishTime
= AsioSession::TimePoint::clock::now();
55 m_queue
->send(m_waitHandle
);
57 // web request died, destroy object
58 assertx(expected
== Canceled
);
63 ///////////////////////////////////////////////////////////////////////////////