| 1 | /* -*- C++ -*- |
|---|---|
| 2 | This file implements the InConstructionState class. |
| 3 | |
| 4 | SPDX-FileCopyrightText: 2005-2013 Mirko Boehm <mirko@kde.org> |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 7 | |
| 8 | $Id: InConstructionState.cpp 30 2005-08-16 16:16:04Z mirko $ |
| 9 | */ |
| 10 | |
| 11 | #include "inconstructionstate.h" |
| 12 | |
| 13 | #include "threadweaver.h" |
| 14 | #include "weaver.h" |
| 15 | |
| 16 | namespace ThreadWeaver |
| 17 | { |
| 18 | InConstructionState::InConstructionState(QueueSignals *weaver) |
| 19 | : WeaverImplState(weaver) |
| 20 | { |
| 21 | } |
| 22 | |
| 23 | void InConstructionState::suspend() |
| 24 | { |
| 25 | // this request is not handled in InConstruction state |
| 26 | } |
| 27 | |
| 28 | void InConstructionState::resume() |
| 29 | { |
| 30 | // this request is not handled in InConstruction state |
| 31 | } |
| 32 | |
| 33 | JobPointer InConstructionState::applyForWork(Thread *th, bool wasBusy) |
| 34 | { |
| 35 | Q_ASSERT(wasBusy == false); |
| 36 | // As long as we are in the construction state, no jobs will be given |
| 37 | // to the worker threads. The threads will be suspended. They will |
| 38 | // return from the blocked state when jobs are queued. By then, we |
| 39 | // should not be in InConstruction state anymore, and we hand the job |
| 40 | // application over to the then active state. |
| 41 | while (weaver()->state()->stateId() == InConstruction) { |
| 42 | weaver()->waitForAvailableJob(th); |
| 43 | } |
| 44 | return weaver()->applyForWork(thread: th, wasBusy); |
| 45 | } |
| 46 | |
| 47 | StateId InConstructionState::stateId() const |
| 48 | { |
| 49 | return InConstruction; |
| 50 | } |
| 51 | |
| 52 | } |
| 53 |
