You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2012/07/11 02:20:23 UTC
svn commit: r1359961 [2/2] - in /incubator/mesos/trunk: src/master/
src/slave/ third_party/libprocess/ third_party/libprocess/examples/
third_party/libprocess/include/process/ third_party/libprocess/src/
Modified: incubator/mesos/trunk/third_party/libprocess/include/process/process.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/process/process.hpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/process/process.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/process/process.hpp Wed Jul 11 00:20:22 2012
@@ -16,6 +16,7 @@
#include <process/message.hpp>
#include <process/mime.hpp>
#include <process/pid.hpp>
+#include <process/thread.hpp>
namespace process {
@@ -116,22 +117,26 @@ protected:
// The default visit implementation for HTTP events invokes
// installed HTTP handlers. A HTTP handler is any function which
- // takes an HttpRequest object and returns and HttpResponse.
- typedef std::tr1::function<Future<HttpResponse>(const HttpRequest&)>
+ // takes an http::Request object and returns an http::Response.
+ typedef std::tr1::function<Future<http::Response>(const http::Request&)>
HttpRequestHandler;
// Setup a handler for an HTTP request.
- void route(
+ bool route(
const std::string& name,
const HttpRequestHandler& handler)
{
- handlers.http[name] = handler;
+ if (name.find('/') != 0) {
+ return false;
+ }
+ handlers.http[name.substr(1)] = handler;
+ return true;
}
template <typename T>
- void route(
+ bool route(
const std::string& name,
- Future<HttpResponse> (T::*method)(const HttpRequest&))
+ Future<http::Response> (T::*method)(const http::Request&))
{
// Note that we use dynamic_cast here so a process can use
// multiple inheritance if it sees so fit (e.g., to implement
@@ -139,7 +144,7 @@ protected:
HttpRequestHandler handler =
std::tr1::bind(method, dynamic_cast<T*>(this),
std::tr1::placeholders::_1);
- route(name, handler);
+ return route(name, handler);
}
// Provide the static asset(s) at the specified _absolute_ path for
@@ -278,7 +283,7 @@ PID<T> spawn(T& t, bool manage = false)
* future we plan to make this more explicit via the use of a PID
* instead of a UPID).
*
- * @param inject if true message will be put on front of messae queue
+ * @param inject if true message will be put on front of message queue
*/
void terminate(const UPID& pid, bool inject = true);
void terminate(const ProcessBase& process, bool inject = true);
@@ -335,6 +340,14 @@ inline bool wait(const ProcessBase* proc
return wait(process->self(), secs);
}
+
+// Per thread process pointer. The extra level of indirection from
+// _process_ to __process__ is used in order to take advantage of the
+// ThreadLocal operators without needing the extra dereference.
+extern ThreadLocal<ProcessBase>* _process_;
+
+#define __process__ (*_process_)
+
} // namespace process {
#endif // __PROCESS_PROCESS_HPP__
Copied: incubator/mesos/trunk/third_party/libprocess/include/process/thread.hpp (from r1359937, incubator/mesos/trunk/third_party/libprocess/src/thread.hpp)
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/process/thread.hpp?p2=incubator/mesos/trunk/third_party/libprocess/include/process/thread.hpp&p1=incubator/mesos/trunk/third_party/libprocess/src/thread.hpp&r1=1359937&r2=1359961&rev=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/src/thread.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/process/thread.hpp Wed Jul 11 00:20:22 2012
@@ -2,18 +2,25 @@
#define __PROCESS_THREAD_HPP__
#include <pthread.h>
-
-#include <glog/logging.h>
+#include <stdio.h> // For perror.
+#include <stdlib.h> // For abort.
template <typename T>
struct ThreadLocal
{
- explicit ThreadLocal(pthread_key_t _key) : key(_key) {}
+ ThreadLocal()
+ {
+ if (pthread_key_create(&key, NULL) != 0) {
+ perror("Failed to create thread local, pthread_key_create");
+ abort();
+ }
+ }
ThreadLocal<T>& operator = (T* t)
{
if (pthread_setspecific(key, t) != 0) {
- PLOG(FATAL) << "Failed to set thread local, pthread_setspecific";
+ perror("Failed to set thread local, pthread_setspecific");
+ abort();
}
return *this;
}
@@ -36,7 +43,7 @@ private:
bool operator < (const ThreadLocal<T>&) const;
bool operator > (const ThreadLocal<T>&) const;
- const pthread_key_t key;
+ pthread_key_t key;
};
#endif // __PROCESS_THREAD_HPP__
Modified: incubator/mesos/trunk/third_party/libprocess/src/decoder.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/src/decoder.hpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/src/decoder.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/src/decoder.hpp Wed Jul 11 00:20:22 2012
@@ -37,7 +37,7 @@ public:
parser.data = this;
}
- std::deque<HttpRequest*> decode(const char* data, size_t length)
+ std::deque<http::Request*> decode(const char* data, size_t length)
{
size_t parsed = http_parser_execute(&parser, &settings, data, length);
@@ -46,12 +46,12 @@ public:
}
if (!requests.empty()) {
- std::deque<HttpRequest*> result = requests;
+ std::deque<http::Request*> result = requests;
requests.clear();
return result;
}
- return std::deque<HttpRequest*>();
+ return std::deque<http::Request*>();
}
bool failed() const
@@ -76,7 +76,7 @@ private:
decoder->value.clear();
assert(decoder->request == NULL);
- decoder->request = new HttpRequest();
+ decoder->request = new http::Request();
decoder->request->headers.clear();
decoder->request->method.clear();
decoder->request->path.clear();
@@ -99,7 +99,7 @@ private:
static int on_message_complete(http_parser* p)
{
DataDecoder* decoder = (DataDecoder*) p->data;
-// std::cout << "HttpRequest:" << std::endl;
+// std::cout << "http::Request:" << std::endl;
// std::cout << " method: " << decoder->request->method << std::endl;
// std::cout << " path: " << decoder->request->path << std::endl;
decoder->requests.push_back(decoder->request);
@@ -188,9 +188,9 @@ private:
std::string field;
std::string value;
- HttpRequest* request;
+ http::Request* request;
- std::deque<HttpRequest*> requests;
+ std::deque<http::Request*> requests;
};
} // namespace process {
Modified: incubator/mesos/trunk/third_party/libprocess/src/encoder.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/src/encoder.hpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/src/encoder.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/src/encoder.hpp Wed Jul 11 00:20:22 2012
@@ -5,6 +5,7 @@
#include <sstream>
+#include <process/http.hpp>
#include <process/process.hpp>
#include "foreach.hpp"
@@ -110,10 +111,10 @@ private:
class HttpResponseEncoder : public DataEncoder
{
public:
- HttpResponseEncoder(const HttpResponse& response)
+ HttpResponseEncoder(const http::Response& response)
: DataEncoder(encode(response)) {}
- static std::string encode(const HttpResponse& response)
+ static std::string encode(const http::Response& response)
{
std::ostringstream out;
Modified: incubator/mesos/trunk/third_party/libprocess/src/foreach.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/src/foreach.hpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/src/foreach.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/src/foreach.hpp Wed Jul 11 00:20:22 2012
@@ -27,9 +27,9 @@
#define foreachpair BOOST_FOREACH_PAIR
#define foreachkey(VAR, COL) \
- foreachpair (VAR, boost::tuples::ignore, COL)
+ foreach (boost::tuples::tie(VAR, boost::tuples::ignore), COL)
#define foreachvalue(VAR, COL) \
- foreachpair (boost::tuples::ignore, VAR, COL)
+ foreach (boost::tuples::tie(boost::tuples::ignore, VAR), COL)
#endif // __FOREACH_HPP__
Modified: incubator/mesos/trunk/third_party/libprocess/src/process.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/src/process.cpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/src/process.cpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/src/process.cpp Wed Jul 11 00:20:22 2012
@@ -57,6 +57,7 @@
#include <process/mime.hpp>
#include <process/process.hpp>
#include <process/socket.hpp>
+#include <process/thread.hpp>
#include <process/timer.hpp>
#include "config.hpp"
@@ -65,9 +66,15 @@
#include "foreach.hpp"
#include "gate.hpp"
#include "synchronized.hpp"
-#include "thread.hpp"
#include "tokenize.hpp"
+using process::http::BadRequest;
+using process::http::InternalServerError;
+using process::http::NotFound;
+using process::http::OK;
+using process::http::Request;
+using process::http::Response;
+using process::http::ServiceUnavailable;
using std::deque;
using std::find;
@@ -242,18 +249,18 @@ public:
// Enqueues the response to be sent once all previously enqueued
// responses have been processed (e.g., waited for and sent).
- void enqueue(const HttpResponse& response, bool persist);
+ void enqueue(const Response& response, bool persist);
// Enqueues a future to a response that will get waited on (up to
// some timeout) and then sent once all previously enqueued
// responses have been processed (e.g., waited for and sent).
- void handle(Future<HttpResponse>* future, bool persist);
+ void handle(Future<Response>* future, bool persist);
private:
void next();
- void waited(const Future<HttpResponse>& future);
- void timedout(const Future<HttpResponse>& future);
- void process(Future<HttpResponse>* future, bool persist);
+ void waited(const Future<Response>& future);
+ void timedout(const Future<Response>& future);
+ void process(Future<Response>* future, bool persist);
Socket socket; // Wrap the socket to keep it from getting closed.
@@ -261,7 +268,7 @@ private:
// and whether or not the socket should be persisted (vs closed).
struct Item
{
- Item(Future<HttpResponse>* _future, bool _persist)
+ Item(Future<Response>* _future, bool _persist)
: future(_future), persist(_persist) {}
~Item()
@@ -269,7 +276,7 @@ private:
delete future;
}
- Future<HttpResponse>* future;
+ Future<Response>* future;
bool persist;
};
@@ -292,7 +299,7 @@ public:
PID<HttpProxy> proxy(int s);
void send(Encoder* encoder, int s, bool persist);
- void send(const HttpResponse& response, int s, bool persist);
+ void send(const Response& response, int s, bool persist);
void send(Message* message);
Encoder* next(int s);
@@ -349,7 +356,7 @@ public:
bool handle(
const Socket& socket,
- HttpRequest* request,
+ Request* request,
ProcessBase* sender = NULL);
bool deliver(
@@ -438,16 +445,6 @@ static bool pending_timers = false;
// Flag to indicate whether or to update the timer on async interrupt.
static bool update_timer = false;
-
-// Thread local process pointer magic (constructed in
-// 'initialize'). We need the extra level of indirection from
-// _process_ to __process__ so that we can take advantage of the
-// operators without needing the extra dereference.
-static ThreadLocal<ProcessBase>* _process_ = NULL;
-
-#define __process__ (*_process_)
-
-
// Scheduling gate that threads wait at when there is nothing to run.
static Gate* gate = new Gate();
@@ -460,6 +457,12 @@ static synchronizable(filterer) = SYNCHR
// Global garbage collector.
PID<GarbageCollector> gc;
+// Per thread process pointer.
+ThreadLocal<ProcessBase>* _process_ = new ThreadLocal<ProcessBase>();
+
+// Per thread executor pointer.
+ThreadLocal<Executor>* _executor_ = new ThreadLocal<Executor>();
+
// We namespace the clock related variables to keep them well
// named. In the future we'll probably want to associate a clock with
@@ -654,7 +657,7 @@ static void transport(Message* message,
}
-static bool libprocess(HttpRequest* request)
+static bool libprocess(Request* request)
{
return request->method == "POST" &&
request->headers.count("User-Agent") > 0 &&
@@ -662,7 +665,7 @@ static bool libprocess(HttpRequest* requ
}
-static Message* parse(HttpRequest* request)
+static Message* parse(Request* request)
{
// TODO(benh): Do better error handling (to deal with a malformed
// libprocess message, malicious or otherwise).
@@ -748,7 +751,8 @@ void handle_timeouts(struct ev_loop* loo
VLOG(1) << "Handling timeouts up to "
<< std::fixed << std::setprecision(9) << now;
- foreachkey (double timeout, *timeouts) {
+ double timeout;
+ foreachkey (timeout, *timeouts) {
if (timeout > now) {
break;
}
@@ -866,10 +870,10 @@ void recv_data(struct ev_loop* loop, ev_
CHECK(length > 0);
// Decode as much of the data as possible into HTTP requests.
- const deque<HttpRequest*>& requests = decoder->decode(data, length);
+ const deque<Request*>& requests = decoder->decode(data, length);
if (!requests.empty()) {
- foreach (HttpRequest* request, requests) {
+ foreach (Request* request, requests) {
process_manager->handle(decoder->socket(), request);
}
} else if (requests.empty() && decoder->failed()) {
@@ -1136,8 +1140,6 @@ void* serve(void* arg)
void* schedule(void* arg)
{
- __process__ = NULL; // Start off not running anything.
-
do {
ProcessBase* process = process_manager->dequeue();
if (process == NULL) {
@@ -1227,14 +1229,6 @@ void initialize(const string& delegate)
process_manager = new ProcessManager(delegate);
socket_manager = new SocketManager();
- // Setup the thread local process pointer.
- pthread_key_t key;
- if (pthread_key_create(&key, NULL) != 0) {
- LOG(FATAL) << "Failed to initialize, pthread_key_create";
- }
-
- _process_ = new ThreadLocal<ProcessBase>(key);
-
// Setup processing threads.
long cpus = sysconf(_SC_NPROCESSORS_ONLN);
@@ -1408,13 +1402,13 @@ HttpProxy::~HttpProxy()
}
-void HttpProxy::enqueue(const HttpResponse& response, bool persist)
+void HttpProxy::enqueue(const Response& response, bool persist)
{
- handle(new Future<HttpResponse>(response), persist);
+ handle(new Future<Response>(response), persist);
}
-void HttpProxy::handle(Future<HttpResponse>* future, bool persist)
+void HttpProxy::handle(Future<Response>* future, bool persist)
{
items.push(new Item(future, persist));
@@ -1445,7 +1439,7 @@ void HttpProxy::next()
}
-void HttpProxy::waited(const Future<HttpResponse>& future)
+void HttpProxy::waited(const Future<Response>& future)
{
if (items.size() > 0) { // The timer might have already fired.
Item* item = items.front();
@@ -1457,8 +1451,7 @@ void HttpProxy::waited(const Future<Http
} else {
// TODO(benh): Consider handling other "states" of future
// (discarded, failed, etc) with different HTTP statuses.
- socket_manager->send(
- HttpServiceUnavailableResponse(), socket, item->persist);
+ socket_manager->send(ServiceUnavailable(), socket, item->persist);
}
items.pop();
@@ -1470,13 +1463,12 @@ void HttpProxy::waited(const Future<Http
}
-void HttpProxy::timedout(const Future<HttpResponse>& future)
+void HttpProxy::timedout(const Future<Response>& future)
{
if (items.size() > 0) { // We might not have been able to cancel the timer.
Item* item = items.front();
if (future == *item->future) {
- socket_manager->send(
- HttpServiceUnavailableResponse(), socket, item->persist);
+ socket_manager->send(ServiceUnavailable(), socket, item->persist);
items.pop();
delete item;
}
@@ -1486,11 +1478,11 @@ void HttpProxy::timedout(const Future<Ht
}
-void HttpProxy::process(Future<HttpResponse>* future, bool persist)
+void HttpProxy::process(Future<Response>* future, bool persist)
{
CHECK(future->isReady());
- HttpResponse response = future->get();
+ Response response = future->get();
// Don't persist connection if headers include 'Connection: close'.
if (response.headers.count("Connection") > 0) {
@@ -1501,7 +1493,7 @@ void HttpProxy::process(Future<HttpRespo
}
// If the response specifies a path, try and perform a sendfile.
- if (response.type == HttpResponse::PATH) {
+ if (response.type == Response::PATH) {
// Make sure no body is sent (this is really an error and
// should be reported and no response sent.
response.body.clear();
@@ -1511,25 +1503,21 @@ void HttpProxy::process(Future<HttpRespo
if (fd < 0) {
if (errno == ENOENT || errno == ENOTDIR) {
VLOG(1) << "Returning '404 Not Found' for path '" << path << "'";
- socket_manager->send(
- HttpNotFoundResponse(), socket, persist);
+ socket_manager->send(NotFound(), socket, persist);
} else {
const char* error = strerror(errno);
VLOG(1) << "Failed to send file at '" << path << "': " << error;
- socket_manager->send(
- HttpInternalServerErrorResponse(), socket, persist);
+ socket_manager->send(InternalServerError(), socket, persist);
}
} else {
struct stat s; // Need 'struct' because of function named 'stat'.
if (fstat(fd, &s) != 0) {
const char* error = strerror(errno);
VLOG(1) << "Failed to send file at '" << path << "': " << error;
- socket_manager->send(
- HttpInternalServerErrorResponse(), socket, persist);
+ socket_manager->send(InternalServerError(), socket, persist);
} else if (S_ISDIR(s.st_mode)) {
VLOG(1) << "Returning '404 Not Found' for directory '" << path << "'";
- socket_manager->send(
- HttpNotFoundResponse(), socket, persist);
+ socket_manager->send(NotFound(), socket, persist);
} else {
// While the user is expected to properly set a 'Content-Type'
// header, we fill in the 'Content-Length' header.
@@ -1726,7 +1714,7 @@ void SocketManager::send(Encoder* encode
}
-void SocketManager::send(const HttpResponse& response, int s, bool persist)
+void SocketManager::send(const Response& response, int s, bool persist)
{
send(new HttpResponseEncoder(response), s, persist);
}
@@ -1923,7 +1911,7 @@ void SocketManager::close(int s)
//
// Because, for example, there could be a race between an HttpProxy
// trying to do send a response with SocketManager::send() or a
- // process might be responding to another HttpRequest (e.g., trying
+ // process might be responding to another Request (e.g., trying
// to do a sendfile) since these things may be happening
// asynchronously we can't close the socket yet, because it might
// get reused before any of the above things have finished, and then
@@ -2027,7 +2015,7 @@ ProcessReference ProcessManager::use(con
bool ProcessManager::handle(
const Socket& socket,
- HttpRequest* request,
+ Request* request,
ProcessBase* sender)
{
CHECK(request != NULL);
@@ -2059,8 +2047,7 @@ bool ProcessManager::handle(
// Enqueue the response with the HttpProxy so that it respects the
// order of requests to account for HTTP/1.1 pipelining.
- dispatch(proxy, &HttpProxy::enqueue,
- HttpBadRequestResponse(), request->keepAlive);
+ dispatch(proxy, &HttpProxy::enqueue, BadRequest(), request->keepAlive);
// Cleanup request.
delete request;
@@ -2077,8 +2064,7 @@ bool ProcessManager::handle(
// Enqueue the response with the HttpProxy so that it respects the
// order of requests to account for HTTP/1.1 pipelining.
- dispatch(proxy, &HttpProxy::enqueue,
- HttpNotFoundResponse(), request->keepAlive);
+ dispatch(proxy, &HttpProxy::enqueue, NotFound(), request->keepAlive);
// Cleanup request.
delete request;
@@ -2130,8 +2116,7 @@ bool ProcessManager::handle(
// Enqueue the response with the HttpProxy so that it respects the
// order of requests to account for HTTP/1.1 pipelining.
- dispatch(proxy, &HttpProxy::enqueue,
- HttpNotFoundResponse(), request->keepAlive);
+ dispatch(proxy, &HttpProxy::enqueue, NotFound(), request->keepAlive);
// Cleanup request.
delete request;
@@ -2759,7 +2744,7 @@ void ProcessBase::visit(const HttpEvent&
VLOG(1) << "Handling HTTP event for process '" << pid.id << "'"
<< " with path: '" << event.request->path << "'";
- CHECK(event.request->path.find('/') == 0); // See ProcessManager::deliver.
+ CHECK(event.request->path.find('/') == 0); // See ProcessManager::handle.
// Split the path by '/'.
vector<string> tokens = tokenize(event.request->path, "/");
@@ -2771,10 +2756,10 @@ void ProcessBase::visit(const HttpEvent&
if (handlers.http.count(name) > 0) {
// Create the promise to link with whatever gets returned, as well
// as a future to wait for the response.
- std::tr1::shared_ptr<Promise<HttpResponse> > promise(
- new Promise<HttpResponse>());
+ std::tr1::shared_ptr<Promise<Response> > promise(
+ new Promise<Response>());
- Future<HttpResponse>* future = new Future<HttpResponse>(promise->future());
+ Future<Response>* future = new Future<Response>(promise->future());
// Get the HttpProxy pid for this socket.
PID<HttpProxy> proxy = socket_manager->proxy(event.socket);
@@ -2785,8 +2770,8 @@ void ProcessBase::visit(const HttpEvent&
// Now call the handler and associate the response with the promise.
promise->associate(handlers.http[name](*event.request));
} else if (assets.count(name) > 0) {
- HttpOKResponse response;
- response.type = HttpResponse::PATH;
+ OK response;
+ response.type = Response::PATH;
response.path = assets[name].path;
// Construct the final path by appending remaining tokens.
@@ -2823,7 +2808,7 @@ void ProcessBase::visit(const HttpEvent&
// Enqueue the response with the HttpProxy so that it respects the
// order of requests to account for HTTP/1.1 pipelining.
dispatch(proxy, &HttpProxy::enqueue,
- HttpNotFoundResponse(), event.request->keepAlive);
+ NotFound(), event.request->keepAlive);
}
}
Modified: incubator/mesos/trunk/third_party/libprocess/src/tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/src/tests.cpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/src/tests.cpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/src/tests.cpp Wed Jul 11 00:20:22 2012
@@ -20,9 +20,9 @@
#include <process/io.hpp>
#include <process/process.hpp>
#include <process/run.hpp>
+#include <process/thread.hpp>
#include "encoder.hpp"
-#include "thread.hpp"
// Definition of a Set action to be used with gmock.
ACTION_P2(Set, variable, value) { *variable = value; }
@@ -36,10 +36,7 @@ using testing::ReturnArg;
TEST(libprocess, thread)
{
- pthread_key_t key;
- ASSERT_EQ(0, pthread_key_create(&key, NULL));
-
- ThreadLocal<ProcessBase>* _process_ = new ThreadLocal<ProcessBase>(key);
+ ThreadLocal<ProcessBase>* _process_ = new ThreadLocal<ProcessBase>();
ProcessBase* process = new ProcessBase();
@@ -56,8 +53,6 @@ TEST(libprocess, thread)
delete process;
delete _process_;
-
- ASSERT_EQ(0, pthread_key_delete(key));
}
@@ -217,7 +212,7 @@ TEST(libprocess, dispatch)
}
-TEST(libprocess, defer)
+TEST(libprocess, defer1)
{
ASSERT_TRUE(GTEST_IS_THREADSAFE);
@@ -289,6 +284,86 @@ TEST(libprocess, defer)
}
+template <typename T>
+void set(T* t1, const T& t2)
+{
+ *t1 = t2;
+}
+
+
+class DeferProcess : public Process<DeferProcess>
+{
+public:
+ DeferProcess(volatile bool* _bool1, volatile bool* _bool2)
+ : bool1(_bool1), bool2(_bool2) {}
+
+protected:
+ virtual void initialize()
+ {
+ deferred<void(bool)> set1 =
+ defer(std::tr1::function<void(bool)>(
+ std::tr1::bind(&set<volatile bool>,
+ bool1,
+ std::tr1::placeholders::_1)));
+
+ set1(true);
+
+ deferred<void(bool)> set2 =
+ defer(std::tr1::function<void(bool)>(
+ std::tr1::bind(&set<volatile bool>,
+ bool2,
+ std::tr1::placeholders::_1)));
+
+ set2(true);
+ }
+
+private:
+ volatile bool* bool1;
+ volatile bool* bool2;
+};
+
+
+TEST(libprocess, defer2)
+{
+ ASSERT_TRUE(GTEST_IS_THREADSAFE);
+
+ volatile bool bool1 = false;
+ volatile bool bool2 = false;
+
+ DeferProcess process(&bool1, &bool2);
+
+ PID<DeferProcess> pid = spawn(process);
+
+ while (!bool1);
+ while (!bool2);
+
+ terminate(pid);
+ wait(pid);
+
+ bool1 = false;
+ bool2 = false;
+
+ deferred<void(bool)> set1 =
+ defer(std::tr1::function<void(bool)>(
+ std::tr1::bind(&set<volatile bool>,
+ &bool1,
+ std::tr1::placeholders::_1)));
+
+ set1(true);
+
+ deferred<void(bool)> set2 =
+ defer(std::tr1::function<void(bool)>(
+ std::tr1::bind(&set<volatile bool>,
+ &bool2,
+ std::tr1::placeholders::_1)));
+
+ set2(true);
+
+ while (!bool1);
+ while (!bool2);
+}
+
+
class HandlersProcess : public Process<HandlersProcess>
{
public:
@@ -931,10 +1006,10 @@ class HttpProcess : public Process<HttpP
public:
HttpProcess()
{
- route("handler", &HttpProcess::handler);
+ route("/handler", &HttpProcess::handler);
}
- MOCK_METHOD1(handler, Future<HttpResponse>(const HttpRequest&));
+ MOCK_METHOD1(handler, Future<http::Response>(const http::Request&));
};
@@ -945,7 +1020,7 @@ TEST(libprocess, http)
HttpProcess process;
EXPECT_CALL(process, handler(_))
- .WillOnce(Return(HttpOKResponse()));
+ .WillOnce(Return(http::OK()));
spawn(process);