ソースを参照

* Write userfile asynchronously

Bryan Drewery 14 年 前
コミット
cd9d34f44b
5 ファイル変更20 行追加2 行削除
  1. 2 0
      doc/UPDATES
  2. 5 0
      src/main.c
  3. 1 1
      src/main.h
  4. 11 1
      src/userrec.c
  5. 1 0
      src/userrec.h

+ 2 - 0
doc/UPDATES

@@ -1,3 +1,5 @@
+* Optimize userfile writing by doing it asynchronously
+
 1.3.3 - http://wraith.botpack.net/milestone/1.3.3
 1.3.3 - http://wraith.botpack.net/milestone/1.3.3
   * Fix --disable-ipv6 compiling
   * Fix --disable-ipv6 compiling
   * Update cmd_mop to support console channel (so it works via Auth commands better)
   * Update cmd_mop to support console channel (so it works via Auth commands better)

+ 5 - 0
src/main.c

@@ -99,6 +99,7 @@ bool     have_linked_to_hub = 0;  /* Have we ever been linked to a hub? */
 int	default_uflags = 0;	/* Default userdefinied flags for people
 int	default_uflags = 0;	/* Default userdefinied flags for people
 				   who say 'hello' or for .adduser */
 				   who say 'hello' or for .adduser */
 int     do_restart = 0;
 int     do_restart = 0;
+int     do_write_userfile = 0;
 bool	backgrd = 1;		/* Run in the background? */
 bool	backgrd = 1;		/* Run in the background? */
 uid_t   myuid;
 uid_t   myuid;
 pid_t   mypid;
 pid_t   mypid;
@@ -520,6 +521,10 @@ static void core_secondly()
     cnt = 0;
     cnt = 0;
   }
   }
 
 
+  if (unlikely(do_write_userfile) && do_write_userfile-- == 1) {
+    real_write_userfile(-1);
+  }
+
   memcpy(&nowtm, gmtime(&now), sizeof(struct tm));
   memcpy(&nowtm, gmtime(&now), sizeof(struct tm));
   if (nowtm.tm_min != lastmin) {
   if (nowtm.tm_min != lastmin) {
     int i = 0;
     int i = 0;

+ 1 - 1
src/main.h

@@ -15,7 +15,7 @@ enum {
 };
 };
 
 
 extern int		role, default_flags, default_uflags, do_confedit,
 extern int		role, default_flags, default_uflags, do_confedit,
-			updating, do_restart;
+			updating, do_restart, do_write_userfile;
 extern bool		use_stderr, backgrd, used_B, term_z, loading, have_linked_to_hub, restart_was_update, restarting, safe_to_log;
 extern bool		use_stderr, backgrd, used_B, term_z, loading, have_linked_to_hub, restart_was_update, restarting, safe_to_log;
 extern char		tempdir[], *binname, owner[121], version[151], ver[101], quit_msg[], *socksfile;
 extern char		tempdir[], *binname, owner[121], version[151], ver[101], quit_msg[], *socksfile;
 extern time_t		online_since, now, restart_time;
 extern time_t		online_since, now, restart_time;

+ 11 - 1
src/userrec.c

@@ -474,7 +474,7 @@ void stream_writeuserfile(bd::Stream& stream, const struct userrec *bu, bool old
 /* Rewrite the entire user file. Call USERFILE hook as well, probably
 /* Rewrite the entire user file. Call USERFILE hook as well, probably
  * causing the channel file to be rewritten as well.
  * causing the channel file to be rewritten as well.
  */
  */
-int write_userfile(int idx)
+int real_write_userfile(int idx)
 {
 {
   if (userlist == NULL || !conf.bot->hub)
   if (userlist == NULL || !conf.bot->hub)
     return 1;			/* No point in saving userfile */
     return 1;			/* No point in saving userfile */
@@ -509,6 +509,16 @@ int write_userfile(int idx)
   return 0;
   return 0;
 }
 }
 
 
+int write_userfile(int idx) {
+  if (idx >= 0) {
+    return real_write_userfile(idx);
+  }
+
+  ++do_write_userfile;
+  return 0;
+}
+
+
 int change_handle(struct userrec *u, char *newh)
 int change_handle(struct userrec *u, char *newh)
 {
 {
   if (!u)
   if (!u)

+ 1 - 0
src/userrec.h

@@ -16,6 +16,7 @@ int deluser(char *);
 int change_handle(struct userrec *, char *);
 int change_handle(struct userrec *, char *);
 void correct_handle(char *);
 void correct_handle(char *);
 void stream_writeuserfile(bd::Stream&, const struct userrec *, bool = 0);
 void stream_writeuserfile(bd::Stream&, const struct userrec *, bool = 0);
+int real_write_userfile(int);
 int write_userfile(int);
 int write_userfile(int);
 void touch_laston(struct userrec *, char *, time_t);
 void touch_laston(struct userrec *, char *, time_t);
 void user_del_chan(char *);
 void user_del_chan(char *);