[Midnightbsd-cvs] src [7379] trunk/libexec/mport.install: allow this to work with dispatch

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Nov 28 22:30:32 EST 2015


Revision: 7379
          http://svnweb.midnightbsd.org/src/?rev=7379
Author:   laffer1
Date:     2015-11-28 22:30:32 -0500 (Sat, 28 Nov 2015)
Log Message:
-----------
allow this to work with dispatch

Modified Paths:
--------------
    trunk/libexec/mport.install/Makefile
    trunk/libexec/mport.install/mport.install.c

Modified: trunk/libexec/mport.install/Makefile
===================================================================
--- trunk/libexec/mport.install/Makefile	2015-11-29 02:59:07 UTC (rev 7378)
+++ trunk/libexec/mport.install/Makefile	2015-11-29 03:30:32 UTC (rev 7379)
@@ -1,11 +1,11 @@
 PROG= mport.install
 
-CFLAGS+=	-I${.CURDIR}/../../lib/libmport/
+CFLAGS+=	-I${.CURDIR}/../../lib/libmport/ -fblocks
 WARNS?= 	6
 
 NO_MAN=		yes
 
-LDADD= 	-lmport
-DPADD= 	${LIBMPORT} 
+LDADD= 	-lmport -ldispatch -lBlocksRuntime
+DPADD= 	${LIBMPORT}  ${LIBBLOCKSRUNTIME} ${LIBDISPATCH}
 
 .include <bsd.prog.mk>

Modified: trunk/libexec/mport.install/mport.install.c
===================================================================
--- trunk/libexec/mport.install/mport.install.c	2015-11-29 02:59:07 UTC (rev 7378)
+++ trunk/libexec/mport.install/mport.install.c	2015-11-29 03:30:32 UTC (rev 7379)
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD: src/libexec/mport.install/mport.install.c,v 1.9 2012/04/11 00:46:55 laffer1 Exp $");
+__MBSDID("$MidnightBSD$");
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -39,9 +39,14 @@
 int
 main(int argc, char *argv[]) 
 {
-	int ch, i;
+	int ch;
 	char *prefix = NULL;
 	mportInstance *mport;
+	__block int error_code = 0;
+
+	dispatch_queue_t mainq = dispatch_get_main_queue();
+        dispatch_group_t grp = dispatch_group_create();
+        dispatch_queue_t q = dispatch_queue_create("print", NULL);
 		
 	while ((ch = getopt(argc, argv, "p:")) != -1) {
 		switch (ch) {
@@ -61,6 +66,8 @@
 	if (argc == 0)
 		usage();
 
+	mport_init_queues();
+
 	mport = mport_instance_new();
 
 	if (mport_instance_init(mport, NULL) != MPORT_OK) {
@@ -67,18 +74,24 @@
 		warnx("Init failed: %s", mport_err_string());
 		return 1;
 	}
-	
-	for (i = 0; i < argc; i++) {
-		if (mport_install_primative(mport, argv[i], prefix) != MPORT_OK) {
-			warnx("install failed: %s", mport_err_string());
-			mport_instance_free(mport);
-			return 1;
-		}
+
+	for (int i = 0; i < argc; i++) {
+		dispatch_group_async(grp, q, ^{
+			if (mport_install_primative(mport, argv[i], prefix) != MPORT_OK) {
+				warnx("install failed: %s", mport_err_string());
+				mport_instance_free(mport);
+				exit(1);
+			}
+		});
 	}
  
-	mport_instance_free(mport); 
-	
-	return 0;
+	dispatch_group_wait(grp, DISPATCH_TIME_FOREVER);
+        dispatch_async(mainq, ^{
+                mport_instance_free(mport);
+                exit(error_code);
+        });
+
+        dispatch_main();
 }
 
 static 



More information about the Midnightbsd-cvs mailing list