Codemod asserts to assertxs in the runtime
[hiphop-php.git] / hphp / runtime / ext / asio / asio-external-thread-event.cpp
blob6555643af45580494fa5ea5af4510d9a71d4400e
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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"
19 #include <thread>
20 #include "hphp/runtime/ext/asio/asio-session.h"
21 #include "hphp/runtime/ext/asio/ext_external-thread-event-wait-handle.h"
23 namespace HPHP {
24 ///////////////////////////////////////////////////////////////////////////////
26 AsioExternalThreadEvent::AsioExternalThreadEvent(ObjectData* priv_data)
27 : m_queue(AsioSession::Get()->getExternalThreadEventQueue()),
28 m_state(Waiting) {
29 m_waitHandle =
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)) {
43 return true;
46 assertx(expected == Finished);
47 return false;
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();
54 // transfer ownership
55 m_queue->send(m_waitHandle);
56 } else {
57 // web request died, destroy object
58 assertx(expected == Canceled);
59 release();
63 ///////////////////////////////////////////////////////////////////////////////