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
2f605a55
Commit
2f605a55
authored
Oct 02, 2009
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleaned
parent
811ba7ba
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
98 deletions
+6
-98
Mutex.h
include/Mutex.h
+6
-3
Mutex.cc
src/Various/Mutex.cc
+0
-95
No files found.
include/Mutex.h
View file @
2f605a55
...
...
@@ -104,13 +104,16 @@ namespace UniSetTypes
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
();
protected
:
uniset_spin_mutex
(
const
uniset_spin_mutex
&
r
);
const
uniset_spin_mutex
&
operator
=
(
const
uniset_spin_mutex
&
r
);
private
:
friend
class
uniset_spin_lock
;
mutex_atomic_t
m
;
};
// -------------------------------------------------------------------------
...
...
src/Various/Mutex.cc
View file @
2f605a55
...
...
@@ -38,7 +38,6 @@ static mutex_atomic_t mutex_atomic_set( mutex_atomic_t* m, int val ){ return (*m
//static void mutex_atomic_inc( mutex_atomic_t* m ){ (*m)++; }
//static void mutex_atomic_dec( mutex_atomic_t* m ){ (*m)--; }
// -----------------------------------------------------------------------------
#ifndef HAVE_LINUX_LIBC_HEADERS_INCLUDE_LINUX_FUTEX_H
uniset_mutex
::
uniset_mutex
()
:
cnd
(
0
),
nm
(
""
)
...
...
@@ -79,61 +78,6 @@ bool uniset_mutex::isRelease()
return
(
bool
)
!
mutex_atomic_read
(
&
locked
);
}
// -----------------------------------------------------------------------------
#else // HAVE_LINUX_FUTEX_H
// -----------------------------------------------------------------------------
// mutex futex
// http://kerneldump.110mb.com/dokuwiki/doku.php?id=wiki:futexes_are_tricky_p3
// : http://people.redhat.com/drepper/futex.pdf
uniset_mutex
::
uniset_mutex
()
:
val
(
0
),
nm
(
""
)
{
}
uniset_mutex
::
uiset_mutex
(
std
::
string
name
)
val
(
0
),
nm
(
name
)
{
}
uniset_mutex
::~
uniset_mutex
()
{
unlock
();
}
void
uniset_mutex
::
lock
()
{
int
c
;
if
(
(
c
=
cmpxchg
(
val
,
0
,
1
))
!=
0
)
{
do
{
if
(
c
==
2
||
cmpxchg
(
val
,
1
,
2
)
!=
0
)
futex_wait
(
&
val
,
2
);
}
while
(
(
c
=
cmpxchg
(
val
,
0
,
2
))
!=
0
);
}
}
void
uniset_mutex
::
unlock
()
{
if
(
atomic_dec
(
val
)
!=
1
)
{
val
=
0
;
futex_wake
(
&
val
,
1
);
}
}
bool
uniset_mutex
::
isRelease
()
{
return
(
bool
)
cmpxchg
(
val
,
1
,
2
);
}
// -----------------------------------------------------------------------------
#endif // HAVE_LINUX_FUTEX_H
// -----------------------------------------------------------------------------
const
uniset_mutex
&
uniset_mutex
::
operator
=
(
const
uniset_mutex
&
r
)
{
if
(
this
!=
&
r
)
...
...
@@ -202,8 +146,6 @@ 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
();
...
...
@@ -241,43 +183,6 @@ 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
)
...
...
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