BVB Source Codes

mars Show once.cpp Source code

Return Download mars: download once.cpp Source code - Download mars Source code - Type:.cpp
  1. // Copyright (C) 2007 Anthony Williams
  2. //
  3. //  Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5.  
  6. #include <boost/thread/detail/config.hpp>
  7. #ifdef BOOST_THREAD_ONCE_ATOMIC
  8. #include "./once_atomic.cpp"
  9. #else
  10. #define __STDC_CONSTANT_MACROS
  11. #include <boost/thread/pthread/pthread_mutex_scoped_lock.hpp>
  12. #include <boost/thread/once.hpp>
  13. #include <boost/assert.hpp>
  14. #include <boost/throw_exception.hpp>
  15. #include <pthread.h>
  16. #include <stdlib.h>
  17. #include <memory>
  18. #include <string.h> // memcmp.
  19. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost
  20. {
  21.     namespace thread_detail
  22.     {
  23.         BOOST_THREAD_DECL uintmax_atomic_t once_global_epoch=BOOST_THREAD_DETAIL_UINTMAX_ATOMIC_MAX_C;
  24.         BOOST_THREAD_DECL pthread_mutex_t once_epoch_mutex=PTHREAD_MUTEX_INITIALIZER;
  25.         BOOST_THREAD_DECL pthread_cond_t once_epoch_cv = PTHREAD_COND_INITIALIZER;
  26.  
  27.         namespace
  28.         {
  29.             pthread_key_t epoch_tss_key;
  30.             pthread_once_t epoch_tss_key_flag=PTHREAD_ONCE_INIT;
  31.  
  32.             extern "C"
  33.             {
  34.                 static void delete_epoch_tss_data(void* data)
  35.                 {
  36.                     free(data);
  37.                 }
  38.  
  39.                 static void create_epoch_tss_key()
  40.                 {
  41.                     BOOST_VERIFY(!pthread_key_create(&epoch_tss_key,delete_epoch_tss_data));
  42.                 }
  43.             }
  44.  
  45. #if defined BOOST_THREAD_PATCH
  46.             const pthread_once_t pthread_once_init_value=PTHREAD_ONCE_INIT;
  47.             struct BOOST_THREAD_DECL delete_epoch_tss_key_on_dlclose_t
  48.             {
  49.                 delete_epoch_tss_key_on_dlclose_t()
  50.                 {
  51.                 }
  52.                 ~delete_epoch_tss_key_on_dlclose_t()
  53.                 {
  54.                     if(memcmp(&epoch_tss_key_flag, &pthread_once_init_value, sizeof(pthread_once_t)))
  55.                     {
  56.                         void* data = (void*)pthread_getspecific(epoch_tss_key);
  57.                         if (data)
  58.                             delete_epoch_tss_data(data);
  59.                         pthread_key_delete(epoch_tss_key);
  60.                     }
  61.                 }
  62.             };
  63.             delete_epoch_tss_key_on_dlclose_t delete_epoch_tss_key_on_dlclose;
  64. #endif
  65.         }
  66.  
  67.         uintmax_atomic_t& get_once_per_thread_epoch()
  68.         {
  69.             BOOST_VERIFY(!pthread_once(&epoch_tss_key_flag,create_epoch_tss_key));
  70.             void* data=pthread_getspecific(epoch_tss_key);
  71.             if(!data)
  72.             {
  73.                 data=malloc(sizeof(thread_detail::uintmax_atomic_t));
  74.                 if(!data) BOOST_THROW_EXCEPTION(std::bad_alloc());
  75.                 BOOST_VERIFY(!pthread_setspecific(epoch_tss_key,data));
  76.                 *static_cast<thread_detail::uintmax_atomic_t*>(data)=BOOST_THREAD_DETAIL_UINTMAX_ATOMIC_MAX_C;
  77.             }
  78.             return *static_cast<thread_detail::uintmax_atomic_t*>(data);
  79.         }
  80.     }
  81.  
  82. }
  83. #endif //
  84.  
downloadonce.cpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top