1 /*============================================================================= 2 3 Library: CTK 4 5 Copyright (c) German Cancer Research Center, 6 Division of Medical and Biological Informatics 7 8 Licensed under the Apache License, Version 2.0 (the "License"); 9 you may not use this file except in compliance with the License. 10 You may obtain a copy of the License at 11 12 http://www.apache.org/licenses/LICENSE-2.0 13 14 Unless required by applicable law or agreed to in writing, software 15 distributed under the License is distributed on an "AS IS" BASIS, 16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 See the License for the specific language governing permissions and 18 limitations under the License. 19 20 =============================================================================*/ 21 22 23 #ifndef CTKEATHREADFACTORYUSER_P_H 24 #define CTKEATHREADFACTORYUSER_P_H 25 26 #include <QMutex> 27 28 #include "ctkEAThreadFactory_p.h" 29 #include "ctkEAInterruptibleThread_p.h" 30 31 /** 32 * Base class for Executors and related classes that rely on thread factories. 33 * Generally intended to be used as a mixin-style abstract class, but 34 * can also be used stand-alone. 35 */ 36 class ctkEAThreadFactoryUser 37 { 38 39 protected: 40 41 mutable QMutex mutex; 42 43 ctkEAThreadFactory* threadFactory; 44 45 class DefaultThread : public ctkEAInterruptibleThread 46 { 47 public: 48 49 DefaultThread(ctkEARunnable* command); 50 51 void run(); 52 53 private: 54 55 ctkEARunnable* command; 56 bool deleteCmd; 57 }; 58 59 class DefaultThreadFactory : public ctkEAThreadFactory 60 { 61 public: 62 63 ctkEAInterruptibleThread* newThread(ctkEARunnable* command); 64 }; 65 66 ctkEAThreadFactoryUser(); 67 68 ~ctkEAThreadFactoryUser(); 69 70 /** 71 * Set the factory for creating new threads. 72 * By default, new threads are created without any special priority, 73 * threadgroup, or status parameters. 74 * You can use a different factory 75 * to change the kind of Thread class used or its construction 76 * parameters. 77 * @param factory the factory to use 78 * @return the previous factory 79 */ 80 ctkEAThreadFactory* setThreadFactory(ctkEAThreadFactory* factory); 81 82 /** 83 * Get the factory for creating new threads. 84 */ 85 ctkEAThreadFactory* getThreadFactory(); 86 87 }; 88 89 #endif // CTKEATHREADFACTORYUSER_P_H 90