Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_SharedAccessPolicy.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TEUCHOS_SHARED_ACCESS_POLICY_HPP
11 #define TEUCHOS_SHARED_ACCESS_POLICY_HPP
12 
13 
14 #include "Teuchos_ConfigDefs.hpp"
15 
16 
17 //
18 // WARNING: This current file is just for iterating on the design of thread
19 // safety in Teuchos and is not working code yet!
20 //
21 
22 
23 namespace Teuchos {
24 
25 
33 class ThreadLock {
34 public:
36  ThreadLock();
38  ~ThreadLock();
40  bool try_lock();
42  void lock();
44  void unlock();
45 };
46 
47 
56 template<class T>
58 public:
60  explicit ScopedThreadLock(ThreadLock &lock);
63 };
64 
65 
87 public:
93  typedef int atomic_integral_type;
95  inline static void atomic_set( atomic_integral_type * p,
96  const atomic_integral_type v );
98  inline static const atomic_integral_type
101  inline static void atomic_increment( atomic_integral_type * p );
103  inline static void atomic_decrement( atomic_integral_type * p );
104  // ToDo: Define some other basic fetch/increment primatives needed for
105  // better performance, for example, for Teuchos::RCPNode.
106 };
107 
108 
109 } // namespace Teuchos
110 
111 
112 #endif /* TEUCHOS_SHARED_ACCESS_POLICY_HPP */
static void atomic_increment(atomic_integral_type *p)
Atomic increment of a shared integral object.
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
Basic portable thread lock primative class.
int atomic_integral_type
Supported type for shared integral objects.
ScopedThreadLock(ThreadLock &lock)
static void atomic_decrement(atomic_integral_type *p)
Atomic decrement of a shared integral object.
static const atomic_integral_type atomic_fetch(const atomic_integral_type *p)
Atomic fetch a shared integral object.
Single policy class defining an approach for sharing an integral object across threads as well as a g...
static void atomic_set(atomic_integral_type *p, const atomic_integral_type v)
Atomic setting a shared integral object.
Stack-based object for locking a thread.