Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Private Attributes
Arc::ThreadRegistry Class Reference

This class is a set of conditions, mutexes, etc. conveniently exposed to moitor running child threads and to wait till they exit. There are no protections against race conditions. So use it carefully. More...

#include <Thread.h>

List of all members.

Public Member Functions

 ThreadRegistry (void)
 ~ThreadRegistry (void)
void RegisterThread (void)
 Register thread as started/starting into this instance.
void UnregisterThread (void)
 Report thread as exited.
bool WaitOrCancel (int timeout)
 Wait for timeout milliseconds or cancel request. Returns true if cancel request received.
bool WaitForExit (int timeout=-1)
 Wait for registered threads to exit. Leave after timeout miliseconds if failed. Returns true if all registered threads reported their exit.
void RequestCancel (void)

Private Attributes

int counter_
bool cancel_
Glib::Cond cond_
Glib::Mutex lock_

Detailed Description

This class is a set of conditions, mutexes, etc. conveniently exposed to moitor running child threads and to wait till they exit. There are no protections against race conditions. So use it carefully.

Definition at line 144 of file Thread.h.


Constructor & Destructor Documentation

Definition at line 247 of file Thread.cpp.

                                    :counter_(0),cancel_(false) {
  }

Definition at line 250 of file Thread.cpp.

                                      {
  }

Member Function Documentation

Register thread as started/starting into this instance.

Definition at line 253 of file Thread.cpp.

                                          {
    lock_.lock();
    ++counter_;
    lock_.unlock();
  }

Here is the caller graph for this function:

Definition at line 300 of file Thread.cpp.

                                         {
    lock_.lock();
    cancel_=true;
    cond_.broadcast();
    lock_.unlock();
  }

Here is the caller graph for this function:

Report thread as exited.

Definition at line 259 of file Thread.cpp.

                                            {
    lock_.lock();
    ++counter_;
    cond_.broadcast();
    lock_.unlock();
  }

Here is the caller graph for this function:

bool Arc::ThreadRegistry::WaitForExit ( int  timeout = -1)

Wait for registered threads to exit. Leave after timeout miliseconds if failed. Returns true if all registered threads reported their exit.

Definition at line 280 of file Thread.cpp.

                                              {
    int n = 0;
    lock_.lock();
    if(timeout >= 0) {
      Glib::TimeVal etime;
      etime.assign_current_time();
      etime.add_milliseconds(timeout);
      while (counter_ > 0) {
        if(!cond_.timed_wait(lock_, etime)) break;
      }
    } else {
      while (counter_ > 0) {
        cond_.wait(lock_);
      }
    }
    n = counter_;
    lock_.unlock();
    return (n <= 0);
  }

Here is the caller graph for this function:

bool Arc::ThreadRegistry::WaitOrCancel ( int  timeout)

Wait for timeout milliseconds or cancel request. Returns true if cancel request received.

Definition at line 266 of file Thread.cpp.

                                               {
    bool v = false;
    lock_.lock();
    Glib::TimeVal etime;
    etime.assign_current_time();
    etime.add_milliseconds(timeout);
    while (!cancel_) {
      if(!cond_.timed_wait(lock_, etime)) break;
    }
    v = cancel_;
    lock_.unlock();
    return v;
  }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 147 of file Thread.h.

Glib::Cond Arc::ThreadRegistry::cond_ [private]

Definition at line 148 of file Thread.h.

Definition at line 146 of file Thread.h.

Glib::Mutex Arc::ThreadRegistry::lock_ [private]

Definition at line 149 of file Thread.h.


The documentation for this class was generated from the following files: