ThreadWeaver
InConstructionState.cpp
Go to the documentation of this file.00001 /* -*- C++ -*- 00002 00003 This file implements the InConstructionState class. 00004 00005 $ Author: Mirko Boehm $ 00006 $ Copyright: (C) 2005, 2006 Mirko Boehm $ 00007 $ Contact: mirko@kde.org 00008 http://www.kde.org 00009 http://www.hackerbuero.org $ 00010 00011 This library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU Library General Public 00013 License as published by the Free Software Foundation; either 00014 version 2 of the License, or (at your option) any later version. 00015 00016 This library is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 Library General Public License for more details. 00020 00021 You should have received a copy of the GNU Library General Public License 00022 along with this library; see the file COPYING.LIB. If not, write to 00023 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00024 Boston, MA 02110-1301, USA. 00025 00026 $Id: InConstructionState.cpp 30 2005-08-16 16:16:04Z mirko $ 00027 */ 00028 00029 #include "InConstructionState.h" 00030 00031 #include "WeaverImpl.h" 00032 #include "ThreadWeaver.h" 00033 00034 namespace ThreadWeaver { 00035 00036 void InConstructionState::suspend() 00037 { 00038 // this request is not handled in InConstruction state 00039 } 00040 00041 void InConstructionState::resume() 00042 { 00043 // this request is not handled in InConstruction state 00044 } 00045 00046 Job* InConstructionState::applyForWork ( Thread *th, Job *previous) 00047 { 00048 // As long as we are in the construction state, no jobs will be given 00049 // to the worker threads. The threads will be suspended. They will 00050 // return from the blocked state when jobs are queued. By then, we 00051 // should not be in InConstruction state anymore, and we hand the job 00052 // application over to the then active state. 00053 while ( weaver()->state().stateId() == InConstruction ) 00054 { 00055 weaver()->waitForAvailableJob ( th); 00056 } 00057 return weaver()->applyForWork ( th, previous ); 00058 } 00059 00060 void InConstructionState::waitForAvailableJob ( Thread * th) 00061 { 00062 weaver()->blockThreadUntilJobsAreBeingAssigned ( th ); 00063 } 00064 00065 StateId InConstructionState::stateId() const 00066 { 00067 return InConstruction; 00068 } 00069 00070 }