C++DB is the database layer that was designed to work with C++CMS. This customized version is used within Ye Ol' Pi Shack.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

87 lines
1.8 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2010-2011 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // Distributed under:
  6. //
  7. // the Boost Software License, Version 1.0.
  8. // (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. // or (at your opinion) under:
  12. //
  13. // The MIT License
  14. // (See accompanying file MIT.txt or a copy at
  15. // http://www.opensource.org/licenses/mit-license.php)
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #define CPPDB_SOURCE
  19. #include <cppdb/mutex.h>
  20. #if defined(WIN32) || defined(_WIN32) || defined(__WIN32)
  21. # include <windows.h>
  22. # ifdef impl_
  23. # undef impl_
  24. # endif
  25. # define impl_ ((CRITICAL_SECTION *)mutex_impl_)
  26. namespace cppdb {
  27. mutex::mutex() : mutex_impl_(0)
  28. {
  29. mutex_impl_ = new CRITICAL_SECTION();
  30. InitializeCriticalSection(impl_);
  31. }
  32. mutex::~mutex()
  33. {
  34. DeleteCriticalSection(impl_);
  35. delete impl_;
  36. }
  37. void mutex::lock()
  38. {
  39. EnterCriticalSection(impl_);
  40. }
  41. void mutex::unlock()
  42. {
  43. LeaveCriticalSection(impl_);
  44. }
  45. }
  46. #else // POSIX
  47. # include <pthread.h>
  48. # ifdef impl_
  49. # undef impl_
  50. # endif
  51. # define impl_ ((pthread_mutex_t *)mutex_impl_)
  52. namespace cppdb {
  53. mutex::mutex() : mutex_impl_(0)
  54. {
  55. mutex_impl_ = new pthread_mutex_t();
  56. pthread_mutex_init(impl_,0);
  57. }
  58. mutex::~mutex()
  59. {
  60. pthread_mutex_destroy(impl_);
  61. delete impl_;
  62. }
  63. void mutex::lock()
  64. {
  65. pthread_mutex_lock(impl_);
  66. }
  67. void mutex::unlock()
  68. {
  69. pthread_mutex_unlock(impl_);
  70. }
  71. }
  72. #endif