[mw-devel] MW3 r1078 - trunk/src

arthur at sucs.org arthur at sucs.org
Mon Mar 16 18:30:53 GMT 2009


Author: arthur
Date: 2009-03-16 18:30:52 +0000 (Mon, 16 Mar 2009)
New Revision: 1078

Modified:
   trunk/src/log.c
   trunk/src/sqlite.c
Log:
do our own busy retry, and remove duplicate code


Modified: trunk/src/log.c
===================================================================
--- trunk/src/log.c	2009-03-16 17:58:32 UTC (rev 1077)
+++ trunk/src/log.c	2009-03-16 18:30:52 UTC (rev 1078)
@@ -147,19 +147,7 @@
 					return;
 				}
 				if (u->type == TAG) {
-					if (nfoundtag < 20) foundurl[nfoundtag++] = token;
-
-					struct taghit *tag;
-					pthread_attr_t ptattr;
-
-					pthread_attr_init(&ptattr);
-					pthread_attr_setdetachstate(&ptattr, PTHREAD_CREATE_DETACHED);
-					pthread_t pt;
-					tag = malloc(sizeof(struct taghit));
-					tag->tag = strdup(token);
-					tag->line = strdup(what);
-					pthread_create(&pt, &ptattr, file_tag, tag);
-					pthread_attr_destroy(&ptattr);
+					if (nfoundtag < 20) foundtag[nfoundtag++] = token;
 				}
 			}
 			u++;

Modified: trunk/src/sqlite.c
===================================================================
--- trunk/src/sqlite.c	2009-03-16 17:58:32 UTC (rev 1077)
+++ trunk/src/sqlite.c	2009-03-16 18:30:52 UTC (rev 1078)
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <unistd.h>
 #include <fcntl.h>
 #include <string.h>
 #include <stdlib.h>
@@ -73,6 +74,7 @@
 	int ret;
 	char *error = NULL;
 	sqlite3 *db;
+	int retries = 5;
 
 	if (dbname == NULL) return 0;
 
@@ -87,10 +89,26 @@
 	new->colNames = NULL;
 	new->data = NULL;
 
-	ret = sqlite3_exec(db, query, db_callback, new, &error);
+	do {
+		ret = sqlite3_exec(db, query, db_callback, new, &error);
+		if (ret == SQLITE_BUSY) {
+			usleep(50000);
+			retries--;
+		}
+	} while (ret == SQLITE_BUSY && retries > 0);
 
 	if (ret != SQLITE_OK) {
-		if (!quiet) printf("Error %s (%d) on query %s\n", error, ret, query);
+		if (!quiet) {
+			switch (ret) {
+				case SQLITE_BUSY: printf("BUSY "); break;
+				case SQLITE_DONE: printf("DONE "); break;
+				case SQLITE_ERROR: printf("ERROR "); break;
+				case SQLITE_MISUSE: printf("MISUSE "); break;
+				case SQLITE_ROW: printf("ROW "); break;
+			}
+
+			printf("Error %s (%d) on query %s\n", error, ret, query);
+		}
 		sqlite3_free(error);
 		db_close(db);
 		return NULL;





More information about the mw-devel mailing list