1
///////////////////////////////////////////////////////////////////////////
3
// Copyright (c) 2005, Industrial Light & Magic, a division of Lucas
6
// All rights reserved.
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are
11
// * Redistributions of source code must retain the above copyright
12
// notice, this list of conditions and the following disclaimer.
13
// * Redistributions in binary form must reproduce the above
14
// copyright notice, this list of conditions and the following disclaimer
15
// in the documentation and/or other materials provided with the
17
// * Neither the name of Industrial Light & Magic nor the names of
18
// its contributors may be used to endorse or promote products derived
19
// from this software without specific prior written permission.
21
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
///////////////////////////////////////////////////////////////////////////
35
#ifndef INCLUDED_ILM_THREAD_MUTEX_H
36
#define INCLUDED_ILM_THREAD_MUTEX_H
38
//-----------------------------------------------------------------------------
40
// class Mutex, class Lock
42
// Class Mutex is a wrapper for a system-dependent mutual exclusion
43
// mechanism. Actual locking and unlocking of a Mutex object must
44
// be performed using an instance of a Lock (defined below).
46
// Class lock provides safe locking and unlocking of mutexes even in
47
// the presence of C++ exceptions. Constructing a Lock object locks
48
// the mutex; destroying the Lock unlocks the mutex.
50
// Lock objects are not themselves thread-safe. You should never
51
// share a Lock object among multiple threads.
55
// Mutex mtx; // Create a Mutex object that is visible
56
// //to multiple threads
58
// ... // create some threads
60
// // Then, within each thread, construct a critical section like so:
63
// Lock lock (mtx); // Lock constructor locks the mutex
64
// ... // do some computation on shared data
65
// } // leaving the block unlocks the mutex
67
//-----------------------------------------------------------------------------
69
#include "IlmBaseConfig.h"
71
#if defined _WIN32 || defined _WIN64
98
#if defined _WIN32 || defined _WIN64
99
mutable CRITICAL_SECTION _mutex;
101
mutable pthread_mutex_t _mutex;
104
void operator = (const Mutex& M); // not implemented
105
Mutex (const Mutex& M); // not implemented
115
Lock (const Mutex& m, bool autoLock = true):
151
const Mutex & _mutex;
156
} // namespace IlmThread
1
///////////////////////////////////////////////////////////////////////////
3
// Copyright (c) 2005, Industrial Light & Magic, a division of Lucas
6
// All rights reserved.
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are
11
// * Redistributions of source code must retain the above copyright
12
// notice, this list of conditions and the following disclaimer.
13
// * Redistributions in binary form must reproduce the above
14
// copyright notice, this list of conditions and the following disclaimer
15
// in the documentation and/or other materials provided with the
17
// * Neither the name of Industrial Light & Magic nor the names of
18
// its contributors may be used to endorse or promote products derived
19
// from this software without specific prior written permission.
21
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
///////////////////////////////////////////////////////////////////////////
35
#ifndef INCLUDED_ILM_THREAD_MUTEX_H
36
#define INCLUDED_ILM_THREAD_MUTEX_H
38
//-----------------------------------------------------------------------------
40
// class Mutex, class Lock
42
// Class Mutex is a wrapper for a system-dependent mutual exclusion
43
// mechanism. Actual locking and unlocking of a Mutex object must
44
// be performed using an instance of a Lock (defined below).
46
// Class lock provides safe locking and unlocking of mutexes even in
47
// the presence of C++ exceptions. Constructing a Lock object locks
48
// the mutex; destroying the Lock unlocks the mutex.
50
// Lock objects are not themselves thread-safe. You should never
51
// share a Lock object among multiple threads.
55
// Mutex mtx; // Create a Mutex object that is visible
56
// //to multiple threads
58
// ... // create some threads
60
// // Then, within each thread, construct a critical section like so:
63
// Lock lock (mtx); // Lock constructor locks the mutex
64
// ... // do some computation on shared data
65
// } // leaving the block unlocks the mutex
67
//-----------------------------------------------------------------------------
69
#include "IlmBaseConfig.h"
71
#if defined _WIN32 || defined _WIN64
98
#if defined _WIN32 || defined _WIN64
99
mutable CRITICAL_SECTION _mutex;
101
mutable pthread_mutex_t _mutex;
104
void operator = (const Mutex& M); // not implemented
105
Mutex (const Mutex& M); // not implemented
115
Lock (const Mutex& m, bool autoLock = true):
151
const Mutex & _mutex;
156
} // namespace IlmThread