Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
60df1b9b
Commit
60df1b9b
authored
Oct 01, 2009
by
Pavel Vaynerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
retuurn old mutex
parent
1c0d68d1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
134 additions
and
12 deletions
+134
-12
Mutex.h
include/Mutex.h
+26
-5
Mutex.cc
src/Various/Mutex.cc
+108
-7
No files found.
include/Mutex.h
View file @
60df1b9b
...
...
@@ -59,14 +59,13 @@ namespace UniSetTypes
{
return
nm
;
};
uniset_mutex
(
const
uniset_mutex
&
r
);
uniset_mutex
&
operator
=
(
const
uniset_mutex
&
r
);
protected
:
private
:
friend
class
uniset_mutex_lock
;
uniset_mutex
(
const
uniset_mutex
&
r
);
const
uniset_mutex
&
operator
=
(
const
uniset_mutex
&
r
);
omni_condition
*
cnd
;
std
::
string
nm
;
omni_semaphore
sem
;
...
...
@@ -100,10 +99,32 @@ namespace UniSetTypes
};
// -------------------------------------------------------------------------
class
uniset_spin_mutex
{
public
:
uniset_spin_mutex
();
~
uniset_spin_mutex
();
uniset_spin_mutex
(
const
uniset_spin_mutex
&
r
);
const
uniset_spin_mutex
&
operator
=
(
const
uniset_spin_mutex
&
r
);
void
lock
(
int
check_pause_msec
=
0
);
void
unlock
();
typedef
uniset_mutex
uniset_spin_mutex
;
typedef
uniset_mutex_lock
uniset_spin_lock
;
private
:
mutex_atomic_t
m
;
};
// -------------------------------------------------------------------------
class
uniset_spin_lock
{
public
:
uniset_spin_lock
(
uniset_spin_mutex
&
m
,
int
check_pause_msec
=
0
);
~
uniset_spin_lock
();
private
:
uniset_spin_lock
(
const
uniset_spin_lock
&
);
uniset_spin_lock
&
operator
=
(
const
uniset_spin_lock
&
);
uniset_spin_mutex
&
m
;
};
// -------------------------------------------------------------------------
}
// end of UniSetTypes namespace
...
...
src/Various/Mutex.cc
View file @
60df1b9b
...
...
@@ -134,21 +134,18 @@ bool uniset_mutex::isRelease()
#endif // HAVE_LINUX_FUTEX_H
// -----------------------------------------------------------------------------
uniset_mutex
&
uniset_mutex
::
operator
=
(
const
uniset_mutex
&
r
)
const
uniset_mutex
&
uniset_mutex
::
operator
=
(
const
uniset_mutex
&
r
)
{
if
(
this
!=
&
r
)
{
nm
=
r
.
nm
;
mutex_atomic_set
(
&
locked
,
0
);
cnd
=
new
omni_condition
(
&
mtx
);
}
locked
=
r
.
locked
;
return
*
this
;
}
uniset_mutex
::
uniset_mutex
(
const
uniset_mutex
&
r
)
:
cnd
(
0
),
nm
(
r
.
nm
)
{
mutex_atomic_set
(
&
locked
,
0
);
cnd
=
new
omni_condition
(
&
mtx
);
}
...
...
@@ -205,3 +202,107 @@ uniset_mutex_lock& uniset_mutex_lock::operator=(const uniset_mutex_lock &r)
return
*
this
;
}
// -----------------------------------------------------------------------------
#ifndef HAVE_LINUX_LIBC_HEADERS_INCLUDE_LINUX_FUTEX_H
uniset_spin_mutex
::
uniset_spin_mutex
()
{
unlock
();
}
uniset_spin_mutex
::~
uniset_spin_mutex
()
{
unlock
();
}
const
uniset_spin_mutex
&
uniset_spin_mutex
::
operator
=
(
const
uniset_spin_mutex
&
r
)
{
if
(
this
!=
&
r
)
unlock
();
return
*
this
;
}
uniset_spin_mutex
::
uniset_spin_mutex
(
const
uniset_spin_mutex
&
r
)
{
unlock
();
}
void
uniset_spin_mutex
::
lock
(
int
check_pause_msec
)
{
while
(
mutex_atomic_read
(
&
m
)
!=
0
)
{
if
(
check_pause_msec
>
0
)
msleep
(
check_pause_msec
);
}
mutex_atomic_set
(
&
m
,
1
);
}
void
uniset_spin_mutex
::
unlock
()
{
m
=
0
;
}
#else // HAVE_FUTEX
// mutex futex
// http://kerneldump.110mb.com/dokuwiki/doku.php?id=wiki:futexes_are_tricky_p3
// : http://people.redhat.com/drepper/futex.pdf
void
uniset_spin_mutex
::
lock
(
int
check_pause_msec
)
{
struct
timespec
tm
;
tm
.
tv_sec
=
check_pause_msec
/
1000
;
tm
.
tv_nsec
=
check_pause_msec
%
1000
;
int
c
;
if
(
(
c
=
cmpxchg
(
val
,
0
,
1
))
!=
0
)
{
do
{
if
(
c
==
2
||
cmpxchg
(
val
,
1
,
2
)
!=
0
)
{
if
(
futex_wait
(
&
val
,
2
,
tm
)
==
ETIMEDOUT
)
return
;
}
}
while
(
(
c
=
cmpxchg
(
val
,
0
,
2
))
!=
0
);
}
}
void
uniset_spin_mutex
::
unlock
()
{
if
(
atomic_dec
(
val
)
!=
1
)
{
val
=
0
;
futex_wake
(
&
val
,
1
);
}
}
#endif // HAVE_FUTEX
// -------------------------------------------------------------------------------------------
uniset_spin_lock
::
uniset_spin_lock
(
uniset_spin_mutex
&
_m
,
int
check_pause_msec
)
:
m
(
_m
)
{
m
.
lock
(
check_pause_msec
);
}
uniset_spin_lock
::~
uniset_spin_lock
()
{
m
.
unlock
();
}
uniset_spin_lock
::
uniset_spin_lock
(
const
uniset_spin_lock
&
r
)
:
m
(
r
.
m
)
{
}
uniset_spin_lock
&
uniset_spin_lock
::
operator
=
(
const
uniset_spin_lock
&
r
)
{
if
(
this
!=
&
r
)
m
=
r
.
m
;
return
*
this
;
}
// -----------------------------------------------------------------------------
#undef MUTEX_LOCK_SLEEP_MS
// -----------------------------------------------------------------------------
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment