libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
thread_api_traits.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2004 by J.M.McGuiness, coder@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 
7 ** License as published by the Free Software Foundation; either
8 ** version 2.1 of the License, or (at your option) any later version.
9 **
10 ** This library is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ** Lesser General Public License for more details.
14 **
15 ** You should have received a copy of the GNU Lesser General Public
16 ** License along with this library; if not, write to the Free Software
17 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 #include "../core/exception.hpp"
21 #include "../core/atomic_counter.hpp"
22 
23 #include <atomic>
24 #include <csignal>
25 
26 #include <errno.h>
27 #include <pthread.h>
28 
29 #if _POSIX_C_SOURCE<200112L
30 #error "POSIX semaphores, sem_*()s, required for this library. Also link with -lrt or -pthread to include the sem_*()s."
31 #endif
32 
33 #include <semaphore.h>
34 
35 namespace jmmcg { namespace LIBJMMCG_VER_NAMESPACE { namespace ppd {
36 
37  namespace pthreads {
38  class anon_mutex;
39  class nonrecursive_anon_mutex;
40  class recursive_anon_mutex;
41  class anon_semaphore;
42  class critical_section;
43  class mutex;
44  class recursive_mutex;
45  class event;
46  class anon_semaphore;
47  class semaphore;
48  }
49 
50  /// The various lock-types for POSIX-threads derived, platforms.
51  template<>
60  atom_deadlocked=EDEADLK,
62  atom_failed=ESRCH,
64  atom_nomemory=ENOMEM,
65  atom_unset=ETIMEDOUT,
66  atom_sem_overflow=EOVERFLOW,
67  atom_errno=-1
68  };
69 
82  template<class V>
84  template<class V>
86  template<class V>
90  using timeout_type=unsigned long;
91  template<class... T>
93 
95 
96  static constexpr timeout_type __fastcall infinite_timeout() noexcept(true) FORCE_INLINE {
97  return ~static_cast<timeout_type>(0);
98  }
99 
100  api_lock_traits()=delete;
101  };
102 
103  template<>
105 
106 } } }
107