Roger Meier | 3faaedf | 2011-10-02 10:51:45 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
| 20 | #ifndef _THRIFT_CONCURRENCY_BOOSTTHREADFACTORY_H_ |
| 21 | #define _THRIFT_CONCURRENCY_BOOSTTHREADFACTORY_H_ 1 |
| 22 | |
| 23 | #include "Thread.h" |
| 24 | |
| 25 | #include <boost/shared_ptr.hpp> |
| 26 | |
| 27 | namespace apache { namespace thrift { namespace concurrency { |
| 28 | |
| 29 | /** |
| 30 | * A thread factory to create posix threads |
| 31 | * |
| 32 | * @version $Id:$ |
| 33 | */ |
| 34 | class BoostThreadFactory : public ThreadFactory { |
| 35 | |
| 36 | public: |
| 37 | |
| 38 | /** |
| 39 | * Boost thread factory. All threads created by a factory are reference-counted |
| 40 | * via boost::shared_ptr and boost::weak_ptr. The factory guarantees that threads and |
| 41 | * the Runnable tasks they host will be properly cleaned up once the last strong reference |
| 42 | * to both is given up. |
| 43 | * |
| 44 | * Threads are created with the specified boost policy, priority, stack-size. A detachable thread is not |
| 45 | * joinable. |
| 46 | * |
| 47 | * By default threads are not joinable. |
| 48 | */ |
| 49 | |
| 50 | BoostThreadFactory(bool detached=true); |
| 51 | |
| 52 | // From ThreadFactory; |
| 53 | boost::shared_ptr<Thread> newThread(boost::shared_ptr<Runnable> runnable) const; |
| 54 | |
| 55 | // From ThreadFactory; |
| 56 | Thread::id_t getCurrentThreadId() const; |
| 57 | |
| 58 | /** |
| 59 | * Sets detached mode of threads |
| 60 | */ |
| 61 | virtual void setDetached(bool detached); |
| 62 | |
| 63 | /** |
| 64 | * Gets current detached mode |
| 65 | */ |
| 66 | virtual bool isDetached() const; |
| 67 | |
| 68 | private: |
| 69 | class Impl; |
| 70 | boost::shared_ptr<Impl> impl_; |
| 71 | }; |
| 72 | |
| 73 | }}} // apache::thrift::concurrency |
| 74 | |
| 75 | #endif // #ifndef _THRIFT_CONCURRENCY_BOOSTTHREADFACTORY_H_ |