threads.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // -*- C++ -*-
  2. // Module: Log4CPLUS
  3. // File: threads.h
  4. // Created: 6/2001
  5. // Author: Tad E. Smith
  6. //
  7. //
  8. // Copyright 2001-2015 Tad E. Smith
  9. //
  10. // Licensed under the Apache License, Version 2.0 (the "License");
  11. // you may not use this file except in compliance with the License.
  12. // You may obtain a copy of the License at
  13. //
  14. // http://www.apache.org/licenses/LICENSE-2.0
  15. //
  16. // Unless required by applicable law or agreed to in writing, software
  17. // distributed under the License is distributed on an "AS IS" BASIS,
  18. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. // See the License for the specific language governing permissions and
  20. // limitations under the License.
  21. /** @file */
  22. #ifndef LOG4CPLUS_THREADS_HEADER_
  23. #define LOG4CPLUS_THREADS_HEADER_
  24. #include <log4cplus/config.hxx>
  25. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  26. #pragma once
  27. #endif
  28. #include <log4cplus/tstring.h>
  29. #include <log4cplus/helpers/pointer.h>
  30. namespace log4cplus { namespace thread {
  31. LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName();
  32. LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName2();
  33. LOG4CPLUS_EXPORT void setCurrentThreadName(const log4cplus::tstring & name);
  34. LOG4CPLUS_EXPORT void setCurrentThreadName2(const log4cplus::tstring & name);
  35. LOG4CPLUS_EXPORT void yield();
  36. LOG4CPLUS_EXPORT void blockAllSignals();
  37. #ifndef LOG4CPLUS_SINGLE_THREADED
  38. class ThreadImplBase
  39. : public virtual log4cplus::helpers::SharedObject
  40. {
  41. protected:
  42. virtual ~ThreadImplBase ();
  43. };
  44. /**
  45. * There are many cross-platform C++ Threading libraries. The goal of
  46. * this class is not to replace (or match in functionality) those
  47. * libraries. The goal of this class is to provide a simple Threading
  48. * class with basic functionality.
  49. */
  50. class LOG4CPLUS_EXPORT AbstractThread
  51. : public virtual log4cplus::helpers::SharedObject
  52. {
  53. public:
  54. AbstractThread();
  55. bool isRunning() const;
  56. virtual void start();
  57. void join () const;
  58. virtual void run() = 0;
  59. protected:
  60. // Force objects to be constructed on the heap
  61. virtual ~AbstractThread();
  62. private:
  63. helpers::SharedObjectPtr<ThreadImplBase> thread;
  64. // Disallow copying of instances of this class.
  65. AbstractThread(const AbstractThread&);
  66. AbstractThread& operator=(const AbstractThread&);
  67. };
  68. typedef helpers::SharedObjectPtr<AbstractThread> AbstractThreadPtr;
  69. #endif // LOG4CPLUS_SINGLE_THREADED
  70. } } // namespace log4cplus { namespace thread {
  71. #endif // LOG4CPLUS_THREADS_HEADER_