Remote Call Framework 3.1
ThreadLibrary.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2019, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 3.1
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_RCF_THREADLIBRARY_HPP
20 #define INCLUDE_RCF_THREADLIBRARY_HPP
21 
22 #include <mutex>
23 #include <shared_mutex>
24 #include <thread>
25 
26 #include <cstdint>
27 
28 #include <RCF/Export.hpp>
29 
30 namespace RCF
31 {
32 
33 
34  typedef std::thread Thread;
35  typedef std::mutex Mutex;
36  typedef std::unique_lock<std::mutex> Lock;
37  typedef std::condition_variable Condition;
38  typedef std::recursive_mutex RecursiveMutex;
39  typedef std::unique_lock<std::recursive_mutex> RecursiveLock;
40 
41  typedef std::thread::id ThreadId;
42  typedef std::shared_timed_mutex ReadWriteMutex;
43  typedef std::shared_lock<std::shared_timed_mutex> ReadLock;
44  typedef std::unique_lock<std::shared_timed_mutex> WriteLock;
45 
46  typedef std::shared_ptr<RecursiveLock> RecursiveLockPtr;
47  typedef std::shared_ptr<RecursiveMutex> RecursiveMutexPtr;
48 
49  typedef std::shared_ptr<Thread> ThreadPtr;
50  typedef std::shared_ptr<ReadWriteMutex> ReadWriteMutexPtr;
51  typedef std::shared_ptr<Mutex> MutexPtr;
52  typedef std::shared_ptr<Lock> LockPtr;
53  typedef std::shared_ptr<Condition> ConditionPtr;
54 
55 
56  RCF_EXPORT ThreadId getCurrentThreadId();
57 
58  // Time in ms since ca 1970, modulo 65536 s (turns over every ~18.2 hrs).
59  RCF_EXPORT std::uint32_t getCurrentTimeMs();
60 
61  // Generate a timeout value for the given ending time.
62  // Returns zero if endTime <= current time <= endTime+10%of timer resolution, otherwise returns a nonzero duration in ms.
63  // Timer resolution as above (18.2 hrs).
64  static const unsigned int MaxTimeoutMs = (((unsigned int)-1)/10)*9;
65  RCF_EXPORT std::uint32_t generateTimeoutMs(unsigned int endTimeMs);
66 
67  RCF_EXPORT Mutex & getRootMutex();
68 
69  RCF_EXPORT void sleepMs(std::uint32_t msec);
70 }
71 
72 #endif // ! INCLUDE_RCF_THREADLIBRARY_HPP
Definition: AmiIoHandler.hpp:24