Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SbThreadMutex.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2017 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : Julien Chaplier (MMM yyyy)
22**=======================================================================*/
23
24
25#ifndef _SB_THREAD_MUTEX_H_
26#define _SB_THREAD_MUTEX_H_
27
28#include <Inventor/SbBase.h>
29
30#ifdef _WIN32
31//#include <process.h>
32#else
33#include <pthread.h>
34#endif
35
66
67 public:
72
73#if 1 SoDEPRECATED
75 SbThreadMutex( const SbBool force );
76#endif
78#ifndef HIDDEN_FROM_DOC
80#endif // HIDDEN_FROM_DOC
81
92 int lock()
93 { if (mutex) return _lock(); else return 0; }
94
102 int unlock()
103 { if (mutex) return _unlock(); else return 0; }
104
113 { if (mutex) return _trylock(); else return 0; }
114
115private:
116#if defined(__linux__) || defined(__APPLE__)
117 pthread_mutex_t* getMutex() { return mutex; }
118#endif
119
120private:
121
122#ifdef _WIN32
123 void* mutex;
124#if defined(_DEBUG)
125 LONG volatile numLocks;
126 unsigned int m_lockOwner;
127#endif
128#else
129 pthread_mutex_t* mutex ;
130 pthread_mutexattr_t* mta;
131 pthread_t thread_id ;
132 int count ;
133#endif
134private:
135
136 // copy-constructing this class is invalid
137 SbThreadMutex(const SbThreadMutex& /*other*/)
138 {
139 }
140
141 // real implementation of each public method
142 // it avoid function call when not in multithread mode.
143 int _lock() ;
144 int _unlock() ;
145 SbBool _trylock();
146
148 void commonConstructor();
149};
150
151// keep this header for compatibility purpose
152#include <Inventor/threads/SbThreadAutoLock.h>
153
154#endif // _SB_THREAD_MUTEX_H_
155
156
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
int lock()
Locks the current thread on this mutex.
SbBool trylock()
Does basically the same as lock, but when a thread tries to gain ownership of this mutex and fails be...
SbThreadMutex()
Creates a mutex.
int unlock()
Relinquishes ownership of this mutex.
SoDEPRECATED SbThreadMutex(const SbBool force)
int SbBool
Boolean type.
Definition SbBase.h:87