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
6f2e1c24
Commit
6f2e1c24
authored
Feb 27, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GlobalEvents: use g_idle_add() instead of WakeFD()
Use the GMainLoop specific function to wake up the main loop. This is simpler and comes with very little overhead.
parent
fc0ad867
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
27 deletions
+4
-27
GlobalEvents.cxx
src/GlobalEvents.cxx
+4
-27
No files found.
src/GlobalEvents.cxx
View file @
6f2e1c24
...
...
@@ -19,21 +19,16 @@
#include "config.h"
#include "GlobalEvents.hxx"
#include "event/WakeFD.hxx"
#include "mpd_error.h"
#include <atomic>
#include <assert.h>
#include <glib.h>
#include <string.h>
#include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "global_events"
namespace
GlobalEvents
{
static
WakeFD
wake_fd
;
static
guint
source_id
;
static
std
::
atomic_uint
flags
;
static
Handler
handlers
[
MAX
];
...
...
@@ -52,13 +47,8 @@ InvokeGlobalEvent(GlobalEvents::Event event)
}
static
gboolean
GlobalEventCallback
(
G_GNUC_UNUSED
GIOChannel
*
source
,
G_GNUC_UNUSED
GIOCondition
condition
,
G_GNUC_UNUSED
gpointer
data
)
GlobalEventCallback
(
G_GNUC_UNUSED
gpointer
data
)
{
if
(
!
GlobalEvents
::
wake_fd
.
Read
())
return
true
;
const
unsigned
flags
=
GlobalEvents
::
flags
.
exchange
(
0
);
for
(
unsigned
i
=
0
;
i
<
GlobalEvents
::
MAX
;
++
i
)
...
...
@@ -66,32 +56,19 @@ GlobalEventCallback(G_GNUC_UNUSED GIOChannel *source,
/* invoke the event handler */
InvokeGlobalEvent
(
GlobalEvents
::
Event
(
i
));
return
tru
e
;
return
fals
e
;
}
void
GlobalEvents
::
Initialize
()
{
if
(
!
wake_fd
.
Create
())
MPD_ERROR
(
"Couldn't open pipe: %s"
,
strerror
(
errno
));
#ifndef G_OS_WIN32
GIOChannel
*
channel
=
g_io_channel_unix_new
(
wake_fd
.
Get
());
#else
GIOChannel
*
channel
=
g_io_channel_win32_new_socket
(
wake_fd
.
Get
());
#endif
source_id
=
g_io_add_watch
(
channel
,
G_IO_IN
,
GlobalEventCallback
,
NULL
);
g_io_channel_unref
(
channel
);
}
void
GlobalEvents
::
Deinitialize
()
{
if
(
source_id
!=
0
)
g_source_remove
(
source_id
);
wake_fd
.
Destroy
();
}
void
...
...
@@ -110,5 +87,5 @@ GlobalEvents::Emit(Event event)
const
unsigned
mask
=
1u
<<
unsigned
(
event
);
if
(
GlobalEvents
::
flags
.
fetch_or
(
mask
)
==
0
)
wake_fd
.
Write
(
);
source_id
=
g_idle_add
(
GlobalEventCallback
,
nullptr
);
}
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