Arquivos
hhvm/hphp/runtime/ext/asio/asio_external_thread_event_queue.cpp
T
Todd Nowacki adda9a5022 HPHP Changes for Clang
More changes for HPHP to help make it clang friendly

~~~hphp/compiler/expression/constant_expression.h
~~~hphp/compiler/expression/function_call.h
  rfind returns a size_t/unsigned int

~~~hphp/runtime/base/server/http_protocol.cpp
  Switched to std::to_string. Assuming [] was not intended here

~~~hphp/runtime/base/ref_data.h
  These fields were accessed in a public manner, assuming public was intended
  instead of private

~~~hphp/runtime/base/variable_serializer.cpp
  Switched to using [] and & to make clang happy. Assuming this was to either
  take or drop the first char.

~~~hphp/runtime/ext/asio/asio_external_thread_event_queue.h
~~~hphp/runtime/ext/asio/asio_external_thread_event_queue.cpp
  Cast  which performs the conversions of a reinterpret_cast is not
  allowed in a constant expression. This is been moved to a macro as a temporary
  fix.

+++hphp/runtime/ext/ext_misc.cpp
  Added std::atomic to supress warnings

~~~hphp/runtime/vm/jit/simplifier.cpp
  Chosen constructor is explicit in copy-initialization

~~~hphp/runtime/vm/jit/translator-asm-helpers.S
  Ambiguous instructions require an explicit suffix
  Changed cmp to cmpl

~~~hphp/runtime/vm/jit/translator-x64-helpers.cpp
  Clang does not support global register variables

+++hphp/runtime/vm/unwind.cpp
  describeFault was only used when DEBUG or USE_TRACE was defined

~~~hphp/runtime/vm/verifier/check_unit.cpp
  Made fmt pointer const to avoid string format issues/warnings

~~~hphp/util/stack_trace.cpp
  Clang does not support variable-length arrays.
  Uniqe_ptr is used instead to take advantage runtime-sized arrays, a
  restriced form of variable-length arrays

~~~hphp/util/thread_local.h
  Clang seems to be supporting the __thread attribute, or at the very least
  it is not complaining about it.

~~~hphp/util/tiny_vector.h
  Clang does not like the flexible array here, since T is not always POD.
  I have reimplemented the array here by just sticking one value in the struct
  and calculating the offset from its address manually.
  Alterinatively, we could change the the non-POD types to be pointers, or
  we could edit their implemenations.

+++hphp/util/util.h
  Created a template for the union,
  A function declared with the constexpr specifier cannot contain
  type declarations that do not define classes or enumerations

+++hphp/runtime/vm/jit/x64-util.h
  Added a TODO
  The way hphp/runtime/vm/jit/x64-util.h is currently implemented, it only
  works if USE_GCC_FAST_TLS is defined
2013-06-25 13:19:03 -07:00

130 linhas
4.1 KiB
C++

/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2013 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 "hphp/runtime/ext/asio/asio_external_thread_event_queue.h"
#include "hphp/runtime/ext/ext_asio.h"
#include "hphp/system/systemlib.h"
namespace HPHP {
///////////////////////////////////////////////////////////////////////////////
AsioExternalThreadEventQueue::AsioExternalThreadEventQueue()
: m_received(nullptr), m_queue(nullptr), m_queueMutex(),
m_queueCondition() {
}
/**
* Process all received finished events.
*
* May throw C++ exception that may leave some events unprocessed.
*/
void AsioExternalThreadEventQueue::processAllReceived() {
assert(m_received);
do {
auto ete_wh = m_received;
m_received = m_received->getNextToProcess();
ete_wh->process();
} while (m_received);
}
/**
* Abandon all received finished events.
*
* Returns true iff provided wait handle was abandoned.
*/
bool AsioExternalThreadEventQueue::abandonAllReceived(c_ExternalThreadEventWaitHandle* wait_handle) {
assert(m_received);
bool seen = false;
do {
auto ete_wh = m_received;
m_received = m_received->getNextToProcess();
ete_wh->abandon(true);
seen |= ete_wh == wait_handle;
} while (m_received);
return seen;
}
/**
* Try to receive finished events without blocking.
*
* Returns true iff at least one event was received.
*/
bool AsioExternalThreadEventQueue::tryReceiveSome() {
assert(!m_received);
m_received = m_queue.exchange(nullptr);
assert(m_received != K_CONSUMER_WAITING);
return m_received;
}
/**
* Receive at least one finished event. Block if necessary.
*/
void AsioExternalThreadEventQueue::receiveSome() {
assert(!m_received);
// try receive external thread events without grabbing lock
m_received = m_queue.exchange(nullptr);
if (m_received) {
assert(m_received != K_CONSUMER_WAITING);
return;
}
// no external thread events received, synchronization needed
std::unique_lock<std::mutex> lock(m_queueMutex);
// transition from empty to WAITING
if (m_queue.compare_exchange_strong(m_received, K_CONSUMER_WAITING)) {
// wait for transition from WAITING to non-empty
do {
m_queueCondition.wait(lock);
} while (m_queue.load() == K_CONSUMER_WAITING);
} else {
// external thread transitioned from empty to non-empty while grabbing lock
}
m_received = m_queue.exchange(nullptr);
assert(m_received);
assert(m_received != K_CONSUMER_WAITING);
}
/**
* Send finished event from the processing thread to the web request thread.
*/
void AsioExternalThreadEventQueue::send(c_ExternalThreadEventWaitHandle* wait_handle) {
auto next = m_queue.load();
while (true) {
while (next != K_CONSUMER_WAITING) {
wait_handle->setNextToProcess(next);
if (m_queue.compare_exchange_weak(next, wait_handle)) {
return;
}
}
// try to transition from WAITING to non-empty
wait_handle->setNextToProcess(nullptr);
if (m_queue.compare_exchange_weak(next, wait_handle)) {
// succeeded, notify condition
std::unique_lock<std::mutex> lock(m_queueMutex);
m_queueCondition.notify_one();
return;
}
}
}
///////////////////////////////////////////////////////////////////////////////
}