pkgsrc/cad/electric/patches/patch-ac
2009-08-01 16:22:25 +00:00

67 lines
1.5 KiB
Text

$NetBSD: patch-ac,v 1.3 2009/08/01 16:22:26 dholland Exp $
Get number of processors for NetBSD/Dragonfly.
Hack around silly behavior that unlocks every newly created pthread mutex.
--- src/graph/graphunixx11.c.orig 2004-07-15 21:59:53.000000000 -0400
+++ src/graph/graphunixx11.c 2009-08-01 12:17:39.000000000 -0400
@@ -3085,11 +3085,30 @@ void ewait(INTBIG process)
/*
* Routine to return the number of processors on this machine.
*/
+
+/* XXX there should really be some sort of autoconf test here... */
+#if defined(__NetBSD__) || defined(__DragonFly__)
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
+
INTBIG enumprocessors(void)
{
INTBIG numproc;
+#if defined(__NetBSD__) || defined(__DragonFly__)
+ int mib[2], ncpu;
+ size_t len;
+
+ mib[0] = CTL_HW;
+ mib[1] = HW_NCPU;
+ len = sizeof(ncpu);
+ sysctl(mib, 2, &ncpu, &len, NULL, 0);
+ numproc = (INTBIG) ncpu;
+
+#else
numproc = sysconf(_SC_NPROCESSORS_ONLN);
+#endif
return(numproc);
}
@@ -3168,6 +3187,27 @@ void emutexunlock(void *vmutex)
}
/*
+ * Routine that ensures mutual-exclusion object "vmutex" is unlocked.
+ */
+void emutexensureunlocked(void *vmutex)
+{
+#ifdef HAVE_PTHREAD
+ pthread_mutex_t *mutex;
+
+ mutex = (pthread_mutex_t *)vmutex;
+ if (pthread_mutex_trylock(mutex) == 0)
+ {
+ pthread_mutex_unlock(mutex);
+ }
+#else
+ mutex_t *mutexid;
+
+ mutexid = (mutex_t *)vmutex;
+ mutex_unlock(mutexid);
+#endif
+}
+
+/*
* Routine to determine the list of printers and return it.
* The list terminates with a zero.
*/