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
248cd50a
Commit
248cd50a
authored
Dec 28, 2008
by
Thomas Jansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update & main_notify: migrate from pthread to glib threads
parent
195cec50
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
24 deletions
+30
-24
main_notify.c
src/main_notify.c
+17
-12
main_notify.h
src/main_notify.h
+2
-2
update.c
src/update.c
+11
-10
No files found.
src/main_notify.c
View file @
248cd50a
...
...
@@ -30,9 +30,9 @@
static
struct
ioOps
main_notify_IO
;
static
int
main_pipe
[
2
];
pthread_t
main_task
;
GThread
*
main_task
;
static
struct
notify
main_notify
;
static
pthread_mutex_t
select_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
static
GMutex
*
select_mutex
=
NULL
;
static
int
ioops_fdset
(
fd_set
*
rfds
,
G_GNUC_UNUSED
fd_set
*
wfds
,
...
...
@@ -65,12 +65,14 @@ static int ioops_consume(int fd_count, fd_set * rfds,
void
init_main_notify
(
void
)
{
main_task
=
pthread_self
();
g_assert
(
select_mutex
==
NULL
);
select_mutex
=
g_mutex_new
();
main_task
=
g_thread_self
();
init_async_pipe
(
main_pipe
);
main_notify_IO
.
fdset
=
ioops_fdset
;
main_notify_IO
.
consume
=
ioops_consume
;
registerIO
(
&
main_notify_IO
);
main_task
=
p
thread_self
();
main_task
=
g_
thread_self
();
notify_init
(
&
main_notify
);
}
...
...
@@ -80,19 +82,22 @@ void deinit_main_notify(void)
deregisterIO
(
&
main_notify_IO
);
xclose
(
main_pipe
[
0
]);
xclose
(
main_pipe
[
1
]);
g_assert
(
select_mutex
!=
NULL
);
g_mutex_free
(
select_mutex
);
select_mutex
=
NULL
;
}
static
int
wakeup_via_pipe
(
void
)
{
int
ret
=
pthread_mutex_trylock
(
&
select_mutex
);
if
(
ret
==
EBUSY
)
{
gboolean
ret
=
g_mutex_trylock
(
select_mutex
);
if
(
ret
==
FALSE
)
{
ssize_t
w
=
write
(
main_pipe
[
1
],
""
,
1
);
if
(
w
<
0
&&
errno
!=
EAGAIN
&&
errno
!=
EINTR
)
FATAL
(
"error writing to pipe: %s
\n
"
,
strerror
(
errno
));
return
1
;
}
else
{
pthread_mutex_unlock
(
&
select_mutex
);
g_mutex_unlock
(
select_mutex
);
return
0
;
}
}
...
...
@@ -107,19 +112,19 @@ void wakeup_main_task(void)
void
main_notify_lock
(
void
)
{
assert
(
pthread_equal
(
main_task
,
pthread_self
()
));
pthread_mutex_lock
(
&
select_mutex
);
assert
(
main_task
==
g_thread_self
(
));
g_mutex_lock
(
select_mutex
);
}
void
main_notify_unlock
(
void
)
{
assert
(
pthread_equal
(
main_task
,
pthread_self
()
));
pthread_mutex_unlock
(
&
select_mutex
);
assert
(
main_task
==
g_thread_self
(
));
g_mutex_unlock
(
select_mutex
);
}
void
wait_main_task
(
void
)
{
assert
(
pthread_equal
(
main_task
,
pthread_self
()
));
assert
(
main_task
==
g_thread_self
(
));
notify_wait
(
&
main_notify
);
}
...
...
src/main_notify.h
View file @
248cd50a
...
...
@@ -21,9 +21,9 @@
#ifndef MPD_MAIN_NOTIFY_H
#define MPD_MAIN_NOTIFY_H
#include <
pthread
.h>
#include <
glib
.h>
extern
pthread_t
main_task
;
extern
GThread
*
main_task
;
void
init_main_notify
(
void
);
...
...
src/update.c
View file @
248cd50a
...
...
@@ -47,7 +47,7 @@ static bool modified;
static
char
*
update_paths
[
32
];
static
size_t
update_paths_nr
;
static
pthread_t
update_thr
;
static
GThread
*
update_thr
;
static
const
unsigned
update_task_id_max
=
1
<<
15
;
...
...
@@ -595,15 +595,14 @@ static void * update_task(void *_path)
static
void
spawn_update_task
(
char
*
path
)
{
pthread_attr_t
attr
;
GError
*
e
;
assert
(
pthread_equal
(
pthread_self
(),
main_task
)
);
assert
(
g_thread_self
()
==
main_task
);
progress
=
UPDATE_PROGRESS_RUNNING
;
modified
=
false
;
pthread_attr_init
(
&
attr
);
if
(
pthread_create
(
&
update_thr
,
&
attr
,
update_task
,
path
))
FATAL
(
"Failed to spawn update task: %s
\n
"
,
strerror
(
errno
));
if
(
!
(
update_thr
=
g_thread_create
(
update_task
,
path
,
TRUE
,
&
e
)))
FATAL
(
"Failed to spawn update task: %s
\n
"
,
e
->
message
);
if
(
++
update_task_id
>
update_task_id_max
)
update_task_id
=
1
;
DEBUG
(
"spawned thread for update job id %i
\n
"
,
update_task_id
);
...
...
@@ -612,7 +611,7 @@ static void spawn_update_task(char *path)
unsigned
directory_update_init
(
char
*
path
)
{
assert
(
pthread_equal
(
pthread_self
(),
main_task
)
);
assert
(
g_thread_self
()
==
main_task
);
if
(
progress
!=
UPDATE_PROGRESS_IDLE
)
{
unsigned
next_task_id
;
...
...
@@ -635,7 +634,7 @@ directory_update_init(char *path)
void
reap_update_task
(
void
)
{
assert
(
pthread_equal
(
pthread_self
(),
main_task
)
);
assert
(
g_thread_self
()
==
main_task
);
if
(
progress
==
UPDATE_PROGRESS_IDLE
)
return
;
...
...
@@ -652,8 +651,7 @@ void reap_update_task(void)
if
(
progress
!=
UPDATE_PROGRESS_DONE
)
return
;
if
(
pthread_join
(
update_thr
,
NULL
))
FATAL
(
"error joining update thread: %s
\n
"
,
strerror
(
errno
));
g_thread_join
(
update_thr
);
if
(
modified
)
{
playlistVersionChange
();
...
...
@@ -679,8 +677,11 @@ void update_global_init(void)
follow_outside_symlinks
=
config_get_bool
(
CONF_FOLLOW_OUTSIDE_SYMLINKS
,
DEFAULT_FOLLOW_OUTSIDE_SYMLINKS
);
cond_init
(
&
delete_cond
);
}
void
update_global_finish
(
void
)
{
cond_destroy
(
&
delete_cond
);
}
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