Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Private Member Functions | Private Attributes | Friends
Arc::ThreadPool Class Reference
Collaboration diagram for Arc::ThreadPool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ThreadPool (void)
void PushQueue (ThreadArgument *arg)

Private Member Functions

int CheckQueue (void)
 ~ThreadPool (void)

Private Attributes

int max_count
int count
Glib::Mutex count_lock
Glib::Mutex queue_lock
std::list< ThreadArgument * > queue

Friends

class ThreadInc

Detailed Description

Definition at line 69 of file Thread.cpp.


Constructor & Destructor Documentation

Arc::ThreadPool::~ThreadPool ( void  ) [inline, private]

Definition at line 79 of file Thread.cpp.

{ };

Definition at line 85 of file Thread.cpp.

                            :max_count(0),count(0) {
    // Estimating amount of available memory 
    uint64_t n = 0;
#ifndef WIN32
    struct rlimit rl;
    if(getrlimit(RLIMIT_AS,&rl) == 0) {
      if(rl.rlim_cur != RLIM_INFINITY) {
        // Dividing by 2 assuming each thread will equally use 
        // stack and heap
        n = rl.rlim_cur/thread_stacksize/2;
        if(n == 0) {
          // What else can we do. Application will fail on first thread
          n=1;
        }
      } else if(rl.rlim_max != RLIM_INFINITY) {
        n = rl.rlim_max/thread_stacksize/2;
        if(n == 0) {
          n=1;
        }
      }
    }
#endif
    if(n == 0) {
      // Very rough estimation of number of threads which can be run
      n = (((uint64_t)1)<<(8*sizeof(int*) - 2))/thread_stacksize;
    }
    if(n > INT_MAX) n = INT_MAX;
    max_count = (int)n;
    // TODO: can't use logger here because it will try to initilize pool
    //threadLogger.msg(DEBUG, "Maximum number of threads is %i",max_count);
  }

Member Function Documentation

int Arc::ThreadPool::CheckQueue ( void  ) [private]

Definition at line 116 of file Thread.cpp.

                                 {
    Glib::Mutex::Lock lock(queue_lock, Glib::TRY_LOCK);
    if(!lock.locked()) return -1;
    int size = queue.size();
    while((count < max_count) && (size > 0)) {
      ThreadArgument* argument = *(queue.begin());
      argument->acquire();
      try {
        UserSwitch usw(0,0);
        Glib::Thread::create(sigc::mem_fun(*argument,
                                           &ThreadArgument::thread),
                             thread_stacksize, false, false,
                             Glib::THREAD_PRIORITY_NORMAL);
        queue.erase(queue.begin());
      } catch (Glib::Error& e) {
        threadLogger.msg(ERROR, e.what());
        argument->release();
      } catch (std::exception& e) {
        threadLogger.msg(ERROR, e.what());
        argument->release();
      };
      size = queue.size();
    }
    return size;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 142 of file Thread.cpp.

                                                {
    Glib::Mutex::Lock lock(queue_lock);
    queue.push_back(arg);
    lock.release();
    if(CheckQueue() > 0)
      threadLogger.msg(INFO, "Maximum number of threads running - puting new request into queue");
  }

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class ThreadInc [friend]

Definition at line 71 of file Thread.cpp.


Member Data Documentation

int Arc::ThreadPool::count [private]

Definition at line 74 of file Thread.cpp.

Glib::Mutex Arc::ThreadPool::count_lock [private]

Definition at line 75 of file Thread.cpp.

Definition at line 73 of file Thread.cpp.

std::list<ThreadArgument*> Arc::ThreadPool::queue [private]

Definition at line 77 of file Thread.cpp.

Glib::Mutex Arc::ThreadPool::queue_lock [private]

Definition at line 76 of file Thread.cpp.


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