summaryrefslogtreecommitdiff
path: root/src/char
diff options
context:
space:
mode:
authorMadCamel <madcamel@gmail.com>2009-07-24 06:14:45 -0400
committerMadCamel <madcamel@gmail.com>2009-07-24 06:18:28 -0400
commit2e10b429a9bad28a4c7999d3a0f5184e48ab1f93 (patch)
tree9f3f71bddf100ae115c9852e47bd939f1e5543dd /src/char
parenta626960e74117bad7b906fa51b3b311b1f4972a0 (diff)
downloadtmwa-2e10b429a9bad28a4c7999d3a0f5184e48ab1f93.tar.gz
tmwa-2e10b429a9bad28a4c7999d3a0f5184e48ab1f93.tar.bz2
tmwa-2e10b429a9bad28a4c7999d3a0f5184e48ab1f93.tar.xz
tmwa-2e10b429a9bad28a4c7999d3a0f5184e48ab1f93.zip
char-server now offloads file writes to a child process
Should see a massive speedup as it's now free to do other things. If processes start piling up, decrease the save frequency.
Diffstat (limited to 'src/char')
-rw-r--r--src/char/char.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 37580b6..08ad642 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -720,8 +720,20 @@ void mmo_char_sync(void) {
// Function to save (in a periodic way) datas in files
//----------------------------------------------------
int mmo_char_sync_timer(int tid, unsigned int tick, int id, int data) {
+ pid_t pid;
+
+ // This can take a lot of time. Fork a child to handle the work and return at once
+ // If we're unable to fork just continue running the function normally
+ if ((pid = fork()) > 0)
+ return 0;
+
mmo_char_sync();
inter_save();
+
+ // If we're a child we should suicide now.
+ if (pid == 0)
+ exit(0);
+
return 0;
}