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
4ed895c7
Commit
4ed895c7
authored
Dec 28, 2008
by
Thomas Jansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dirvec: migrate from pthread to glib threads
parent
8332a704
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
17 deletions
+36
-17
dirvec.c
src/dirvec.c
+29
-17
dirvec.h
src/dirvec.h
+4
-0
main.c
src/main.c
+3
-0
No files found.
src/dirvec.c
View file @
4ed895c7
...
...
@@ -5,9 +5,8 @@
#include <string.h>
#include <glib.h>
#include <pthread.h>
static
pthread_mutex_t
nr_lock
=
PTHREAD_MUTEX_INITIALIZER
;
static
GMutex
*
nr_lock
=
NULL
;
static
size_t
dv_size
(
const
struct
dirvec
*
dv
)
{
...
...
@@ -22,11 +21,24 @@ static int dirvec_cmp(const void *d1, const void *d2)
return
strcmp
(
a
->
path
,
b
->
path
);
}
void
dirvec_init
(
void
)
{
g_assert
(
nr_lock
==
NULL
);
nr_lock
=
g_mutex_new
();
}
void
dirvec_deinit
(
void
)
{
g_assert
(
nr_lock
!=
NULL
);
g_mutex_free
(
nr_lock
);
nr_lock
=
NULL
;
}
void
dirvec_sort
(
struct
dirvec
*
dv
)
{
pthread_mutex_lock
(
&
nr_lock
);
g_mutex_lock
(
nr_lock
);
qsort
(
dv
->
base
,
dv
->
nr
,
sizeof
(
struct
directory
*
),
dirvec_cmp
);
pthread_mutex_unlock
(
&
nr_lock
);
g_mutex_unlock
(
nr_lock
);
}
struct
directory
*
dirvec_find
(
const
struct
dirvec
*
dv
,
const
char
*
path
)
...
...
@@ -37,13 +49,13 @@ struct directory *dirvec_find(const struct dirvec *dv, const char *path)
base
=
g_path_get_basename
(
path
);
pthread_mutex_lock
(
&
nr_lock
);
g_mutex_lock
(
nr_lock
);
for
(
i
=
dv
->
nr
;
--
i
>=
0
;
)
if
(
!
strcmp
(
directory_get_name
(
dv
->
base
[
i
]),
base
))
{
ret
=
dv
->
base
[
i
];
break
;
}
pthread_mutex_unlock
(
&
nr_lock
);
g_mutex_unlock
(
nr_lock
);
g_free
(
base
);
return
ret
;
...
...
@@ -53,13 +65,13 @@ int dirvec_delete(struct dirvec *dv, struct directory *del)
{
size_t
i
;
pthread_mutex_lock
(
&
nr_lock
);
g_mutex_lock
(
nr_lock
);
for
(
i
=
0
;
i
<
dv
->
nr
;
++
i
)
{
if
(
dv
->
base
[
i
]
!=
del
)
continue
;
/* we _don't_ call directory_free() here */
if
(
!--
dv
->
nr
)
{
pthread_mutex_unlock
(
&
nr_lock
);
g_mutex_unlock
(
nr_lock
);
free
(
dv
->
base
);
dv
->
base
=
NULL
;
return
i
;
...
...
@@ -70,25 +82,25 @@ int dirvec_delete(struct dirvec *dv, struct directory *del)
}
break
;
}
pthread_mutex_unlock
(
&
nr_lock
);
g_mutex_unlock
(
nr_lock
);
return
i
;
}
void
dirvec_add
(
struct
dirvec
*
dv
,
struct
directory
*
add
)
{
pthread_mutex_lock
(
&
nr_lock
);
g_mutex_lock
(
nr_lock
);
++
dv
->
nr
;
dv
->
base
=
xrealloc
(
dv
->
base
,
dv_size
(
dv
));
dv
->
base
[
dv
->
nr
-
1
]
=
add
;
pthread_mutex_unlock
(
&
nr_lock
);
g_mutex_unlock
(
nr_lock
);
}
void
dirvec_destroy
(
struct
dirvec
*
dv
)
{
pthread_mutex_lock
(
&
nr_lock
);
g_mutex_lock
(
nr_lock
);
dv
->
nr
=
0
;
pthread_mutex_unlock
(
&
nr_lock
);
g_mutex_unlock
(
nr_lock
);
if
(
dv
->
base
)
{
free
(
dv
->
base
);
dv
->
base
=
NULL
;
...
...
@@ -101,20 +113,20 @@ int dirvec_for_each(const struct dirvec *dv,
size_t
i
;
size_t
prev_nr
;
pthread_mutex_lock
(
&
nr_lock
);
g_mutex_lock
(
nr_lock
);
for
(
i
=
0
;
i
<
dv
->
nr
;
)
{
struct
directory
*
dir
=
dv
->
base
[
i
];
assert
(
dir
);
prev_nr
=
dv
->
nr
;
pthread_mutex_unlock
(
&
nr_lock
);
g_mutex_unlock
(
nr_lock
);
if
(
fn
(
dir
,
arg
)
<
0
)
return
-
1
;
pthread_mutex_lock
(
&
nr_lock
);
/* dv->nr may change in fn() */
g_mutex_lock
(
nr_lock
);
/* dv->nr may change in fn() */
if
(
prev_nr
==
dv
->
nr
)
++
i
;
}
pthread_mutex_unlock
(
&
nr_lock
);
g_mutex_unlock
(
nr_lock
);
return
0
;
}
src/dirvec.h
View file @
4ed895c7
...
...
@@ -8,6 +8,10 @@ struct dirvec {
size_t
nr
;
};
void
dirvec_init
(
void
);
void
dirvec_deinit
(
void
);
void
dirvec_sort
(
struct
dirvec
*
dv
);
struct
directory
*
dirvec_find
(
const
struct
dirvec
*
dv
,
const
char
*
path
);
...
...
src/main.c
View file @
4ed895c7
...
...
@@ -50,6 +50,7 @@
#include "zeroconf.h"
#include "main_notify.h"
#include "os_compat.h"
#include "dirvec.h"
#ifdef ENABLE_ARCHIVE
#include "archive_list.h"
...
...
@@ -269,6 +270,7 @@ int main(int argc, char *argv[])
g_thread_init
(
NULL
);
idle_init
();
dirvec_init
();
initConf
();
parseOptions
(
argc
,
argv
,
&
options
);
...
...
@@ -383,6 +385,7 @@ int main(int argc, char *argv[])
music_pipe_free
();
cleanUpPidFile
();
finishConf
();
dirvec_deinit
();
idle_deinit
();
close_log_files
();
...
...
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