SystemC
3.0.0
Accellera SystemC proof-of-concept library
sysc
communication
sc_host_mutex.h
Go to the documentation of this file.
1
/*****************************************************************************
2
3
Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4
more contributor license agreements. See the NOTICE file distributed
5
with this work for additional information regarding copyright ownership.
6
Accellera licenses this file to you under the Apache License, Version 2.0
7
(the "License"); you may not use this file except in compliance with the
8
License. You may obtain a copy of the License at
9
10
http://www.apache.org/licenses/LICENSE-2.0
11
12
Unless required by applicable law or agreed to in writing, software
13
distributed under the License is distributed on an "AS IS" BASIS,
14
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
implied. See the License for the specific language governing
16
permissions and limitations under the License.
17
18
*****************************************************************************/
19
20
/*****************************************************************************
21
22
sc_host_mutex.h -- A "real" mutex for the underlying host system
23
24
Original Author: Philipp A. Hartmann, OFFIS
25
26
CHANGE LOG AT THE END OF THE FILE
27
*****************************************************************************/
28
29
#ifndef SC_HOST_MUTEX_H_INCLUDED_
30
#define SC_HOST_MUTEX_H_INCLUDED_
31
32
#include "
sysc/kernel/sc_cmnhdr.h
"
33
#include "
sysc/communication/sc_mutex_if.h
"
34
35
#include <mutex>
36
37
#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
38
# pragma warning(push)
39
# pragma warning(disable: 4251)
// DLL import for std::mutex
40
#endif
41
42
namespace
sc_core
{
43
44
// ----------------------------------------------------------------------------
45
// CLASS : sc_host_mutex
46
//
47
// The sc_host_mutex class, wrapping an OS mutex on the simulation host
48
// ----------------------------------------------------------------------------
49
50
class
SC_API
sc_host_mutex
:
public
sc_mutex_if
51
{
52
public
:
53
54
// constructors and destructor
55
56
sc_host_mutex
() =
default
;
57
virtual
~sc_host_mutex
() =
default
;
58
59
// interface methods
60
61
// blocks until mutex could be locked
62
virtual
int
lock
()
63
{ m_mtx.lock();
return
0; }
64
65
// returns -1 if mutex could not be locked
66
virtual
int
trylock
()
67
{
return
m_mtx.try_lock() ? 0 : -1; }
68
69
// should return -1 if mutex was not locked by caller,
70
// but is not yet able to check this
71
virtual
int
unlock
()
72
{ m_mtx.unlock();
return
0; }
73
74
private
:
75
std::mutex m_mtx;
76
};
77
78
}
// namespace sc_core
79
80
#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
81
# pragma warning(pop)
82
#endif
83
84
/*****************************************************************************
85
86
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
87
changes you are making here.
88
89
Name, Affiliation, Date:
90
Description of Modification:
91
*****************************************************************************/
92
//$Log: sc_host_mutex.h,v $
93
//Revision 1.4 2011/08/30 21:53:23 acg
94
// Jerome Cornet: include window.h for gnu c in windows case.
95
//
96
//Revision 1.3 2011/08/07 19:08:01 acg
97
// Andy Goodrich: moved logs to end of file so line number synching works
98
// better between versions.
99
//
100
//Revision 1.2 2011/06/25 17:08:38 acg
101
// Andy Goodrich: Jerome Cornet's changes to use libtool to build the
102
// library.
103
//
104
//Revision 1.1 2011/04/18 19:04:11 acg
105
// Philipp A. Hartmann: first check in of file.
106
//
107
108
#endif
109
110
// Taf!
sc_cmnhdr.h
SC_API
#define SC_API
Definition:
sc_cmnhdr.h:148
sc_mutex_if.h
sc_core
Definition:
sc_buffer.h:36
sc_core::sc_host_mutex
Definition:
sc_host_mutex.h:51
sc_core::sc_host_mutex::trylock
virtual int trylock()
Definition:
sc_host_mutex.h:66
sc_core::sc_host_mutex::~sc_host_mutex
virtual ~sc_host_mutex()=default
sc_core::sc_host_mutex::unlock
virtual int unlock()
Definition:
sc_host_mutex.h:71
sc_core::sc_host_mutex::sc_host_mutex
sc_host_mutex()=default
sc_core::sc_host_mutex::lock
virtual int lock()
Definition:
sc_host_mutex.h:62
sc_core::sc_mutex_if
Definition:
sc_mutex_if.h:44
Generated on Fri Aug 16 2024 16:36:33 for SystemC by
1.9.4