Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
483ba5ea
Commit
483ba5ea
authored
Jan 10, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
thread/GLibMutex: new Mutex implementation
Switch WIN32 to this implementation to be able to use condition variables, which is impossible with CriticalSection.
parent
18076ac9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
20 deletions
+45
-20
Makefile.am
Makefile.am
+1
-1
GLibMutex.hxx
src/thread/GLibMutex.hxx
+42
-17
Mutex.hxx
src/thread/Mutex.hxx
+2
-2
No files found.
Makefile.am
View file @
483ba5ea
...
...
@@ -163,7 +163,7 @@ src_mpd_SOURCES = \
$(MIXER_API_SRC)
\
src/thread/Mutex.hxx
\
src/thread/PosixMutex.hxx
\
src/thread/
CriticalSection
.hxx
\
src/thread/
GLibMutex
.hxx
\
src/glib_socket.h
\
src/clock.c src/clock.h
\
src/notify.c
\
...
...
src/thread/
CriticalSection
.hxx
→
src/thread/
GLibMutex
.hxx
View file @
483ba5ea
/*
* Copyright (C) 20
09-20
13 Max Kellermann <max@duempel.org>
* Copyright (C) 2013 Max Kellermann <max@duempel.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
...
...
@@ -27,36 +27,61 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MPD_THREAD_
CRITICAL_SECTION
_HXX
#define MPD_THREAD_
CRITICAL_SECTION
_HXX
#ifndef MPD_THREAD_
GLIB_MUTEX
_HXX
#define MPD_THREAD_
GLIB_MUTEX
_HXX
#include <
windows
.h>
#include <
glib
.h>
class
CriticalSection
{
CRITICAL_SECTION
critical_section
;
/**
* A wrapper for GMutex.
*/
class
GLibMutex
{
#if GLIB_CHECK_VERSION(2,32,0)
GMutex
mutex
;
#else
GMutex
*
mutex
;
#endif
public
:
CriticalSection
()
{
::
InitializeCriticalSection
(
&
critical_section
);
GLibMutex
()
{
#if GLIB_CHECK_VERSION(2,32,0)
g_mutex_init
(
&
mutex
);
#else
mutex
=
g_mutex_new
();
#endif
}
~
CriticalSection
()
{
::
DeleteCriticalSection
(
&
critical_section
);
~
GLibMutex
()
{
#if GLIB_CHECK_VERSION(2,32,0)
g_mutex_clear
(
&
mutex
);
#else
g_mutex_free
(
mutex
);
#endif
}
CriticalSection
(
const
CriticalSection
&
other
)
=
delete
;
CriticalSection
&
operator
=
(
const
CriticalSection
&
other
)
=
delete
;
GLibMutex
(
const
GLibMutex
&
other
)
=
delete
;
GLibMutex
&
operator
=
(
const
GLibMutex
&
other
)
=
delete
;
private
:
GMutex
*
GetNative
()
{
#if GLIB_CHECK_VERSION(2,32,0)
return
&
mutex
;
#else
return
mutex
;
#endif
}
public
:
void
lock
()
{
::
EnterCriticalSection
(
&
critical_section
);
}
;
g_mutex_lock
(
GetNative
()
);
}
bool
try_lock
()
{
return
::
TryEnterCriticalSection
(
&
critical_section
)
!=
0
;
}
;
return
g_mutex_trylock
(
GetNative
())
;
}
void
unlock
()
{
::
LeaveCriticalSection
(
&
critical_section
);
g_mutex_lock
(
GetNative
()
);
}
};
...
...
src/thread/Mutex.hxx
View file @
483ba5ea
...
...
@@ -24,8 +24,8 @@
/* mingw-w64 4.6.3 lacks a std::mutex implementation */
#include "
CriticalSection
.hxx"
typedef
CriticalSection
Mutex
;
#include "
GLibMutex
.hxx"
typedef
GLibMutex
Mutex
;
#else
...
...
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