28#ifndef _util_group_thread_h
29#define _util_group_thread_h
35#include <util/class/class.h>
44class ThreadLock :
public RefCount {
47 virtual ~ThreadLock();
70 void unlock() {
if (locked_) { lock_->unlock(); locked_ =
false; } }
72 void lock() {
if (!locked_) { lock_->lock(); locked_ =
true; } }
84 static void *run_Thread_run(
void*thread);
87 virtual void run() =0;
92class ThreadGrp:
public DescribedClass {
100 ThreadGrp(
const ThreadGrp&,
int nthread = -1);
101 virtual ~ThreadGrp();
113 void delete_threads();
131 static ThreadGrp * get_default_threadgrp();
132 static ThreadGrp * initial_threadgrp(
int &argc,
char ** argv);
139class ProcThreadGrp:
public ThreadGrp {
157 void *Thread__run_Thread_run(
void*thread);
Ref< ThreadLock > new_lock()
Return a local object.
ThreadGrp * clone(int nthread=-1)
Create a ThreadGrp like the current one.
int wait_threads()
Wait for all the threads to complete.
int start_threads()
Starts the threads running.
A template class that maintains references counts.
Definition ref.h:332
virtual ThreadGrp * clone(int nthread=-1)
Create a ThreadGrp like the current one.
virtual Ref< ThreadLock > new_lock()=0
Return a local object.
int nthread() const
The number of threads that will be run by start_thread.
Definition thread.h:111
virtual void add_thread(int threadnum, Thread *thread)
Assigns a Thread object to each thread.
virtual void add_thread(int threadnum, Thread *thread, int priority)
Like add_thread(threadnum, thread), but assign a priority that the thread is to use.
virtual int start_threads()=0
Starts the threads running.
virtual int wait_threads()=0
Wait for all the threads to complete.
ThreadLockHolder(const Ref< ThreadLock > &l)
Acquires the lock.
Definition thread.h:65
void unlock()
Release the lock before the DTOR is called, if it is still held.
Definition thread.h:70
~ThreadLockHolder()
Releases the lock if it is still held.
Definition thread.h:74
void lock()
Acquire the lock once more.
Definition thread.h:72
virtual void unlock()=0
Release the lock.
virtual void lock()=0
Obtain the lock.
The Thread abstract class defines an interface which must be implemented by classes wishing to be run...
Definition thread.h:79
virtual void run()=0
This is called with the Thread is run from a ThreadGrp.