[Midnightbsd-cvs] src [7367] trunk/lib/libmport: add some libdispatch love

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Nov 28 18:08:51 EST 2015


Revision: 7367
          http://svnweb.midnightbsd.org/src/?rev=7367
Author:   laffer1
Date:     2015-11-28 18:08:50 -0500 (Sat, 28 Nov 2015)
Log Message:
-----------
add some libdispatch love

Modified Paths:
--------------
    trunk/lib/libmport/Makefile
    trunk/lib/libmport/clean.c
    trunk/lib/libmport/db.c
    trunk/lib/libmport/default_cbs.c
    trunk/lib/libmport/instance.c
    trunk/lib/libmport/mport.h
    trunk/lib/libmport/mport_private.h
    trunk/lib/libmport/stats.c

Added Paths:
-----------
    trunk/lib/libmport/dispatch.c
    trunk/lib/libmport/mport_dispatch.h

Modified: trunk/lib/libmport/Makefile
===================================================================
--- trunk/lib/libmport/Makefile	2015-11-28 22:21:08 UTC (rev 7366)
+++ trunk/lib/libmport/Makefile	2015-11-28 23:08:50 UTC (rev 7367)
@@ -2,7 +2,7 @@
 
 LIB=		mport
 SRCS=		bundle_write.c bundle_read.c plist.c create_primative.c db.c \
-		util.c error.c install_primative.c instance.c \
+		dispatch.c util.c error.c install_primative.c instance.c \
 		version_cmp.c check_preconditions.c delete_primative.c \
 		default_cbs.c  merge_primative.c bundle_read_install_pkg.c \
 		update_primative.c bundle_read_update_pkg.c pkgmeta.c \

Modified: trunk/lib/libmport/clean.c
===================================================================
--- trunk/lib/libmport/clean.c	2015-11-28 22:21:08 UTC (rev 7366)
+++ trunk/lib/libmport/clean.c	2015-11-28 23:08:50 UTC (rev 7367)
@@ -39,43 +39,54 @@
 
 MPORT_PUBLIC_API int 
 mport_clean_database(mportInstance *mport) {
-	if (mport_db_do(mport->db, "vacuum") != MPORT_OK)
-		RETURN_CURRENT_ERROR;
-	return MPORT_OK;
+    __block int error_code = MPORT_OK;
+
+    dispatch_sync(mportTaskSerial, ^(int){
+        if (mport_db_do(mport->db, "vacuum") != MPORT_OK)
+            error_code = mport_err_code();
+        error_code = MPORT_OK;
+    });
+
+    return error_code;
 }
 
 MPORT_PUBLIC_API int
 mport_clean_oldpackages(mportInstance *mport) {
-	mportIndexEntry **indexEntry;
-	struct dirent *de;
-	DIR *d;
-	char *path;
+    __block int error_code = MPORT_OK;
 
-	d = opendir(MPORT_FETCH_STAGING_DIR);
-	if (d == NULL)
-		RETURN_ERRORX(MPORT_ERR_FATAL, "Couldn't open directory %s: %s", MPORT_FETCH_STAGING_DIR, strerror(errno));
+    dispatch_sync(mportTaskSerial, ^{
+        struct dirent *de;
+        DIR *d = opendir(MPORT_FETCH_STAGING_DIR);
 
-	while ((de = readdir(d)) != NULL) {
-		if (strcmp(".", de->d_name) == 0 || strcmp("..", de->d_name) == 0)
-			continue;
-		if (mport_index_search(mport, &indexEntry, "bundlefile=%Q", de->d_name) != MPORT_OK)
-			RETURN_CURRENT_ERROR;
+        if (d == NULL)
+            RETURN_ERRORX(MPORT_ERR_FATAL, "Couldn't open directory %s: %s", MPORT_FETCH_STAGING_DIR, strerror(errno));
 
-		if (indexEntry == NULL || *indexEntry == NULL) {
-			asprintf(&path, "%s/%s", MPORT_FETCH_STAGING_DIR, de->d_name);
-			if (path != NULL)
-				if (unlink(path) < 0) {
-					closedir(d);
-					RETURN_ERRORX(MPORT_ERR_FATAL, "Could not delete file %s: %s", path, strerror(errno));
-				}
-			free(path);
-		} else {
-			 mport_index_entry_free_vec(indexEntry);
-		}
-	}
+        while ((de = readdir(d)) != NULL) {
+                mportIndexEntry **indexEntry;
+                char *path;
+                if (strcmp(".", de->d_name) == 0 || strcmp("..", de->d_name) == 0)
+                    continue;
 
-	closedir(d);
+                if (mport_index_search(mport, &indexEntry, "bundlefile=%Q", de->d_name) != MPORT_OK) {
+                    error_code = mport_err_code();
+                }
 
-	return MPORT_OK;
+                if (indexEntry == NULL || *indexEntry == NULL) {
+                    asprintf(&path, "%s/%s", MPORT_FETCH_STAGING_DIR, de->d_name);
+                    if (path != NULL) if (unlink(path) < 0) {
+                        error_code = SET_ERRORX(MPORT_ERR_FATAL, "Could not delete file %s: %s", path, strerror(errno));
+                    }
+                    free(path);
+                } else {
+                    mport_index_entry_free_vec(indexEntry);
+                }
+
+            }
+
+            closedir(d);
+
+        });
+
+    return error_code;
 }
 

Modified: trunk/lib/libmport/db.c
===================================================================
--- trunk/lib/libmport/db.c	2015-11-28 22:21:08 UTC (rev 7366)
+++ trunk/lib/libmport/db.c	2015-11-28 23:08:50 UTC (rev 7367)
@@ -41,41 +41,50 @@
 
 /* mport_db_do(sqlite3 *db, const char *sql, ...)
  * 
- * A wrapper for doing executing a single sql query.  Takes a sqlite3 struct
+ * A wrapper for executing a single sql query.  Takes a sqlite3 struct
  * pointer, a format string and a list of args.  See the documentation for 
  * sqlite3_vmprintf() for format information.
  */
-int mport_db_do(sqlite3 *db, const char *fmt, ...) 
-{
-  va_list args;
-  char *sql;
-  int sqlcode;
-  
-  va_start(args, fmt);
-  
-  sql = sqlite3_vmprintf(fmt, args);
-  
-  va_end(args);
-  
-  if (sql == NULL)
-    RETURN_ERROR(MPORT_ERR_FATAL, "Couldn't allocate memory for sql statement");
-  
-  sqlcode = sqlite3_exec(db, sql, 0, 0, 0);
-  /* if we get an error code, we want to run it again in some cases */
-  if (sqlcode == SQLITE_BUSY || sqlcode == SQLITE_LOCKED) {
-    sleep(1);
-    if (sqlite3_exec(db, sql, 0, 0, 0) != SQLITE_OK) {
-      sqlite3_free(sql);
-      RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
+int
+mport_db_do(sqlite3 *db, const char *fmt, ...) {
+    va_list args;
+    char *sql;
+    int sqlcode;
+    int result = MPORT_OK;
+    char *err;
+
+    va_start(args, fmt);
+
+    sql = sqlite3_vmprintf(fmt, args);
+
+    va_end(args);
+
+    if (sql == NULL)
+        RETURN_ERROR(MPORT_ERR_FATAL, "Couldn't allocate memory for sql statement");
+
+    dispatch_sync(mportSQLSerial, ^{
+        sqlcode = sqlite3_exec(db, sql, 0, 0, 0);
+        /* if we get an error code, we want to run it again in some cases */
+        if (sqlcode == SQLITE_BUSY || sqlcode == SQLITE_LOCKED) {
+            sleep(1);
+            if (sqlite3_exec(db, sql, 0, 0, 0) != SQLITE_OK) {
+                sqlite3_free(sql);
+                err = sqlite3_errmsg(db);
+                result = MPORT_ERR_FATAL;
+            }
+        } else if (sqlcode != SQLITE_OK) {
+            sqlite3_free(sql);
+            err = sqlite3_errmsg(db);
+            result = MPORT_ERR_FATAL;
+        }
+
+        sqlite3_free(sql);
+    });
+
+    if (result == MPORT_ERR_FATAL) {
+        RETURN_ERROR(MPORT_ERR_FATAL, err);
     }
-  } else if (sqlcode != SQLITE_OK) {
-    sqlite3_free(sql);
-    RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
-  }
-  
-  sqlite3_free(sql);
-  
-  return MPORT_OK;
+    return result;
 }
 
 
@@ -86,7 +95,8 @@
  * This function returns MPORT_OK on success.  The sqlite3_stmt pointer 
  * may be null if this function does not return MPORT_OK.
  */
-int mport_db_prepare(sqlite3 *db, sqlite3_stmt **stmt, const char * fmt, ...)
+int
+mport_db_prepare(sqlite3 *db, sqlite3_stmt **stmt, const char * fmt, ...)
 {
   va_list args;
   char *sql;

Modified: trunk/lib/libmport/default_cbs.c
===================================================================
--- trunk/lib/libmport/default_cbs.c	2015-11-28 22:21:08 UTC (rev 7366)
+++ trunk/lib/libmport/default_cbs.c	2015-11-28 23:08:50 UTC (rev 7367)
@@ -31,6 +31,7 @@
 #include <termios.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/ioctl.h>
 #include "mport.h"
 #include "mport_private.h"
 

Added: trunk/lib/libmport/dispatch.c
===================================================================
--- trunk/lib/libmport/dispatch.c	                        (rev 0)
+++ trunk/lib/libmport/dispatch.c	2015-11-28 23:08:50 UTC (rev 7367)
@@ -0,0 +1,41 @@
+/*-
+ * Copyright (c) 2015 Lucas Holt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__MBSDID("$MidnightBSD$");
+
+#include "mport_dispatch.h"
+#include "mport_private.h"
+
+void
+mport_init_queues(void)
+{
+
+    mportArchiveSerial = dispatch_queue_create("org.midnightbsd.mport.archive", NULL);
+    mportPrintSerial = dispatch_queue_create("org.midnightbsd.mport.print", NULL);
+    mportSQLSerial = dispatch_queue_create("org.midnightbsd.mport.sql", NULL);
+    mportTaskSerial= dispatch_queue_create("org.midnightbsd.mport.task", NULL);
+}
\ No newline at end of file

Modified: trunk/lib/libmport/instance.c
===================================================================
--- trunk/lib/libmport/instance.c	2015-11-28 22:21:08 UTC (rev 7366)
+++ trunk/lib/libmport/instance.c	2015-11-28 23:08:50 UTC (rev 7367)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2013 Lucas Holt
+ * Copyright (c) 2013, 2015 Lucas Holt
  * Copyright (c) 2007-2009 Chris Reinhardt
  * All rights reserved.
  *
@@ -26,6 +26,7 @@
  */
 
 #include <sys/cdefs.h>
+
 __MBSDID("$MidnightBSD$");
 
 #include <sys/types.h>
@@ -37,171 +38,186 @@
 #include "mport.h"
 #include "mport_private.h"
 
-/* allocate mem for a mportInstance */
+/**
+ * allocate memory for a mportInstance
+ */
 MPORT_PUBLIC_API mportInstance *
-mport_instance_new(void)
-{
-  return (mportInstance *)calloc(1, sizeof(mportInstance)); 
+mport_instance_new(void) {
+
+    return (mportInstance *) calloc(1, sizeof(mportInstance));
 }
- 
 
-/* set up the master database, and related instance infrastructure. */
-MPORT_PUBLIC_API int mport_instance_init(mportInstance *mport, const char *root)
-{
-  char dir[FILENAME_MAX];
 
-  mport->flags = 0;
-  
-  if (root != NULL) {
-    mport->root = strdup(root);
-  } else {
-    mport->root = strdup("");
-  }
+/**
+ * Set up the master database, and related instance infrastructure.
+ */
+MPORT_PUBLIC_API int
+mport_instance_init(mportInstance *mport, const char *root) {
+    char dir[FILENAME_MAX];
 
-  (void)snprintf(dir, FILENAME_MAX, "%s/%s", mport->root, MPORT_INST_DIR);
+    dispatch_once(&mportInitializeOnce, ^{
+        mport->flags = 0;
 
-  if (mport_mkdir(dir) != MPORT_OK)
-    RETURN_CURRENT_ERROR;
-  
-  (void)snprintf(dir, FILENAME_MAX, "%s/%s", mport->root, MPORT_INST_INFRA_DIR);
-  
-  if (mport_mkdir(dir) != MPORT_OK)
-    RETURN_CURRENT_ERROR;
+        if (root != NULL) {
+            mport->root = strdup(root);
+        } else {
+            mport->root = strdup("");
+        }
 
-  /* dir is a file here, just trying to save memory */
-  (void)snprintf(dir, FILENAME_MAX, "%s/%s", mport->root, MPORT_MASTER_DB_FILE);
-  if (sqlite3_open(dir, &(mport->db)) != 0) {
-    sqlite3_close(mport->db);
-    RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(mport->db));
-  }
-  
-  
-  if (sqlite3_create_function(mport->db, "mport_version_cmp", 2, SQLITE_ANY, NULL, &mport_version_cmp_sqlite, NULL, NULL) != SQLITE_OK) {
-    sqlite3_close(mport->db);
-    RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(mport->db));
-  }
-  
-  /* set the default UI callbacks */
-  mport->msg_cb           = &mport_default_msg_cb;
-  mport->progress_init_cb = &mport_default_progress_init_cb;
-  mport->progress_step_cb = &mport_default_progress_step_cb;
-  mport->progress_free_cb = &mport_default_progress_free_cb;
-  mport->confirm_cb       = &mport_default_confirm_cb;
-  
- 
-  mport_upgrade_master_schema(mport->db, mport_get_database_version(mport->db));
+        mport_init_queues();
 
-  /* create tables */
-  return mport_generate_master_schema(mport->db);
+        (void) snprintf(dir, FILENAME_MAX, "%s/%s", mport->root, MPORT_INST_DIR);
+
+        if (mport_mkdir(dir) != MPORT_OK)
+            RETURN_CURRENT_ERROR;
+
+        (void) snprintf(dir, FILENAME_MAX, "%s/%s", mport->root, MPORT_INST_INFRA_DIR);
+
+        if (mport_mkdir(dir) != MPORT_OK)
+            RETURN_CURRENT_ERROR;
+
+        /* dir is a file here, just trying to save memory */
+        (void) snprintf(dir, FILENAME_MAX, "%s/%s", mport->root, MPORT_MASTER_DB_FILE);
+        if (sqlite3_open(dir, &(mport->db)) != 0) {
+            sqlite3_close(mport->db);
+            RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(mport->db));
+        }
+
+        if (sqlite3_create_function(mport->db, "mport_version_cmp", 2, SQLITE_ANY, NULL, &mport_version_cmp_sqlite,
+                                    NULL,
+                                    NULL) != SQLITE_OK) {
+            sqlite3_close(mport->db);
+            RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(mport->db));
+        }
+
+        /* set the default UI callbacks */
+        mport->msg_cb = &mport_default_msg_cb;
+        mport->progress_init_cb = &mport_default_progress_init_cb;
+        mport->progress_step_cb = &mport_default_progress_step_cb;
+        mport->progress_free_cb = &mport_default_progress_free_cb;
+        mport->confirm_cb = &mport_default_confirm_cb;
+
+        mport_upgrade_master_schema(mport->db, mport_get_database_version(mport->db));
+    });
+
+    /* create tables */
+    return mport_generate_master_schema(mport->db);
 }
 
-int 
+/**
+ * Get the mport database schema version.
+ */
+int
 mport_get_database_version(sqlite3 *db) {
-	sqlite3_stmt *stmt_version;
-	int databaseVersion = 0;
-	
-	if (sqlite3_prepare_v2(db, "PRAGMA user_version;", -1, &stmt_version, NULL) == SQLITE_OK) {
-		while (sqlite3_step(stmt_version) == SQLITE_ROW) {
-			databaseVersion = sqlite3_column_int(stmt_version, 0);
-		}
-	} else {
-		return -1; /* ERROR condition */
-	}
-	sqlite3_finalize(stmt_version);
+    sqlite3_stmt *stmt_version;
+    int databaseVersion = -1; /* ERROR condition */
 
-	return databaseVersion;
+    dispatch_sync(mportSQLSerial, ^{
+        if (sqlite3_prepare_v2(db, "PRAGMA user_version;", -1, &stmt_version, NULL) == SQLITE_OK) {
+            while (sqlite3_step(stmt_version) == SQLITE_ROW) {
+                databaseVersion = sqlite3_column_int(stmt_version, 0);
+            }
+        }
+        sqlite3_finalize(stmt_version);
+    });
+
+    return databaseVersion;
 }
 
+/**
+ * Set the mport database schema version for when we upgrade mport
+ */
 int
 mport_set_database_version(sqlite3 *db) {
-	char *sql;
+    char *sql;
 
-	asprintf(&sql, "PRAGMA user_version=%d", MPORT_MASTER_VERSION);
+    asprintf(&sql, "PRAGMA user_version=%d", MPORT_MASTER_VERSION);
 
-	if (mport_db_do(db, sql) != MPORT_OK) {
-		free(sql);
-		RETURN_CURRENT_ERROR;
-	}
+    if (mport_db_do(db, sql) != MPORT_OK) {
+        free(sql);
+        RETURN_CURRENT_ERROR;
+    }
 
-	free(sql);
+    free(sql);
 
-	return (MPORT_OK);
+    return (MPORT_OK);
 }
 
 /* Setters for the variable UI callbacks. */
-MPORT_PUBLIC_API void mport_set_msg_cb(mportInstance *mport, mport_msg_cb cb) 
-{
-  mport->msg_cb = cb;
+MPORT_PUBLIC_API void
+mport_set_msg_cb(mportInstance *mport, mport_msg_cb cb) {
+    mport->msg_cb = cb;
 }
 
-MPORT_PUBLIC_API void mport_set_progress_init_cb(mportInstance *mport, mport_progress_init_cb cb)
-{
-  mport->progress_init_cb = cb;
+MPORT_PUBLIC_API void
+mport_set_progress_init_cb(mportInstance *mport, mport_progress_init_cb cb) {
+    mport->progress_init_cb = cb;
 }
 
-MPORT_PUBLIC_API void mport_set_progress_step_cb(mportInstance *mport, mport_progress_step_cb cb)
-{
-  mport->progress_step_cb = cb;
+MPORT_PUBLIC_API void
+mport_set_progress_step_cb(mportInstance *mport, mport_progress_step_cb cb) {
+    mport->progress_step_cb = cb;
 }
 
-MPORT_PUBLIC_API void mport_set_progress_free_cb(mportInstance *mport, mport_progress_free_cb cb)
-{
-  mport->progress_free_cb = cb;
+MPORT_PUBLIC_API void
+mport_set_progress_free_cb(mportInstance *mport, mport_progress_free_cb cb) {
+    mport->progress_free_cb = cb;
 }
 
 
-MPORT_PUBLIC_API void mport_set_confirm_cb(mportInstance *mport, mport_confirm_cb cb) 
-{
-  mport->confirm_cb = cb;
+MPORT_PUBLIC_API void
+mport_set_confirm_cb(mportInstance *mport, mport_confirm_cb cb) {
+    mport->confirm_cb = cb;
 }
 
 
 /* callers for the callbacks (only for msg at the moment) */
-void mport_call_msg_cb(mportInstance *mport, const char *fmt, ...)
-{
-  va_list args;
-  char *msg;
-  
-  va_start(args, fmt);
-  (void)vasprintf(&msg, fmt, args);
-  va_end(args);
-  
-  if (msg == NULL) 
-    return; /* No message for you! */
+void
+mport_call_msg_cb(mportInstance *mport, const char *fmt, ...) {
+    va_list args;
 
-  (mport->msg_cb)(msg);
-  
-  free(msg);
+    char *msg;
+    va_start(args, fmt);
+    (void) vasprintf(&msg, fmt, args);
+    va_end(args);
+
+    if (msg == NULL)
+        return; /* No message for you! */
+
+    dispatch_async(mportPrintSerial, ^{
+        (mport->msg_cb)(msg);
+
+        free(msg);
+    });
 }
 
 
-void mport_call_progress_init_cb(mportInstance *mport, const char *fmt, ...)
-{
-  va_list args;
-  char *title;
-  
-  va_start(args, fmt);
-  (void)vasprintf(&title, fmt, args);
-  
-  if (title == NULL)
-    return;
-    
-  (mport->progress_init_cb)(title);
-  
-  free(title);
+void
+mport_call_progress_init_cb(mportInstance *mport, const char *fmt, ...) {
+    va_list args;
+    char *title;
+
+    va_start(args, fmt);
+    (void) vasprintf(&title, fmt, args);
+
+    if (title == NULL)
+        return;
+
+    dispatch_async(mportPrintSerial, ^{
+        (mport->progress_init_cb)(title);
+
+        free(title);
+    });
 }
 
 
-  
+MPORT_PUBLIC_API int
+mport_instance_free(mportInstance *mport) {
+    if (sqlite3_close(mport->db) != SQLITE_OK) {
+        RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(mport->db));
+    }
 
-MPORT_PUBLIC_API int mport_instance_free(mportInstance *mport) 
-{
-  if (sqlite3_close(mport->db) != SQLITE_OK) {
-    RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(mport->db));
-  }
-  
-  free(mport->root);
-  free(mport);
-  return MPORT_OK;
+    free(mport->root);
+    free(mport);
+    return MPORT_OK;
 }
-

Modified: trunk/lib/libmport/mport.h
===================================================================
--- trunk/lib/libmport/mport.h	2015-11-28 22:21:08 UTC (rev 7366)
+++ trunk/lib/libmport/mport.h	2015-11-28 23:08:50 UTC (rev 7367)
@@ -36,8 +36,9 @@
 #include <sqlite3.h>
 #include <sys/queue.h>
 #include <stdio.h>
-#include <dispatch/dispatch.h>
 
+#include "mport_dispatch.h"
+
 typedef void (*mport_msg_cb)(const char *);
 typedef void (*mport_progress_init_cb)(const char *);
 typedef void (*mport_progress_step_cb)(int, int, const char *);

Added: trunk/lib/libmport/mport_dispatch.h
===================================================================
--- trunk/lib/libmport/mport_dispatch.h	                        (rev 0)
+++ trunk/lib/libmport/mport_dispatch.h	2015-11-28 23:08:50 UTC (rev 7367)
@@ -0,0 +1,61 @@
+/* $MidnightBSD$
+ *
+ * Copyright (c) 2015 Lucas Holt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#ifndef _MPORT_DISPATCH_H_
+#define _MPORT_DISPATCH_H_
+
+#include <dispatch/dispatch.h>
+
+typedef void (^completion_block_t)(int error_code);
+
+/**
+ * package task queue
+ */
+static dispatch_queue_t mportTaskSerial = NULL;
+
+/**
+ * libarchive operations queue
+ */
+static dispatch_queue_t mportArchiveSerial = NULL;
+
+/**
+ * print callbacks queue
+ */
+static dispatch_queue_t mportPrintSerial = NULL;
+
+/**
+ * sqlite operations queue
+ */
+static dispatch_queue_t mportSQLSerial = NULL;
+
+static dispatch_once_t mportInitializeOnce;
+
+
+void mport_init_queues();
+
+#endif
\ No newline at end of file

Modified: trunk/lib/libmport/mport_private.h
===================================================================
--- trunk/lib/libmport/mport_private.h	2015-11-28 22:21:08 UTC (rev 7366)
+++ trunk/lib/libmport/mport_private.h	2015-11-28 23:08:50 UTC (rev 7367)
@@ -174,12 +174,8 @@
 #define MPORT_OSVERSION "0.8"
 #elif __MidnightBSD_version >= 7000
 #define MPORT_OSVERSION "0.7"
-#elif __MidnightBSD_version >= 6000
-#define MPORT_OSVERSION "0.6"
-#elif __MidnightBSD_version >= 5000
-#define MPORT_OSVERSION "0.5"
 #else
-#error "libmport only supports MidnightBSD versions 0.5 and greater."
+#error "libmport only supports MidnightBSD versions 0.7 and greater."
 #endif
 
 

Modified: trunk/lib/libmport/stats.c
===================================================================
--- trunk/lib/libmport/stats.c	2015-11-28 22:21:08 UTC (rev 7366)
+++ trunk/lib/libmport/stats.c	2015-11-28 23:08:50 UTC (rev 7367)
@@ -44,7 +44,7 @@
         RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
     }
 
-    s->pkg_installed = sqlite3_column_int(stmt, 0);
+    s->pkg_installed = (unsigned int) sqlite3_column_int(stmt, 0);
     sqlite3_finalize(stmt);
 
     if (mport_db_prepare(db, &stmt, "SELECT COUNT(*) FROM idx.packages") != MPORT_OK)
@@ -55,7 +55,7 @@
         RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
     }
 
-    s->pkg_available = sqlite3_column_int(stmt, 0);
+    s->pkg_available = (unsigned int) sqlite3_column_int(stmt, 0);
     sqlite3_finalize(stmt);
 
     return (MPORT_OK);



More information about the Midnightbsd-cvs mailing list