aboutsummaryrefslogtreecommitdiffstats
path: root/src/directory.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2006-07-30 03:43:38 +0000
committerEric Wong <normalperson@yhbt.net>2006-07-30 03:43:38 +0000
commit4cf5d04ca15bc28ee4636d1dccb858763513e571 (patch)
tree7898902e786f5763643a513ea96bcada8a2559cc /src/directory.c
parent4d5b8509eb46cff40890b781018669233a79e414 (diff)
downloadmpd-4cf5d04ca15bc28ee4636d1dccb858763513e571.tar.gz
mpd-4cf5d04ca15bc28ee4636d1dccb858763513e571.tar.xz
mpd-4cf5d04ca15bc28ee4636d1dccb858763513e571.zip
interface/connection malloc reductions from mpd-ke
This patch massively reduces the amount of heap allocations at the interface/command layer. Most commands with minimal output should not allocate memory from the heap at all. Things like repeatedly polling status, currentsong, and volume changes should be faster as a result, and more importantly, not a source of memory fragmentation. These changes should be safe in that there's no way for a remote-client to corrupt memory or otherwise do bad stuff to MPD, but an extra set of eyes to review would be good. Of course there's never any warranty :) No longer do we use FILE * structures in the interface, which means we don't have to allocate any new memory for most connections. Now, before you go on about losing the buffering that FILE * +implies+, remember that myfprintf() never took advantage of any of the stdio buffering features. To reduce the diff and make bugs easier to spot in the diff, I've kept myfprintf in places where we write to files (and not network interfaces). Expect myfprintf to go away entirely soon (we'll use fprintf for writing regular files). git-svn-id: https://svn.musicpd.org/mpd/trunk@4483 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/directory.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/src/directory.c b/src/directory.c
index 85060670a..0bf2b6453 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -159,10 +159,10 @@ void readDirectoryDBIfUpdateIsFinished()
}
}
-int updateInit(FILE * fp, List * pathList)
+int updateInit(int fd, List * pathList)
{
if (directory_updatePid > 0) {
- commandError(fp, ACK_ERROR_UPDATE_ALREADY, "already updating",
+ commandError(fd, ACK_ERROR_UPDATE_ALREADY, "already updating",
NULL);
return -1;
}
@@ -216,7 +216,7 @@ int updateInit(FILE * fp, List * pathList)
} else if (directory_updatePid < 0) {
unblockSignals();
ERROR("updateInit: Problems forking()'ing\n");
- commandError(fp, ACK_ERROR_SYSTEM,
+ commandError(fd, ACK_ERROR_SYSTEM,
"problems trying to update", NULL);
directory_updatePid = 0;
return -1;
@@ -228,7 +228,7 @@ int updateInit(FILE * fp, List * pathList)
directory_updateJobId = 1;
DEBUG("updateInit: fork()'d update child for update job id %i\n",
(int)directory_updateJobId);
- myfprintf(fp, "updating_db: %i\n", (int)directory_updateJobId);
+ fdprintf(fd, "updating_db: %i\n", (int)directory_updateJobId);
return 0;
}
@@ -871,33 +871,33 @@ static Directory *getDirectory(char *name)
return getSubDirectory(mp3rootDirectory, name, &shortname);
}
-static int printDirectoryList(FILE * fp, DirectoryList * directoryList)
+static int printDirectoryList(int fd, DirectoryList * directoryList)
{
ListNode *node = directoryList->firstNode;
Directory *directory;
while (node != NULL) {
directory = (Directory *) node->data;
- myfprintf(fp, "%s%s\n", DIRECTORY_DIR,
- getDirectoryPath(directory));
+ fdprintf(fd, "%s%s\n", DIRECTORY_DIR,
+ getDirectoryPath(directory));
node = node->nextNode;
}
return 0;
}
-int printDirectoryInfo(FILE * fp, char *name)
+int printDirectoryInfo(int fd, char *name)
{
Directory *directory;
if ((directory = getDirectory(name)) == NULL) {
- commandError(fp, ACK_ERROR_NO_EXIST, "directory not found",
+ commandError(fd, ACK_ERROR_NO_EXIST, "directory not found",
NULL);
return -1;
}
- printDirectoryList(fp, directory->subDirectories);
- printSongInfoFromList(fp, directory->songs);
+ printDirectoryList(fd, directory->subDirectories);
+ printSongInfoFromList(fd, directory->songs);
return 0;
}
@@ -1208,8 +1208,8 @@ int readDirectoryDB()
readDirectoryInfo(fp, mp3rootDirectory);
while (fclose(fp) && errno == EINTR) ;
- stats.numberOfSongs = countSongsIn(stderr, NULL);
- stats.dbPlayTime = sumSongTimesIn(stderr, NULL);
+ stats.numberOfSongs = countSongsIn(STDERR_FILENO, NULL);
+ stats.dbPlayTime = sumSongTimesIn(STDERR_FILENO, NULL);
if (stat(dbFile, &st) == 0)
directory_dbModTime = st.st_mtime;
@@ -1237,10 +1237,10 @@ void updateMp3Directory()
return;
}
-static int traverseAllInSubDirectory(FILE * fp, Directory * directory,
- int (*forEachSong) (FILE *, Song *,
+static int traverseAllInSubDirectory(int fd, Directory * directory,
+ int (*forEachSong) (int, Song *,
void *),
- int (*forEachDir) (FILE *, Directory *,
+ int (*forEachDir) (int, Directory *,
void *), void *data)
{
ListNode *node = directory->songs->firstNode;
@@ -1249,7 +1249,7 @@ static int traverseAllInSubDirectory(FILE * fp, Directory * directory,
int errFlag = 0;
if (forEachDir) {
- errFlag = forEachDir(fp, directory, data);
+ errFlag = forEachDir(fd, directory, data);
if (errFlag)
return errFlag;
}
@@ -1257,7 +1257,7 @@ static int traverseAllInSubDirectory(FILE * fp, Directory * directory,
if (forEachSong) {
while (node != NULL && !errFlag) {
song = (Song *) node->data;
- errFlag = forEachSong(fp, song, data);
+ errFlag = forEachSong(fd, song, data);
node = node->nextNode;
}
if (errFlag)
@@ -1268,7 +1268,7 @@ static int traverseAllInSubDirectory(FILE * fp, Directory * directory,
while (node != NULL && !errFlag) {
dir = (Directory *) node->data;
- errFlag = traverseAllInSubDirectory(fp, dir, forEachSong,
+ errFlag = traverseAllInSubDirectory(fd, dir, forEachSong,
forEachDir, data);
node = node->nextNode;
}
@@ -1276,23 +1276,23 @@ static int traverseAllInSubDirectory(FILE * fp, Directory * directory,
return errFlag;
}
-int traverseAllIn(FILE * fp, char *name,
- int (*forEachSong) (FILE *, Song *, void *),
- int (*forEachDir) (FILE *, Directory *, void *), void *data)
+int traverseAllIn(int fd, char *name,
+ int (*forEachSong) (int, Song *, void *),
+ int (*forEachDir) (int, Directory *, void *), void *data)
{
Directory *directory;
if ((directory = getDirectory(name)) == NULL) {
Song *song;
if ((song = getSongFromDB(name)) && forEachSong) {
- return forEachSong(fp, song, data);
+ return forEachSong(fd, song, data);
}
- commandError(fp, ACK_ERROR_NO_EXIST,
+ commandError(fd, ACK_ERROR_NO_EXIST,
"directory or file not found", NULL);
return -1;
}
- return traverseAllInSubDirectory(fp, directory, forEachSong, forEachDir,
+ return traverseAllInSubDirectory(fd, directory, forEachSong, forEachDir,
data);
}
@@ -1315,8 +1315,8 @@ void initMp3Directory()
mp3rootDirectory = newDirectory(NULL, NULL);
exploreDirectory(mp3rootDirectory);
freeAllDirectoryStats(mp3rootDirectory);
- stats.numberOfSongs = countSongsIn(stderr, NULL);
- stats.dbPlayTime = sumSongTimesIn(stderr, NULL);
+ stats.numberOfSongs = countSongsIn(STDERR_FILENO, NULL);
+ stats.dbPlayTime = sumSongTimesIn(STDERR_FILENO, NULL);
if (stat(getDbFile(), &st) == 0)
directory_dbModTime = st.st_mtime;