Code Search for Developers
 
 
  

ThreadCleanup.h from AlphaMail at Krugle


Show ThreadCleanup.h syntax highlighted

#ifndef THREADCLEANUP_H
#define THREADCLEANUP_H

#include <vector>
#include <map>
#include <boost/thread/mutex.hpp>
#include <boost/thread.hpp>
#include <IMAPTypes.h>
#include <Runnable.h>
#include <RequestProcessor.h>

namespace Middleware 
{
   class RequestProcessor;

   /**
    * This class provides a mechanism by which an alternate thread can clean up
    * any arbitrary thread that ends. It uses sync primitives to insure that 
    * it cleans up only those threads that are complete.
    */
   class ThreadCleanup : public Runnable, private boost::noncopyable
   {
      public:
         ThreadCleanup(bool *sflag) { shutdown_flag = sflag; }
         ~ThreadCleanup();

         /**
          * This method associates a RequestProcessor with the thread that is
          * running it. Any new RequestProcessor should be added using this
          * method once it's thread has been created.
          */
         void manage(RequestProcessor *p, boost::thread *t);

         /**
          * When a Runnable thread completes, it should call this
          * method to schedule a cleanup of the thread resources. If the
          * Runnable itself should also be freed, pass true as the second
          * argument.
          *
          * @param p The Runnable to call join on.
          * @param free A flag indicating whether the Runnable itself needs
          * freed.
          */
         void schedule_cleanup(RequestProcessor *p);

         /**
          * This is the thread method for the cleanup routine itself.
          */
         void operator()();

         void notify() { 
            boost::mutex::scoped_lock lk(object_mutex);
            thread_complete.notify_one();
         }
      private:
         boost::mutex object_mutex;
         boost::condition thread_complete;
         std::vector<RequestProcessor*> to_cleanup;
         std::map<RequestProcessor*, boost::thread *> thread_map;
         bool *shutdown_flag;
   };
};
#endif




See more files for this project here

AlphaMail

AlphaMail is an accelerated web mail interface with a C++ middleware layer that is more effective than an IMAP proxy which is a highly scalable (10k+ users). The interface includes modern features, Section 508 compliance, and universal browser support.

Project homepage: http://sourceforge.net/projects/alphamail
Programming language(s): C++,Java,JavaScript,Perl
License: other

  CacheManager.h
  IMAPFolder.h
  IMAPParser.h
  IMAPParserFactory.h
  IMAPRegexParser.h
  IMAPTypes.h
  MessageAttributes.h
  RequestProcessor.h
  Runnable.h
  ThreadCleanup.h
  imap_debug.h
  middleware.h