• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

ThreadWeaver

  • sources
  • kde-4.12
  • kdelibs
  • threadweaver
  • Weaver
WorkingHardState.cpp
Go to the documentation of this file.
1 /* -*- C++ -*-
2 
3 This file implements the WorkingHardState class.
4 
5 $ Author: Mirko Boehm $
6 $ Copyright: (C) 2005-2013 Mirko Boehm $
7 $ Contact: mirko@kde.org
8 http://www.kde.org
9 http://creative-destruction.me $
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Library General Public
13  License as published by the Free Software Foundation; either
14  version 2 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Library General Public License for more details.
20 
21  You should have received a copy of the GNU Library General Public License
22  along with this library; see the file COPYING.LIB. If not, write to
23  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  Boston, MA 02110-1301, USA.
25 
26 $Id: WorkingHardState.cpp 30 2005-08-16 16:16:04Z mirko $
27 */
28 
29 #include "WorkingHardState.h"
30 
31 #include <QtCore/QByteRef>
32 
33 #include "Job.h"
34 #include "Thread.h"
35 #include "WeaverImpl.h"
36 #include "ThreadWeaver.h"
37 #include "DebuggingAids.h"
38 
39 
40 using namespace ThreadWeaver;
41 
42 void WorkingHardState::activated()
43 {
44  weaver()->assignJobs();
45 }
46 
47 void WorkingHardState::suspend()
48 {
49  weaver()->setState ( Suspending );
50 }
51 
52 void WorkingHardState::resume()
53 {
54 }
55 
56 Job* WorkingHardState::applyForWork(Thread *th, Job* previous)
57 { // beware: this code is executed in the applying thread!
58  debug ( 2, "WorkingHardState::applyForWork: thread %i applies for work "
59  "in %s state.\n", th->id(),
60  qPrintable ( weaver()->state().stateName() ) );
61 
62  Job *next = weaver()->takeFirstAvailableJob(previous);
63  if ( next ) {
64  return next;
65  } else {
66  debug ( 2, "WorkingHardState::applyForWork: no work for thread %i, "
67  "blocking it.\n", th->id() );
68  weaver()->waitForAvailableJob( th );
69  // this is no infinite recursion: the state may have changed
70  // meanwhile, or jobs may have become available:
71  return weaver()->applyForWork( th, 0 );
72  }
73 }
74 
75 void WorkingHardState::waitForAvailableJob ( Thread *th )
76 {
77  weaver()->blockThreadUntilJobsAreBeingAssigned ( th );
78 }
79 
80 StateId WorkingHardState::stateId() const
81 {
82  return WorkingHard;
83 }
Job.h
ThreadWeaver::Thread
The class Thread is used to represent the worker threads in the weaver's inventory.
Definition: Thread.h:46
ThreadWeaver::WorkingHardState::stateId
StateId stateId() const
reimpl
Definition: WorkingHardState.cpp:80
ThreadWeaver::WorkingHardState::resume
virtual void resume()
Resume job processing.
Definition: WorkingHardState.cpp:52
ThreadWeaver::WorkingHard
Jobs are being processed.
Definition: State.h:53
ThreadWeaver::StateId
StateId
All weaver objects maintain a state of operation which can be queried by the application.
Definition: State.h:48
ThreadWeaver::StateImplementation::weaver
WeaverImpl * weaver()
Definition: StateImplementation.cpp:35
ThreadWeaver.h
ThreadWeaver::WorkingHardState::suspend
virtual void suspend()
Suspend job processing.
Definition: WorkingHardState.cpp:47
ThreadWeaver::WeaverImpl::takeFirstAvailableJob
Job * takeFirstAvailableJob(Job *previous)
Take the first available job out of the queue and return it.
Definition: WeaverImpl.cpp:333
ThreadWeaver::WorkingHardState::waitForAvailableJob
virtual void waitForAvailableJob(Thread *th)
Wait (by suspending the calling thread) until a job becomes available.
Definition: WorkingHardState.cpp:75
Thread.h
ThreadWeaver::Suspending
Job processing is suspended, but some jobs which where already in progress are not finished yet...
Definition: State.h:56
ThreadWeaver::WeaverImpl::assignJobs
void assignJobs()
Schedule enqueued jobs to be executed by idle threads.
Definition: WeaverImpl.cpp:288
DebuggingAids.h
ThreadWeaver::WeaverImpl::setState
void setState(StateId)
Set the object state.
Definition: WeaverImpl.cpp:124
WeaverImpl.h
ThreadWeaver::State::stateName
QString stateName() const
The ID of the current state.
Definition: State.cpp:69
ThreadWeaver::Thread::id
unsigned int id()
Returns the thread id.
Definition: Thread.cpp:80
ThreadWeaver::debug
void debug(int severity, const char *cformat,...)
This method prints a text message on the screen, if debugging is enabled.
Definition: DebuggingAids.h:112
ThreadWeaver::WorkingHardState::activated
void activated()
Overload.
Definition: WorkingHardState.cpp:42
ThreadWeaver::WeaverImpl::applyForWork
virtual Job * applyForWork(Thread *thread, Job *previous)
Assign a job to the calling thread.
Definition: WeaverImpl.cpp:354
WorkingHardState.h
ThreadWeaver::Job
A Job is a simple abstraction of an action that is to be executed in a thread context.
Definition: Job.h:65
ThreadWeaver::WeaverImpl::waitForAvailableJob
void waitForAvailableJob(Thread *th)
Wait for a job to become available.
Definition: WeaverImpl.cpp:359
ThreadWeaver::WeaverImpl::blockThreadUntilJobsAreBeingAssigned
void blockThreadUntilJobsAreBeingAssigned(Thread *th)
Blocks the calling thread until some actor calls assignJobs.
Definition: WeaverImpl.cpp:364
ThreadWeaver::WorkingHardState::applyForWork
virtual Job * applyForWork(Thread *th, Job *previous)
Assign a job to an idle thread.
Definition: WorkingHardState.cpp:56
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ThreadWeaver

Skip menu "ThreadWeaver"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal