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
5c3c5066
Commit
5c3c5066
authored
Jan 10, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GlobalEvents: lock-less operation using std::atomic
Use a bit field instead of a mutex-protected bool array.
parent
ecd5eb02
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
39 deletions
+9
-39
GlobalEvents.cxx
src/GlobalEvents.cxx
+8
-31
GlobalEvents.hxx
src/GlobalEvents.hxx
+0
-7
SignalHandlers.cxx
src/SignalHandlers.cxx
+1
-1
No files found.
src/GlobalEvents.cxx
View file @
5c3c5066
...
...
@@ -20,9 +20,10 @@
#include "config.h"
#include "GlobalEvents.hxx"
#include "event/WakeFD.hxx"
#include "thread/Mutex.hxx"
#include "mpd_error.h"
#include <atomic>
#include <assert.h>
#include <glib.h>
#include <string.h>
...
...
@@ -34,8 +35,7 @@
namespace
GlobalEvents
{
static
WakeFD
wake_fd
;
static
guint
source_id
;
static
Mutex
mutex
;
static
bool
flags
[
MAX
];
static
std
::
atomic_uint
flags
;
static
Handler
handlers
[
MAX
];
}
...
...
@@ -59,15 +59,10 @@ GlobalEventCallback(G_GNUC_UNUSED GIOChannel *source,
if
(
!
GlobalEvents
::
wake_fd
.
Read
())
return
true
;
bool
events
[
GlobalEvents
::
MAX
];
GlobalEvents
::
mutex
.
lock
();
memcpy
(
events
,
GlobalEvents
::
flags
,
sizeof
(
events
));
memset
(
GlobalEvents
::
flags
,
0
,
sizeof
(
GlobalEvents
::
flags
));
GlobalEvents
::
mutex
.
unlock
();
const
unsigned
flags
=
GlobalEvents
::
flags
.
fetch_and
(
0
);
for
(
unsigned
i
=
0
;
i
<
GlobalEvents
::
MAX
;
++
i
)
if
(
events
[
i
]
)
if
(
flags
&
(
1u
<<
i
)
)
/* invoke the event handler */
InvokeGlobalEvent
(
GlobalEvents
::
Event
(
i
));
...
...
@@ -113,25 +108,7 @@ GlobalEvents::Emit(Event event)
{
assert
((
unsigned
)
event
<
MAX
);
mutex
.
lock
();
if
(
flags
[
event
])
{
/* already set: don't write */
mutex
.
unlock
();
return
;
}
flags
[
event
]
=
true
;
mutex
.
unlock
();
wake_fd
.
Write
();
}
void
GlobalEvents
::
FastEmit
(
Event
event
)
{
assert
((
unsigned
)
event
<
MAX
);
flags
[
event
]
=
true
;
wake_fd
.
Write
();
const
unsigned
mask
=
1u
<<
unsigned
(
event
);
if
((
GlobalEvents
::
flags
.
fetch_or
(
mask
)
&
mask
)
==
0
)
wake_fd
.
Write
();
}
src/GlobalEvents.hxx
View file @
5c3c5066
...
...
@@ -58,13 +58,6 @@ namespace GlobalEvents {
void
Register
(
Event
event
,
Handler
handler
);
void
Emit
(
Event
event
);
/**
* Similar to event_pipe_emit(), but aimed for use in signal handlers:
* it doesn't lock the mutex, and doesn't log on error. That makes it
* potentially lossy, but for its intended use, that does not matter.
*/
void
FastEmit
(
Event
event
);
}
#endif
/* MAIN_NOTIFY_H */
src/SignalHandlers.cxx
View file @
5c3c5066
...
...
@@ -40,7 +40,7 @@ static void exit_signal_handler(G_GNUC_UNUSED int signum)
static
void
reload_signal_handler
(
G_GNUC_UNUSED
int
signum
)
{
GlobalEvents
::
Fast
Emit
(
GlobalEvents
::
RELOAD
);
GlobalEvents
::
Emit
(
GlobalEvents
::
RELOAD
);
}
static
void
...
...
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