1 #ifndef CC_THREADUTILP_H
2 #define CC_THREADUTILP_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #ifndef COIN_INTERNAL
37 #error this is a private header file
38 #endif /* ! COIN_INTERNAL */
39 
40 #ifdef HAVE_CONFIG_H
41 #include <config.h>
42 #endif /* HAVE_CONFIG_H */
43 
44 #ifdef HAVE_THREADS
45 
46 #include <Inventor/C/threads/mutex.h>
47 #include <Inventor/C/threads/sync.h>
48 
49 #include "threads/mutexp.h"
50 
51 #define CC_MUTEX_CONSTRUCT(_mymutex_) \
52   do { \
53     cc_mutex_global_lock(); \
54     if (_mymutex_ == NULL) { \
55       _mymutex_ = static_cast<void*>(cc_mutex_construct()); \
56     } \
57     cc_mutex_global_unlock(); \
58   } while (0)
59 
60 #define CC_MUTEX_DESTRUCT(_mymutex_) \
61   cc_mutex_destruct(static_cast<cc_mutex*>(_mymutex_));     \
62   _mymutex_ = NULL
63 
64 #define CC_MUTEX_LOCK(_mymutex_) \
65   cc_mutex_lock(static_cast<cc_mutex *>(_mymutex_))
66 
67 #define CC_MUTEX_UNLOCK(_mymutex_) \
68   cc_mutex_unlock(static_cast<cc_mutex *>(_mymutex_))
69 
70 #define CC_SYNC_BEGIN(_myid_) \
71   void * coin_mydummysyncptr = cc_sync_begin((void*) _myid_)
72 
73 #define CC_SYNC_END(_myid_) \
74   cc_sync_end(coin_mydummysyncptr)
75 
76 #define CC_GLOBAL_LOCK cc_mutex_global_lock()
77 #define CC_GLOBAL_UNLOCK cc_mutex_global_unlock()
78 
79 #else /* ! HAVE_THREADS */
80 
81 #define CC_MUTEX_CONSTRUCT(_mymutex_)  do { } while (0)
82 #define CC_MUTEX_DESTRUCT(_mymutex_)  do { } while (0)
83 #define CC_MUTEX_LOCK(_mymutex_)  do { } while (0)
84 #define CC_MUTEX_UNLOCK(_mymutex_)  do { } while (0)
85 #define CC_SYNC_BEGIN(_myid_)  do { } while (0)
86 #define CC_SYNC_END(_myid_)  do { } while (0)
87 #define CC_GLOBAL_LOCK  do { } while (0)
88 #define CC_GLOBAL_UNLOCK  do { } while (0)
89 
90 #endif /* ! HAVE_THREADS */
91 
92 #endif /* CC_THREADUTILP_H */
93