threads-impl.h 1.9 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-2017 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_IMPL_THREADS_IMPL_HEADER_
  23. #define LOG4CPLUS_IMPL_THREADS_IMPL_HEADER_
  24. #include <log4cplus/config.hxx>
  25. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  26. #pragma once
  27. #endif
  28. #if defined (_WIN32)
  29. #include <log4cplus/config/windowsh-inc.h>
  30. #endif
  31. #include <log4cplus/tstring.h>
  32. #include <log4cplus/helpers/pointer.h>
  33. #include <log4cplus/thread/threads.h>
  34. #if ! defined (INSIDE_LOG4CPLUS)
  35. # error "This header must not be be used outside log4cplus' implementation files."
  36. #endif
  37. namespace log4cplus { namespace thread { namespace impl {
  38. #if defined (LOG4CPLUS_USE_PTHREADS)
  39. typedef pthread_t os_handle_type;
  40. typedef pthread_t os_id_type;
  41. inline
  42. pthread_t
  43. getCurrentThreadId ()
  44. {
  45. return pthread_self ();
  46. }
  47. #elif defined (LOG4CPLUS_USE_WIN32_THREADS)
  48. typedef HANDLE os_handle_type;
  49. typedef DWORD os_id_type;
  50. inline
  51. DWORD
  52. getCurrentThreadId ()
  53. {
  54. return GetCurrentThreadId ();
  55. }
  56. #elif defined (LOG4CPLUS_SINGLE_THREADED)
  57. typedef void * os_handle_type;
  58. typedef int os_id_type;
  59. inline
  60. int
  61. getCurrentThreadId ()
  62. {
  63. return 1;
  64. }
  65. #endif
  66. } } } // namespace log4cplus { namespace thread { namespace impl {
  67. #endif // LOG4CPLUS_IMPL_THREADS_IMPL_HEADER_