1 | /* -*- C++ -*- |
2 | This file implements the WorkingHardState 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: WorkingHardState.cpp 30 2005-08-16 16:16:04Z mirko $ |
9 | */ |
10 | |
11 | #include "workinghardstate.h" |
12 | |
13 | #include "debuggingaids.h" |
14 | #include "job.h" |
15 | #include "thread.h" |
16 | #include "threadweaver.h" |
17 | |
18 | namespace ThreadWeaver |
19 | { |
20 | void WorkingHardState::activated() |
21 | { |
22 | weaver()->reschedule(); |
23 | } |
24 | |
25 | WorkingHardState::WorkingHardState(Weaver *weaver) |
26 | : WeaverImplState(weaver) |
27 | { |
28 | } |
29 | |
30 | void WorkingHardState::suspend() |
31 | { |
32 | weaver()->setState(Suspending); |
33 | } |
34 | |
35 | void WorkingHardState::resume() |
36 | { |
37 | } |
38 | |
39 | JobPointer WorkingHardState::applyForWork(Thread *th, bool wasBusy) |
40 | { |
41 | // beware: this code is executed in the applying thread! |
42 | TWDEBUG(2, "WorkingHardState::applyForWork: thread %i applies for work in %s state.\n" , th->id(), qPrintable(weaver()->state()->stateName())); |
43 | JobPointer next = weaver()->takeFirstAvailableJobOrSuspendOrWait(th, threadWasBusy: wasBusy, suspendIfAllThreadsInactive: false, justReturning: false); |
44 | if (next) { |
45 | return next; |
46 | } else { |
47 | // this is no infinite recursion: the state may have changed meanwhile, or jobs may have become available: |
48 | TWDEBUG(2, "WorkingHardState::applyForWork: repeating for thread %i in %s state.\n" , th->id(), qPrintable(weaver()->state()->stateName())); |
49 | return weaver()->applyForWork(thread: th, wasBusy: false); |
50 | } |
51 | } |
52 | |
53 | StateId WorkingHardState::stateId() const |
54 | { |
55 | return WorkingHard; |
56 | } |
57 | |
58 | } |
59 | |