Orfeo Toolbox  3.16
itkTimeStamp.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkTimeStamp.cxx,v $
5  Language: C++
6  Date: $Date: 2009-03-05 10:22:03 $
7  Version: $Revision: 1.19 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  Portions of this code are covered under the VTK copyright.
13  See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14 
15  This software is distributed WITHOUT ANY WARRANTY; without even
16  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17  PURPOSE. See the above copyright notices for more information.
18 
19 =========================================================================*/
20 #include "itkTimeStamp.h"
21 #include "itkFastMutexLock.h"
22 
23 #if defined(_WIN32)
24  #include "itkWindows.h"
25 
26 #elif defined(__APPLE__)
27 // OSAtomic.h optimizations only used in 10.5 and later
28  #include <AvailabilityMacros.h>
29  #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
30  #include <libkern/OSAtomic.h>
31  #endif
32 
33 #elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
34  #if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2))
35  # include <ext/atomicity.h>
36  #else
37  # include <bits/atomicity.h>
38  #endif
39 
40 #endif
41 
42 
43 namespace itk
44 {
45 
46 #if defined(__GLIBCXX__) // g++ 3.4+
47 
48 using __gnu_cxx::__exchange_and_add;
49 
50 #endif
51 
55 TimeStamp*
58 {
59  return new Self;
60 }
61 
62 
66 void
69 {
70  // Windows optimization
71 #if defined(WIN32) || defined(_WIN32)
72  static LONG itkTimeStampTime = 0;
73  m_ModifiedTime = (unsigned long)InterlockedIncrement(&itkTimeStampTime);
74 
75  // Mac optimization
76 #elif defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
77  #if __LP64__
78  // "m_ModifiedTime" is "unsigned long", a type that changess sizes
79  // depending on architecture. The atomic increment is safe, since it
80  // operates on a variable of the exact type needed. The cast does not
81  // change the size, but does change signedness, which is not ideal.
82  static volatile int64_t itkTimeStampTime = 0;
83  m_ModifiedTime = (unsigned long)OSAtomicIncrement64Barrier(&itkTimeStampTime);
84  #else
85  static volatile int32_t itkTimeStampTime = 0;
86  m_ModifiedTime = (unsigned long)OSAtomicIncrement32Barrier(&itkTimeStampTime);
87  #endif
88 
89 // gcc optimization
90 #elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
91  // We start from 1 since __exchange_and_add returns the old (non-incremented)
92  // value. This is not really necessary but will make the absolute value of the
93  // timestamp more consistent across platforms.
94  static volatile _Atomic_word itkTimeStampTime = 1;
95  m_ModifiedTime = (unsigned long)__exchange_and_add(&itkTimeStampTime, 1);
96 
97 // General case
98 #else
99 
102  static unsigned long itkTimeStampTime = 0;
103 
105  static SimpleFastMutexLock TimeStampMutex;
106 
107  TimeStampMutex.Lock();
108  m_ModifiedTime = ++itkTimeStampTime;
109  TimeStampMutex.Unlock();
110 #endif
111 
112 
113 }
114 
115 } // end namespace itk

Generated at Sun Feb 3 2013 00:10:03 for Orfeo Toolbox with doxygen 1.8.1.1