You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by jf...@apache.org on 2011/12/06 02:41:59 UTC
svn commit: r1210741 - /thrift/trunk/lib/cpp/src/concurrency/FunctionRunner.h
Author: jfarrell
Date: Tue Dec 6 01:41:59 2011
New Revision: 1210741
URL: http://svn.apache.org/viewvc?rev=1210741&view=rev
Log:
Thrift-1444:FunctionRunner - add syntactic sugar to create shared_ptrs
Client: cpp
Patch: Dave Watson
Simplify FunctionRunner addTask calls.
Modified:
thrift/trunk/lib/cpp/src/concurrency/FunctionRunner.h
Modified: thrift/trunk/lib/cpp/src/concurrency/FunctionRunner.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/concurrency/FunctionRunner.h?rev=1210741&r1=1210740&r2=1210741&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/concurrency/FunctionRunner.h (original)
+++ thrift/trunk/lib/cpp/src/concurrency/FunctionRunner.h Tue Dec 6 01:41:59 2011
@@ -34,16 +34,15 @@ namespace apache { namespace thrift { na
* void* my_thread_main(void* arg);
* shared_ptr<ThreadFactory> factory = ...;
* // To create a thread that executes my_thread_main once:
- * shared_ptr<Thread> thread =
- * factory->newThread(shared_ptr<FunctionRunner>(
- * new FunctionRunner(my_thread_main, some_argument)));
+ * shared_ptr<Thread> thread = factory->newThread(
+ * FunctionRunner::create(my_thread_main, some_argument));
* thread->start();
*
* bool A::foo();
* A* a = new A();
* // To create a thread that executes a.foo() every 100 milliseconds:
- * factory->newThread(shared_ptr<FunctionRunner>(
- * new FunctionRunner(std::tr1::bind(&A::foo, a), 100)))->start();
+ * factory->newThread(FunctionRunner::create(
+ * std::tr1::bind(&A::foo, a), 100))->start();
*
*/
@@ -57,6 +56,20 @@ class FunctionRunner : public Runnable {
typedef std::tr1::function<bool()> BoolFunc;
/**
+ * Syntactic sugar to make it easier to create new FunctionRunner
+ * objects wrapped in shared_ptr.
+ */
+ static boost::shared_ptr<FunctionRunner> create(const VoidFunc& cob) {
+ return boost::shared_ptr<FunctionRunner>(new FunctionRunner(cob));
+ }
+
+ static boost::shared_ptr<FunctionRunner> create(PthreadFuncPtr func,
+ void* arg) {
+ return boost::shared_ptr<FunctionRunner>(new FunctionRunner(func, arg));
+ }
+
+
+ /**
* Given a 'pthread_create' style callback, this FunctionRunner will
* execute the given callback. Note that the 'void*' return value is ignored.
*/