Revision: 73078
http://sourceforge.net/p/brlcad/code/73078
Author: brlcad
Date: 2019-05-17 04:36:33 +0000 (Fri, 17 May 2019)
Log Message:
-----------
Restore the new semaphore registration system, this time utilizing a
different initialization method that should work universally including
Windows. Now relies on C++ static object initialization and one tiny
feature from C++11 to make semaphore registration parallel threadsafe.
This version now also cleans up the semaphore allocations when done
too via destructor. All tests pass on Windows and Linux. Code could
use a little cleanup, but looking well on the whole hilarity.
Modified Paths:
--------------
brlcad/trunk/include/analyze.h
brlcad/trunk/include/bu/parallel.h
brlcad/trunk/include/common.h
brlcad/trunk/include/photonmap.h
brlcad/trunk/include/rt/defines.h
brlcad/trunk/include/rt/resource.h
brlcad/trunk/src/adrt/librender/camera.c
brlcad/trunk/src/adrt/librender/camera.h
brlcad/trunk/src/burst/paint.c
brlcad/trunk/src/gtools/beset/fitness.c
brlcad/trunk/src/gtools/beset/fitness.h
brlcad/trunk/src/libanalyze/analyze_private.h
brlcad/trunk/src/libanalyze/api.c
brlcad/trunk/src/libbn/noise.c
brlcad/trunk/src/libbrep/PullbackCurve.cpp
brlcad/trunk/src/libbu/CMakeLists.txt
brlcad/trunk/src/libbu/datetime.c
brlcad/trunk/src/libbu/getcwd.c
brlcad/trunk/src/libbu/hash.c
brlcad/trunk/src/libbu/init.c
brlcad/trunk/src/libbu/list.c
brlcad/trunk/src/libbu/malloc.c
brlcad/trunk/src/libbu/parallel.c
brlcad/trunk/src/libbu/semaphore.c
brlcad/trunk/src/libbu/thread.cpp
brlcad/trunk/src/libged/check/check_adj_air.c
brlcad/trunk/src/libged/check/check_exp_air.c
brlcad/trunk/src/libged/check/check_gap.c
brlcad/trunk/src/libged/check/check_overlaps.c
brlcad/trunk/src/libged/check/check_unconf_air.c
brlcad/trunk/src/libged/gqa.c
brlcad/trunk/src/liboptical/photonmap.c
brlcad/trunk/src/librt/cache.c
brlcad/trunk/src/librt/db_open.c
brlcad/trunk/src/librt/prep.c
brlcad/trunk/src/librt/primitives/brep/brep.cpp
brlcad/trunk/src/librt/tree.c
brlcad/trunk/src/proc-db/pix2g.c
brlcad/trunk/src/rt/worker.c
Added Paths:
-----------
brlcad/trunk/src/libbu/bu_init.cpp
brlcad/trunk/src/libbu/semaphore_register.cpp
Modified: brlcad/trunk/include/analyze.h
===================================================================
--- brlcad/trunk/include/analyze.h 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/include/analyze.h 2019-05-17 04:36:33 UTC (rev 73078)
@@ -50,11 +50,8 @@
/* Libanalyze return codes */
#define ANALYZE_OK 0x0000
#define ANALYZE_ERROR 0x0001 /**< something went wrong, function not completed
*/
-#define ANALYZE_SEM_WORKER RT_SEM_LAST
-#define ANALYZE_SEM_STATS ANALYZE_SEM_WORKER+1
-#define ANALYZE_SEM_LIST ANALYZE_SEM_STATS+1
-#define ANALYZE_SEM_LAST ANALYZE_SEM_LIST+1
+
/*
* Density specific structures
*/
Modified: brlcad/trunk/include/bu/parallel.h
===================================================================
--- brlcad/trunk/include/bu/parallel.h 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/include/bu/parallel.h 2019-05-17 04:36:33 UTC (rev 73078)
@@ -187,19 +187,41 @@
* because bu_log() acquires semaphore #0 (BU_SEM_SYSCALL).
*/
-/*
- * Section for manifest constants for bu_semaphore_acquire()
+/**
+ *
*/
-#define BU_SEM_SYSCALL 0
-#define BU_SEM_LISTS 1
-#define BU_SEM_BN_NOISE 2
-#define BU_SEM_MAPPEDFILE 3
-#define BU_SEM_THREAD 4
-#define BU_SEM_MALLOC 5
-#define BU_SEM_DATETIME 6
-#define BU_SEM_HASH 7
-#define BU_SEM_DIR 8
-#define BU_SEM_LAST (BU_SEM_DIR+1) /* allocate this many for LIBBU+LIBBN */
+BU_EXPORT extern int bu_semaphore_register(const char *name);
+
+
+/**
+ * emaphores available for both library and application
+ * use.
+ *
+ */
+#define BU_SEMAPHORE_DEFINE(x) x = bu_semaphore_register(CPP_STR(x))
+
+/**
+ * This semaphore is intended for short-lived protection.
+ *
+ * It is provided for both library and application use, code that
+ * doesn't call into a BRL-CAD library.
+ */
+BU_EXPORT extern int BU_SEM_GENERAL;
+
+/**
+ * This semaphore is intended to protect general system calls.
+ *
+ * It is provided for both library and application use, code that
+ * doesn't call into a BRL-CAD library.
+ */
+BU_EXPORT extern int BU_SEM_SYSCALL;
+
+/**
+ * FIXME: this one shouldn't need to be global.
+ */
+BU_EXPORT extern int BU_SEM_MAPPEDFILE;
+
+
/*
* Automatic restart capability in bu_bomb(). The return from
* BU_SETJUMP is the return from the setjmp(). It is 0 on the first
@@ -227,6 +249,8 @@
/**
* Release all initialized semaphores and any associated memory.
+ *
+ * FIXME: per hacking, rename to bu_semaphore_clear()
*/
BU_EXPORT extern void bu_semaphore_free(void);
Modified: brlcad/trunk/include/common.h
===================================================================
--- brlcad/trunk/include/common.h 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/include/common.h 2019-05-17 04:36:33 UTC (rev 73078)
@@ -388,41 +388,23 @@
#ifdef __cplusplus
# define INITIALIZE(lib) \
- static void lib(void); \
- struct lib##_t_ { lib##_t_(void) { lib(); } }; static lib##_t_ lib##_;
\
- static void lib(void)
+static void lib(void); \
+struct lib##_t_ { lib##_t_(void) { lib(); } }; static lib##_t_ lib##_; \
+static void lib(void)
-#elif defined(_MSC_VER)
+/* #elif defined(HAVE_WINDOWS_H) */
-/* We may have issues with this trick in 2015 optimized builds. See:
- *
- * https://bugzilla.gnome.org/show_bug.cgi?id=752837
- * https://github.com/GNOME/glib/blob/master/glib/gconstructor.h
- *
- * for what the glib folks had to go through, and even after all that they had
- * to leave their static build broken on Windows... */
+/* # define INITIALIZE(lib) \ */
+/* \ */
+/* static void lib(void); \ */
+/* BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID nil) { lib();
return TRUE; } \ */
+/* static void lib(void) */
-# ifdef _WIN64
-# define INITIALIZE(lib) \
- __pragma(section(".CRT$XCU",read)) \
- static void lib(void); \
- __declspec(allocate(".CRT$XCU")) void (*lib##_)(void) = lib; \
- __pragma(comment(linker,"/include:" #lib "_")) \
- static void lib(void)
-# else
-# define INITIALIZE(lib) \
- __pragma(section(".CRT$XCU",read)) \
- static void lib(void); \
- __declspec(allocate(".CRT$XCU")) void (*lib##_)(void) = lib; \
- __pragma(comment(linker,"/include:" "_" #lib "_")) \
- static void lib(void)
-# endif
-
#else
-# define INITIALIZE(lib) \
- static void lib(void) __attribute__((constructor)); \
- static void lib(void)
+/* # define INITIALIZE(lib) \ */
+/* static void lib(void) __attribute__((constructor)); \ */
+/* static void lib(void) */
#endif
Modified: brlcad/trunk/include/photonmap.h
===================================================================
--- brlcad/trunk/include/photonmap.h 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/include/photonmap.h 2019-05-17 04:36:33 UTC (rev 73078)
@@ -53,6 +53,7 @@
#define PM_SHADOW 2 /* Current not used */
#define PM_IMPORTANCE 3
+
/**
* Photon Map Data Structure
*/
Modified: brlcad/trunk/include/rt/defines.h
===================================================================
--- brlcad/trunk/include/rt/defines.h 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/include/rt/defines.h 2019-05-17 04:36:33 UTC (rev 73078)
@@ -179,26 +179,7 @@
# define RT_G_DEBUG RTG.debug
#endif
-/**
- * Definition of global parallel-processing semaphores.
- *
- * res_syscall is now BU_SEM_SYSCALL
- */
-#define RT_SEM_TREE0 (BU_SEM_LAST)
-#define RT_SEM_TREE1 (RT_SEM_TREE0+1)
-#define RT_SEM_TREE2 (RT_SEM_TREE1+1)
-#define RT_SEM_TREE3 (RT_SEM_TREE2+1)
-#define RT_SEM_WORKER (RT_SEM_TREE3+1)
-#define RT_SEM_STATS (RT_SEM_WORKER+1)
-#define RT_SEM_RESULTS (RT_SEM_STATS+1)
-#define RT_SEM_MODEL (RT_SEM_RESULTS+1)
-#define RT_SEM_CACHE (RT_SEM_MODEL+1)
-#define RT_SEM_PM (RT_SEM_CACHE+1)
-#define RT_SEM_TIE (RT_SEM_PM+1)
-#define RT_SEM_LAST (RT_SEM_TIE+1)
-
-
#define BACKING_DIST (-2.0) /**< @brief mm to look behind start
point */
#define OFFSET_DIST 0.01 /**< @brief mm to advance point into
box */
Modified: brlcad/trunk/include/rt/resource.h
===================================================================
--- brlcad/trunk/include/rt/resource.h 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/include/rt/resource.h 2019-05-17 04:36:33 UTC (rev 73078)
@@ -111,6 +111,20 @@
#define RT_CK_RESOURCE(_p) BU_CKMAG(_p, RESOURCE_MAGIC, "struct resource")
#define RT_RESOURCE_INIT_ZERO { RESOURCE_MAGIC, 0, BU_LIST_INIT_ZERO,
BU_PTBL_INIT_ZERO, 0, 0, 0, BU_LIST_INIT_ZERO, 0, 0, 0, BU_LIST_INIT_ZERO,
BU_LIST_INIT_ZERO, BU_LIST_INIT_ZERO, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
NULL, 0, 0, 0, 0, BU_PTBL_INIT_ZERO, NULL, 0, 0, 0, NULL, BU_PTBL_INIT_ZERO }
+/**
+ * Definition of global parallel-processing semaphores.
+ *
+ * res_syscall is now BU_SEM_SYSCALL
+ */
+RT_EXPORT extern int RT_SEM_WORKER;
+RT_EXPORT extern int RT_SEM_MODEL;
+RT_EXPORT extern int RT_SEM_RESULTS;
+RT_EXPORT extern int RT_SEM_TREE0;
+RT_EXPORT extern int RT_SEM_TREE1;
+RT_EXPORT extern int RT_SEM_TREE2;
+RT_EXPORT extern int RT_SEM_TREE3;
+
+
__END_DECLS
#endif /* RT_RESOURCE_H */
Modified: brlcad/trunk/src/adrt/librender/camera.c
===================================================================
--- brlcad/trunk/src/adrt/librender/camera.c 2019-05-16 22:26:26 UTC (rev
73077)
+++ brlcad/trunk/src/adrt/librender/camera.c 2019-05-17 04:36:33 UTC (rev
73078)
@@ -23,14 +23,17 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include "bio.h"
-#include "bio.h"
#include "bu/parallel.h"
#include "bu/dylib.h"
-#include "raytrace.h" /* for RT_SEM_TIE semaphore */
+#include "bu/parallel.h"
+#include "bu/log.h"
+#include "bu/str.h"
-#include "camera.h"
+#include "./camera.h"
+
struct render_shader_s {
const char *name;
int (*init)(render_t *, const char *);
@@ -408,15 +411,15 @@
while (1) {
/* Determine if this scanline should be computed by this thread */
- bu_semaphore_acquire(RT_SEM_TIE);
+ bu_semaphore_acquire(td->sem_tie_worker);
if (*td->scanline == td->tile->size_y) {
- bu_semaphore_release(RT_SEM_TIE);
+ bu_semaphore_release(td->sem_tie_worker);
return;
} else {
scanline = *td->scanline;
(*td->scanline)++;
}
- bu_semaphore_release(RT_SEM_TIE);
+ bu_semaphore_release(td->sem_tie_worker);
v_scanline = scanline + td->tile->orig_y;
if (td->tile->format == RENDER_CAMERA_BIT_DEPTH_24) {
@@ -542,6 +545,7 @@
td.res_buf = &((char *)result->data)[result->ind];
scanline = 0;
td.scanline = &scanline;
+ td.sem_tie_worker = bu_semaphore_register("sem_tie_worker");
bu_parallel(render_camera_render_thread, camera->thread_num, &td);
Modified: brlcad/trunk/src/adrt/librender/camera.h
===================================================================
--- brlcad/trunk/src/adrt/librender/camera.h 2019-05-16 22:26:26 UTC (rev
73077)
+++ brlcad/trunk/src/adrt/librender/camera.h 2019-05-17 04:36:33 UTC (rev
73078)
@@ -88,6 +88,7 @@
camera_tile_t *tile;
void *res_buf;
unsigned int *scanline;
+ int sem_tie_worker;
} render_camera_thread_data_t;
Modified: brlcad/trunk/src/burst/paint.c
===================================================================
--- brlcad/trunk/src/burst/paint.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/burst/paint.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -127,9 +127,9 @@
for (y = gyorg; y < gyfin; y++) {
if (zoom != 1 && (y - gy) % zoom == 0)
continue;
- bu_semaphore_acquire(RT_SEM_STATS);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
(void) fb_read(fbiop, gxorg, y, (unsigned char *)pixbuf, cnt);
- bu_semaphore_release(RT_SEM_STATS);
+ bu_semaphore_release(BU_SEM_GENERAL);
for (x = gxorg; x < gxfin; x++) {
if (SAMERGB(&pixbuf[x-gxorg][0], pixexpendable)
) {
@@ -151,9 +151,9 @@
pixbuf[x-gxorg][BLU]);
#endif
}
- bu_semaphore_acquire(RT_SEM_STATS);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
(void) fb_write(fbiop, gxorg, y, (unsigned char *)pixbuf, cnt);
- bu_semaphore_release(RT_SEM_STATS);
+ bu_semaphore_release(BU_SEM_GENERAL);
#if DEBUG_CELLFB
brst_log("paintCellFb: fb_write(%d, %d)\n", x, y);
#endif
@@ -182,9 +182,9 @@
celldist = ap->a_cumlen/cellsz * zoom;
x = roundToInt(x + VDOT(ap->a_ray.r_dir, gridhor) * celldist);
y = roundToInt(y + VDOT(ap->a_ray.r_dir, gridver) * celldist);
- bu_semaphore_acquire(RT_SEM_STATS);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
err = fb_write(fbiop, x, y, pixel, 1);
- bu_semaphore_release(RT_SEM_STATS);
+ bu_semaphore_release(BU_SEM_GENERAL);
#if DEBUG_SPALLFB
brst_log("paintSpallFb:gridhor=<%g, %g, %g> gridver=<%g, %g, %g>\n",
gridhor[X], gridhor[Y], gridhor[Z],
Modified: brlcad/trunk/src/gtools/beset/fitness.c
===================================================================
--- brlcad/trunk/src/gtools/beset/fitness.c 2019-05-16 22:26:26 UTC (rev
73077)
+++ brlcad/trunk/src/gtools/beset/fitness.c 2019-05-17 04:36:33 UTC (rev
73078)
@@ -120,9 +120,9 @@
int status = 0;
if (partHeadp == NULL && fstate->ray[ap->a_user] == NULL) {
- bu_semaphore_acquire(SEM_SAME);
+ bu_semaphore_acquire(fstate->sem_same);
fstate->same += fstate->a_len;
- bu_semaphore_release(SEM_SAME);
+ bu_semaphore_release(fstate->sem_same);
return 0;
}
@@ -136,8 +136,8 @@
/* if both rays missed, count this as the same.
* no need to evaluate further*/
- bu_semaphore_acquire(SEM_SAME);
- bu_semaphore_acquire(SEM_DIFF);
+ bu_semaphore_acquire(fstate->sem_same);
+ bu_semaphore_acquire(fstate->sem_diff);
while (pp != partHeadp && mp != fstate->ray[ap->a_user]) {
if (status & STATUS_PP)
@@ -263,8 +263,8 @@
/* include trailing empty space as similar */
fstate->same += fstate->a_len - lastpt;
- bu_semaphore_release(SEM_SAME);
- bu_semaphore_release(SEM_DIFF);
+ bu_semaphore_release(fstate->sem_same);
+ bu_semaphore_release(fstate->sem_diff);
return 1;
}
@@ -288,12 +288,12 @@
get_next_row(struct fitness_state *fstate)
{
int r;
- bu_semaphore_acquire(SEM_WORK);
+ bu_semaphore_acquire(fstate->sem_work);
if (fstate->row < fstate->res[Y])
r = ++fstate->row; /* get a row to work on */
else
r = 0; /* signal end of work */
- bu_semaphore_release(SEM_WORK);
+ bu_semaphore_release(fstate->sem_work);
return r;
}
@@ -479,6 +479,9 @@
void
fit_prep(struct fitness_state *fstate, int rows, int cols)
{
+ fstate->sem_work = bu_semaphore_register("beset_sem_work");
+ fstate->sem_diff = bu_semaphore_register("beset_sem_diff");
+ fstate->sem_same = bu_semaphore_register("beset_sem_same");
fstate->max_cpus = fstate->ncpu = 1;/*bu_avail_cpus();*/
fstate->capture = 0;
fstate->res[X] = rows;
Modified: brlcad/trunk/src/gtools/beset/fitness.h
===================================================================
--- brlcad/trunk/src/gtools/beset/fitness.h 2019-05-16 22:26:26 UTC (rev
73077)
+++ brlcad/trunk/src/gtools/beset/fitness.h 2019-05-17 04:36:33 UTC (rev
73078)
@@ -37,12 +37,7 @@
#define STATUS_MP 2
#define STATUS_EMPTY 0
-#define SEM_WORK RT_SEM_LAST
-#define SEM_DIFF RT_SEM_LAST+1
-#define SEM_SAME RT_SEM_LAST+2
-#define TOTAL_SEMAPHORES SEM_SAME+1
-
struct part {
struct bu_list l;
fastf_t inhit_dist;
@@ -54,6 +49,10 @@
struct part **ray; /* internal representation of raytraced source */
struct rt_i *rtip; /* current objects to be raytraced */
+ /* semaphores for parallel */
+ int sem_work;
+ int sem_diff;
+ int sem_same;
struct resource resource[MAX_PSW]; /* memory resource for multi-cpu
processing */
int ncpu;
int max_cpus;
Modified: brlcad/trunk/src/libanalyze/analyze_private.h
===================================================================
--- brlcad/trunk/src/libanalyze/analyze_private.h 2019-05-16 22:26:26 UTC
(rev 73077)
+++ brlcad/trunk/src/libanalyze/analyze_private.h 2019-05-17 04:36:33 UTC
(rev 73078)
@@ -100,10 +100,14 @@
int v_axis; /* is being used for the U, V, or invariant vector
direction */
int i_axis;
- /* ANALYZE_SEM_WORKER protects this */
+ int sem_worker;
+
+ /* sem_worker protects this */
int v; /* indicates how many "grid_size" steps in the v
direction have been taken */
- /* ANALYZE_SEM_STATS protects this */
+ int sem_stats;
+
+ /* sem_stats protects this */
double *m_lenDensity;
double *m_len;
unsigned long *shots;
Modified: brlcad/trunk/src/libanalyze/api.c
===================================================================
--- brlcad/trunk/src/libanalyze/api.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/libanalyze/api.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -82,7 +82,8 @@
if (!segs) /* unexpected */
return 0;
- if (PartHeadp->pt_forw == PartHeadp) return 1;
+ if (PartHeadp->pt_forw == PartHeadp)
+ return 1;
/* examine each partition until we get back to the head */
@@ -107,10 +108,10 @@
VJOIN1(opt, ap->a_ray.r_pt, pp->pt_outhit->hit_dist, ap->a_ray.r_dir);
if (state->debug) {
- bu_semaphore_acquire(ANALYZE_SEM_WORKER);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
bu_vls_printf(state->debug_str, "%s %g->%g\n",
pp->pt_regionp->reg_name,
pp->pt_inhit->hit_dist, pp->pt_outhit->hit_dist);
- bu_semaphore_release(ANALYZE_SEM_WORKER);
+ bu_semaphore_release(BU_SEM_GENERAL);
}
if (state->analysis_flags & ANALYSIS_EXP_AIR) {
@@ -145,18 +146,18 @@
/* computing the mass of the objects */
if (state->analysis_flags & ANALYSIS_MASS) {
if (state->debug) {
- bu_semaphore_acquire(ANALYZE_SEM_WORKER);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
bu_vls_printf(state->debug_str, "Hit %s doing mass\n",
pp->pt_regionp->reg_name);
- bu_semaphore_release(ANALYZE_SEM_WORKER);
+ bu_semaphore_release(BU_SEM_GENERAL);
}
/* make sure mater index is within range of densities */
if (material_id < 0 && state->default_den == 0) {
- bu_semaphore_acquire(ANALYZE_SEM_WORKER);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
bu_vls_printf(state->log_str, "Density index %d on region %s is
not in density table.\nSet GIFTmater on region or add entry to density table\n",
pp->pt_regionp->reg_gmater,
pp->pt_regionp->reg_name); /* XXX this should do
something else */
- bu_semaphore_release(ANALYZE_SEM_WORKER);
+ bu_semaphore_release(BU_SEM_GENERAL);
return ANALYZE_ERROR;
}
@@ -205,9 +206,9 @@
los = pp->pt_regionp->reg_los;
if (los < 1) {
- bu_semaphore_acquire(ANALYZE_SEM_WORKER);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
bu_vls_printf(state->log_str, "bad LOS (%d) on %s\n", los,
pp->pt_regionp->reg_name);
- bu_semaphore_release(ANALYZE_SEM_WORKER);
+ bu_semaphore_release(BU_SEM_GENERAL);
}
/* accumulate the total mass values */
@@ -216,7 +217,7 @@
prd = ((struct per_region_data *)pp->pt_regionp->reg_udata);
/* accumulate the per-region per-view mass values */
- bu_semaphore_acquire(ANALYZE_SEM_STATS);
+ bu_semaphore_acquire(state->sem_stats);
prd->r_lenDensity[state->i_axis] += val;
/* accumulate the per-object per-view mass values */
@@ -265,7 +266,7 @@
poi[Z] -= mass*cmass[Y]*cmass[Z];
}
}
- bu_semaphore_release(ANALYZE_SEM_STATS);
+ bu_semaphore_release(state->sem_stats);
}
}
@@ -293,7 +294,7 @@
}
{
- bu_semaphore_acquire(ANALYZE_SEM_STATS);
+ bu_semaphore_acquire(state->sem_worker);
/* factor in the normal vector to find how 'skew' the surface
is */
RT_HIT_NORMAL(inormal, pp->pt_inhit, pp->pt_inseg->seg_stp,
&(ap->a_ray), pp->pt_inflip);
VREVERSE(inormal, inormal);
@@ -311,7 +312,7 @@
prd->optr->o_area[state->curr_view] += (cell_area/icos);
prd->optr->o_area[state->curr_view] += (cell_area/ocos);
- bu_semaphore_release(ANALYZE_SEM_STATS);
+ bu_semaphore_release(state->sem_worker);
}
}
@@ -320,7 +321,7 @@
struct per_region_data *prd = ((struct per_region_data
*)pp->pt_regionp->reg_udata);
ap->A_LEN += dist; /* add to total volume */
{
- bu_semaphore_acquire(ANALYZE_SEM_STATS);
+ bu_semaphore_acquire(state->sem_worker);
/* add to region volume */
prd->r_len[state->curr_view] += dist;
@@ -328,16 +329,15 @@
/* add to object volume */
prd->optr->o_len[state->curr_view] += dist;
- bu_semaphore_release(ANALYZE_SEM_STATS);
+ bu_semaphore_release(state->sem_worker);
}
if (state->debug) {
- bu_semaphore_acquire(ANALYZE_SEM_WORKER);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
bu_vls_printf(state->debug_str, "\t\tvol hit %s oDist:%g
objVol:%g %s\n",
pp->pt_regionp->reg_name, dist,
prd->optr->o_len[state->curr_view], prd->optr->o_name);
- bu_semaphore_release(ANALYZE_SEM_WORKER);
+ bu_semaphore_release(BU_SEM_GENERAL);
}
if (state->plot_volume) {
- bu_semaphore_acquire(BU_SEM_SYSCALL);
if (ap->a_user & 1) {
pl_color(state->plot_volume, 128, 255, 192); /* pale green
*/
} else {
@@ -345,7 +345,6 @@
}
pdv_3line(state->plot_volume, pt, opt);
- bu_semaphore_release(BU_SEM_SYSCALL);
}
}
@@ -358,7 +357,7 @@
}
if (pp->pt_regionp->reg_aircode) {
- /* look for air first on shotlines */
+ /* look for air first on shotlines */
if (pp->pt_back == PartHeadp) {
if (state->analysis_flags & ANALYSIS_FIRST_AIR)
state->first_air_callback(&ap->a_ray, pp,
state->first_air_callback_data);
@@ -460,14 +459,14 @@
VJOIN1(ihit, rp->r_pt, ihitp->hit_dist, rp->r_dir);
if (state->analysis_flags & ANALYSIS_OVERLAPS) {
- bu_semaphore_acquire(ANALYZE_SEM_LIST);
+ bu_semaphore_acquire(state->sem_worker);
add_unique_pair(state->overlapList, reg1, reg2, depth, ihit);
- bu_semaphore_release(ANALYZE_SEM_LIST);
+ bu_semaphore_release(state->sem_worker);
state->overlaps_callback(&ap->a_ray, pp, reg1, reg2, depth,
state->overlaps_callback_data);
} else {
- bu_semaphore_acquire(ANALYZE_SEM_WORKER);
+ bu_semaphore_acquire(state->sem_worker);
bu_vls_printf(state->log_str, "overlap %s %s\n", reg1->reg_name,
reg2->reg_name);
- bu_semaphore_release(ANALYZE_SEM_WORKER);
+ bu_semaphore_release(state->sem_worker);
}
/* XXX We should somehow flag the volume/mass calculations as invalid */
@@ -801,13 +800,13 @@
shot_cnt = 0;
while (1) {
- bu_semaphore_acquire(ANALYZE_SEM_WORKER);
+ bu_semaphore_acquire(state->sem_worker);
if (rectangular_grid_generator(&ap.a_ray, state->grid) == 1){
- bu_semaphore_release(ANALYZE_SEM_WORKER);
+ bu_semaphore_release(state->sem_worker);
break;
}
ap.a_user = (int)(state->grid->current_point / (state->grid->x_points));
- bu_semaphore_release(ANALYZE_SEM_WORKER);
+ bu_semaphore_release(state->sem_worker);
(void)rt_shootray(&ap);
if (state->aborted)
return;
@@ -819,11 +818,11 @@
* view and return. When all threads have been through here,
* we'll have returned to serial computation.
*/
- bu_semaphore_acquire(ANALYZE_SEM_STATS);
+ bu_semaphore_acquire(state->sem_stats);
state->shots[state->curr_view] += shot_cnt;
state->m_lenDensity[state->curr_view] += ap.A_LENDEN; /* add our
length*density value */
state->m_len[state->curr_view] += ap.A_LEN; /* add our volume value */
- bu_semaphore_release(ANALYZE_SEM_STATS);
+ bu_semaphore_release(state->sem_stats);
}
/**
@@ -1401,6 +1400,8 @@
}
/* initialize some stuff */
+ state->sem_worker = bu_semaphore_register("analyze_sem_worker");
+ state->sem_stats = bu_semaphore_register("analyze_sem_stats");
allocate_region_data(state, names);
grid.refine_flag = 0;
shoot_rays(state);
Modified: brlcad/trunk/src/libbn/noise.c
===================================================================
--- brlcad/trunk/src/libbn/noise.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/libbn/noise.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -162,6 +162,9 @@
]
+static int sem_noise = 0;
+
+
void
bn_noise_init(void)
{
@@ -168,10 +171,13 @@
uint32_t i, j, k, temp;
uint32_t rndtabi = BN_RAND_TABSIZE - 1;
- bu_semaphore_acquire(BU_SEM_BN_NOISE);
+ if (!sem_noise)
+ sem_noise = bu_semaphore_register("SEM_NOISE");
+ bu_semaphore_acquire(sem_noise);
+
if (ht.hashTableValid) {
- bu_semaphore_release(BU_SEM_BN_NOISE);
+ bu_semaphore_release(sem_noise);
return;
}
@@ -201,7 +207,7 @@
ht.hashTableValid = 1;
- bu_semaphore_release(BU_SEM_BN_NOISE);
+ bu_semaphore_release(sem_noise);
CK_HT();
}
@@ -491,7 +497,7 @@
* the list to wait our turn to add what we want to the table.
*/
- bu_semaphore_acquire(BU_SEM_BN_NOISE);
+ bu_semaphore_acquire(sem_noise);
/* We search the list one more time in case the last process to
* hold the semaphore just created the table we were about to add
@@ -511,7 +517,7 @@
if (i >= etbl_next)
ep = build_spec_tbl(h, l, o);
- bu_semaphore_release(BU_SEM_BN_NOISE);
+ bu_semaphore_release(sem_noise);
return ep;
}
Modified: brlcad/trunk/src/libbrep/PullbackCurve.cpp
===================================================================
--- brlcad/trunk/src/libbrep/PullbackCurve.cpp 2019-05-16 22:26:26 UTC (rev
73077)
+++ brlcad/trunk/src/libbrep/PullbackCurve.cpp 2019-05-17 04:36:33 UTC (rev
73078)
@@ -258,7 +258,8 @@
int p = bu_parallel_id();
if (!locals_initialized[p]) {
- bu_semaphore_acquire(BU_SEM_MALLOC);
+ static int sem_pullback_init =
bu_semaphore_register("SEM_PULLBACK_INIT");
+ bu_semaphore_acquire(sem_pullback_init);
rev_surface[p] = ON_RevSurface::New();
nurbs_surface[p] = ON_NurbsSurface::New();
extr_surface[p] = new ON_Extrusion();
@@ -266,7 +267,7 @@
sum_surface[p] = ON_SumSurface::New();
proxy_surface[p] = new ON_SurfaceProxy();
locals_initialized[p] = true;
- bu_semaphore_release(BU_SEM_MALLOC);
+ bu_semaphore_release(sem_pullback_init);
}
ON_Interval domSplits[2][2] = { { ON_Interval::EmptyInterval,
ON_Interval::EmptyInterval }, { ON_Interval::EmptyInterval,
ON_Interval::EmptyInterval }};
Modified: brlcad/trunk/src/libbu/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libbu/CMakeLists.txt 2019-05-16 22:26:26 UTC (rev
73077)
+++ brlcad/trunk/src/libbu/CMakeLists.txt 2019-05-17 04:36:33 UTC (rev
73078)
@@ -61,6 +61,7 @@
bomb.c
booleanize.c
brlcad_path.c
+ bu_init.cpp
cmd.c
cmdhist.c
color.c
@@ -90,7 +91,6 @@
hook.c
htond.c
htonf.c
- init.c
interrupt.c
kill.c
lex.c
@@ -116,6 +116,7 @@
redblack.c
realpath.c
semaphore.c
+ semaphore_register.cpp
sha1.c
simd.c
sort.c
@@ -152,32 +153,22 @@
# Define a pre-build test for libbu to check the semaphores in BRL-CAD's
headers for
# ordering issues
-set(BCAD_SRCS_FILE "${CMAKE_CURRENT_BINARY_DIR}/brlcad_srcs.txt")
-file(REMOVE "${BCAD_SRCS_FILE}")
-file(GLOB_RECURSE BCAD_HDRS "${CMAKE_SOURCE_DIR}/include/*.h*")
-foreach(HDRF ${BCAD_HDRS})
- if (NOT "${HDRF}" MATCHES ".*.svn.*")
- file(APPEND "${BCAD_SRCS_FILE}" "${HDRF}\n")
- endif (NOT "${HDRF}" MATCHES ".*.svn.*")
-endforeach(HDRF ${BCAD_HDRS})
-file(GLOB_RECURSE BCAD_SRCS "${CMAKE_SOURCE_DIR}/src/*.c*")
-foreach(SRCF ${BCAD_SRCS})
- if (NOT "${SRCF}" MATCHES ".*.svn.*")
- if (NOT "${SRCF}" MATCHES ".*/other/*")
- if (NOT "${SRCF}" MATCHES ".*/misc/*")
- file(APPEND "${BCAD_SRCS_FILE}" "${SRCF}\n")
- endif (NOT "${SRCF}" MATCHES ".*/misc/*")
- endif (NOT "${SRCF}" MATCHES ".*/other/*")
- endif (NOT "${SRCF}" MATCHES ".*.svn.*")
-endforeach(SRCF ${BCAD_SRCS})
-DISTCLEAN("${CMAKE_CURRENT_BINARY_DIR}/brlcad_srcs.txt")
-BRLCAD_ADDEXEC(semchk "tests/semchk.cxx" "" NO_INSTALL)
-add_custom_command(
- TARGET libbu PRE_BUILD
- COMMAND $<TARGET_FILE:semchk> "${BCAD_SRCS_FILE}"
- COMMENT "Validating BRL-CAD semaphore definitions"
- DEPENDS semchk
- )
+#set(BCAD_HDRS_FILE "${CMAKE_CURRENT_BINARY_DIR}/brlcad_headers.txt")
+#file(REMOVE "${BCAD_HDRS_FILE}")
+#file(GLOB_RECURSE BCAD_HDRS "${CMAKE_SOURCE_DIR}/include/*.h*")
+#foreach(HDRF ${BCAD_HDRS})
+# if (NOT "${HDRF}" MATCHES ".*.svn.*")
+# file(APPEND "${BCAD_HDRS_FILE}" "${HDRF}\n")
+# endif (NOT "${HDRF}" MATCHES ".*.svn.*")
+#endforeach(HDRF ${BCAD_HDRS})
+#DISTCLEAN("${CMAKE_CURRENT_BINARY_DIR}/brlcad_headers.txt")
+#BRLCAD_ADDEXEC(semchk "tests/semchk.cxx" "" NO_INSTALL)
+#add_custom_command(
+# TARGET libbu PRE_BUILD
+# COMMAND $<TARGET_FILE:semchk> "${BCAD_HDRS_FILE}"
+# COMMENT "Validating BRL-CAD library semaphore definitions"
+# DEPENDS semchk
+# )
BRLCAD_ADDDATA(fix.6r vfont)
BRLCAD_ADDDATA(nonie.r.12 vfont)
Added: brlcad/trunk/src/libbu/bu_init.cpp
===================================================================
--- brlcad/trunk/src/libbu/bu_init.cpp (rev 0)
+++ brlcad/trunk/src/libbu/bu_init.cpp 2019-05-17 04:36:33 UTC (rev 73078)
@@ -0,0 +1,104 @@
+/* B U _ I N I T . C P P
+ * BRL-CAD
+ *
+ * Copyright (c) 2019 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file init.c
+ *
+ * Sole purpose of this file is to capture status and aspects of an
+ * application and the application's environment when first run such
+ * as initial working directory and available memory. That is, it's
+ * intended to be reflective, not generative or conditional logic.
+ *
+ * Please do NOT add application-specific logic here.
+ *
+ * NOTE: as this init is global to ALL applications before main(),
+ * care must be taken to not write to STDOUT or STDERR or app output
+ * may be corrupted, signals can be raised, or worse.
+ *
+ */
+
+#include "common.h"
+
+#include "bu/defines.h"
+#include "bu/app.h"
+#include "bu/parallel.h"
+
+#include <iostream>
+
+
+/* These ARE exported outside LIBBU */
+int BU_SEM_GENERAL;
+int BU_SEM_SYSCALL;
+int BU_SEM_BN_NOISE;
+int BU_SEM_MAPPEDFILE;
+
+/* These ARE NOT exported outside LIBBU */
+extern "C" int BU_SEM_DATETIME;
+extern "C" int BU_SEM_DIR;
+extern "C" int BU_SEM_MALLOC;
+extern "C" int BU_SEM_THREAD;
+
+
+static void
+libbu_init(void)
+{
+ char iwd[MAXPATHLEN] = {0};
+
+ BU_SEMAPHORE_DEFINE(BU_SEM_GENERAL);
+ BU_SEMAPHORE_DEFINE(BU_SEM_SYSCALL);
+ BU_SEMAPHORE_DEFINE(BU_SEM_BN_NOISE);
+ BU_SEMAPHORE_DEFINE(BU_SEM_MAPPEDFILE);
+ BU_SEMAPHORE_DEFINE(BU_SEM_THREAD);
+ BU_SEMAPHORE_DEFINE(BU_SEM_MALLOC);
+ BU_SEMAPHORE_DEFINE(BU_SEM_DATETIME);
+ BU_SEMAPHORE_DEFINE(BU_SEM_DIR);
+
+ bu_getiwd(iwd, MAXPATHLEN);
+}
+
+
+static void
+libbu_clear(void)
+{
+ bu_semaphore_free();
+}
+
+
+struct libbu_initializer {
+ /* constructor */
+ libbu_initializer() {
+ libbu_init();
+ }
+ /* destructor */
+ ~libbu_initializer() {
+ libbu_clear();
+ }
+};
+
+static libbu_initializer LIBBU;
+
+
+/*
+ * Local Variables:
+ * tab-width: 8
+ * mode: C
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: brlcad/trunk/src/libbu/bu_init.cpp
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: brlcad/trunk/src/libbu/datetime.c
===================================================================
--- brlcad/trunk/src/libbu/datetime.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/libbu/datetime.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -47,7 +47,9 @@
extern int gettimeofday(struct timeval *, void *);
#endif
+int BU_SEM_DATETIME;
+
void
bu_utctime(struct bu_vls *vls_gmtime, const int64_t time_val)
{
Modified: brlcad/trunk/src/libbu/getcwd.c
===================================================================
--- brlcad/trunk/src/libbu/getcwd.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/libbu/getcwd.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -51,6 +51,9 @@
#endif
+int BU_SEM_DIR;
+
+
char *
bu_getcwd(char *buf, size_t size)
{
Modified: brlcad/trunk/src/libbu/hash.c
===================================================================
--- brlcad/trunk/src/libbu/hash.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/libbu/hash.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -40,6 +40,7 @@
struct bu_hash_tbl {
uint32_t magic;
+ int semaphore;
unsigned long mask;
unsigned long num_lists;
unsigned long num_entries;
@@ -47,6 +48,7 @@
};
#define BU_CK_HASH_TBL(_hp) BU_CKMAG(_hp, BU_HASH_TBL_MAGIC, "bu_hash_tbl")
+
HIDDEN unsigned long
_bu_hash(const uint8_t *key, size_t len)
{
@@ -62,7 +64,9 @@
return hash;
}
-HIDDEN int _nhash_keycmp(const uint8_t *k1, const uint8_t *k2, size_t key_len)
+
+HIDDEN int
+_nhash_keycmp(const uint8_t *k1, const uint8_t *k2, size_t key_len)
{
const uint8_t *c1 = k1;
const uint8_t *c2 = k2;
@@ -79,6 +83,7 @@
return match;
}
+
struct bu_hash_tbl *
bu_hash_create(unsigned long tbl_size)
{
@@ -120,6 +125,8 @@
*/
hsh_tbl->lists = (struct bu_hash_entry **)calloc(hsh_tbl->num_lists,
sizeof(struct bu_hash_entry *));
+ hsh_tbl->semaphore = bu_semaphore_register("SEM_HASH");
+
hsh_tbl->num_entries = 0;
hsh_tbl->magic = BU_HASH_TBL_MAGIC;
@@ -126,6 +133,7 @@
return hsh_tbl;
}
+
void
bu_hash_destroy(struct bu_hash_tbl *hsh_tbl)
{
@@ -221,7 +229,7 @@
if (!key || key_len == 0)
return -1;
- bu_semaphore_acquire(BU_SEM_HASH);
+ bu_semaphore_acquire(hsh_tbl->semaphore);
/* Use key hash to get bin, add entry to bin list */
idx = _bu_hash(key, key_len) & hsh_tbl->mask;
@@ -270,7 +278,7 @@
/* finally do as asked, set the value */
hsh_entry->value = val;
- bu_semaphore_release(BU_SEM_HASH);
+ bu_semaphore_release(hsh_tbl->semaphore);
return ret;
}
@@ -285,11 +293,11 @@
BU_CK_HASH_TBL(hsh_tbl);
- bu_semaphore_acquire(BU_SEM_HASH);
+ bu_semaphore_acquire(hsh_tbl->semaphore);
/* If we don't have a key, no-op */
if (!key || key_len == 0) {
- bu_semaphore_release(BU_SEM_HASH);
+ bu_semaphore_release(hsh_tbl->semaphore);
return;
}
@@ -298,7 +306,7 @@
/* Nothing in bin, we're done */
if (!hsh_tbl->lists[idx]) {
- bu_semaphore_release(BU_SEM_HASH);
+ bu_semaphore_release(hsh_tbl->semaphore);
return;
}
@@ -325,7 +333,7 @@
}
}
- bu_semaphore_release(BU_SEM_HASH);
+ bu_semaphore_release(hsh_tbl->semaphore);
}
@@ -337,11 +345,11 @@
BU_CK_HASH_TBL(hsh_tbl);
- bu_semaphore_acquire(BU_SEM_HASH);
+ bu_semaphore_acquire(hsh_tbl->semaphore);
if (hsh_tbl->num_entries == 0) {
/* this table is empty */
- bu_semaphore_release(BU_SEM_HASH);
+ bu_semaphore_release(hsh_tbl->semaphore);
return (struct bu_hash_entry *)NULL;
}
@@ -356,18 +364,18 @@
if (!ec) {
for (l = 0; l < hsh_tbl->num_lists; l++) {
if (hsh_tbl->lists[l]) {
- bu_semaphore_release(BU_SEM_HASH);
+ bu_semaphore_release(hsh_tbl->semaphore);
return hsh_tbl->lists[l];
}
}
/* if we've got nothing (empty bins) we're "done" iterating - return
* NULL */
- bu_semaphore_release(BU_SEM_HASH);
+ bu_semaphore_release(hsh_tbl->semaphore);
return (struct bu_hash_entry *)NULL;
}
if (e && e->next) {
- bu_semaphore_release(BU_SEM_HASH);
+ bu_semaphore_release(hsh_tbl->semaphore);
return e->next;
}
@@ -377,16 +385,17 @@
idx++;
for (l = idx; l < hsh_tbl->num_lists; l++) {
if (hsh_tbl->lists[l]) {
- bu_semaphore_release(BU_SEM_HASH);
+ bu_semaphore_release(hsh_tbl->semaphore);
return hsh_tbl->lists[l];
}
idx++;
}
/* if we've got nothing by this point we've reached the end */
- bu_semaphore_release(BU_SEM_HASH);
+ bu_semaphore_release(hsh_tbl->semaphore);
return (struct bu_hash_entry *)NULL;
}
+
int
bu_hash_key(struct bu_hash_entry *e, uint8_t **key, size_t *key_len)
{
Modified: brlcad/trunk/src/libbu/init.c
===================================================================
--- brlcad/trunk/src/libbu/init.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/libbu/init.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -38,6 +38,16 @@
#include "bu/app.h"
#include "bu/parallel.h"
+
+int BU_SEM_GENERAL;
+int BU_SEM_SYSCALL;
+int BU_SEM_BN_NOISE;
+int BU_SEM_MAPPEDFILE;
+int BU_SEM_THREAD;
+int BU_SEM_MALLOC;
+int BU_SEM_DATETIME;
+int BU_SEM_DIR;
+
/* The Visual C compiler pragmas needed for INITIALIZE specify a "read"
* attribute, which is conflicting with the system definition of read:
*
@@ -52,6 +62,16 @@
INITIALIZE(libbu)
{
char iwd[MAXPATHLEN] = {0};
+
+ BU_SEMAPHORE_DEFINE(BU_SEM_GENERAL);
+ BU_SEMAPHORE_DEFINE(BU_SEM_SYSCALL);
+ BU_SEMAPHORE_DEFINE(BU_SEM_BN_NOISE);
+ BU_SEMAPHORE_DEFINE(BU_SEM_MAPPEDFILE);
+ BU_SEMAPHORE_DEFINE(BU_SEM_THREAD);
+ BU_SEMAPHORE_DEFINE(BU_SEM_MALLOC);
+ BU_SEMAPHORE_DEFINE(BU_SEM_DATETIME);
+ BU_SEMAPHORE_DEFINE(BU_SEM_DIR);
+
bu_getiwd(iwd, MAXPATHLEN);
}
Modified: brlcad/trunk/src/libbu/list.c
===================================================================
--- brlcad/trunk/src/libbu/list.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/libbu/list.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -26,6 +26,7 @@
#include "bu/malloc.h"
#include "bu/parallel.h"
+
struct bu_list *
bu_list_new(void)
{
@@ -86,32 +87,7 @@
}
}
-void
-bu_list_parallel_append(struct bu_list *headp, struct bu_list *itemp)
-{
- bu_semaphore_acquire(BU_SEM_LISTS);
- BU_LIST_INSERT(headp, itemp); /* insert before head = append
*/
- bu_semaphore_release(BU_SEM_LISTS);
-}
-struct bu_list *
-bu_list_parallel_dequeue(struct bu_list *headp)
-{
- for (;;) {
- register struct bu_list *p;
-
- bu_semaphore_acquire(BU_SEM_LISTS);
- p = BU_LIST_FIRST(bu_list, headp);
- if (BU_LIST_NOT_HEAD(p, headp)) {
- BU_LIST_DEQUEUE(p);
- bu_semaphore_release(BU_SEM_LISTS);
- return p;
- }
- bu_semaphore_release(BU_SEM_LISTS);
- }
- /* NOTREACHED */
-}
-
void
bu_ck_list(const struct bu_list *hd, const char *str)
{
Modified: brlcad/trunk/src/libbu/malloc.c
===================================================================
--- brlcad/trunk/src/libbu/malloc.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/libbu/malloc.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -43,7 +43,9 @@
extern int posix_memalign(void **, size_t, size_t);
#endif
+int BU_SEM_MALLOC;
+
/**
* this controls whether to semaphore protect malloc calls
*
Modified: brlcad/trunk/src/libbu/parallel.c
===================================================================
--- brlcad/trunk/src/libbu/parallel.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/libbu/parallel.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -111,7 +111,9 @@
void parallel_cpp11thread(void (*func)(int, void *), size_t ncpu, void *arg);
#endif /* CPP11THREAD */
+int BU_SEM_THREAD;
+
typedef enum {
PARALLEL_GET = 0,
PARALLEL_PUT = 1
Modified: brlcad/trunk/src/libbu/semaphore.c
===================================================================
--- brlcad/trunk/src/libbu/semaphore.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/libbu/semaphore.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -85,6 +85,7 @@
#endif
+
void
bu_semaphore_init(unsigned int nsemaphores)
{
@@ -169,6 +170,8 @@
void
bu_semaphore_free(void)
{
+ extern void semaphore_clear(void);
+ semaphore_clear();
#if !defined(PARALLEL) && !defined(DEFINED_BU_SEMAPHORES)
return; /* No support on this hardware
*/
Copied: brlcad/trunk/src/libbu/semaphore_register.cpp (from rev 73053,
brlcad/trunk/src/libbu/semaphore_register.cpp)
===================================================================
--- brlcad/trunk/src/libbu/semaphore_register.cpp
(rev 0)
+++ brlcad/trunk/src/libbu/semaphore_register.cpp 2019-05-17 04:36:33 UTC
(rev 73078)
@@ -0,0 +1,85 @@
+#include "common.h"
+
+#include <vector>
+
+#include "bu/str.h"
+#include "bu/parallel.h"
+
+/* #define DEBUGSEM 1 */
+#ifdef DEBUGSEM
+# include <iostream>
+#endif
+
+
+static const int SEM_LOCK = 1;
+
+static std::vector<const char *> &
+semaphore_registry(bool wipe = false)
+{
+ /* semaphore #1 is used internally here and only here, so we start with it */
+ static std::vector<const char *> semaphores = {"SEM_LOCK"};
+
+ if (wipe) {
+#ifdef DEBUGSEM
+ std::cout << "!!! clearing " << semaphores.size() << " semaphores" <<
std::endl;
+ for (size_t i = 0; i < semaphores.size(); i++) {
+ std::cout << "!!! found " << semaphores[i] << " = " << i+1 << std::endl;
+ }
+#endif
+ bu_semaphore_acquire(SEM_LOCK);
+ semaphores.clear();
+ bu_semaphore_release(SEM_LOCK);
+ }
+
+ return semaphores;
+}
+
+
+extern "C" void
+semaphore_clear(void)
+{
+ (void)semaphore_registry(true);
+}
+
+
+static size_t
+semaphore_registered(const char *name)
+{
+ const std::vector<const char *> &semaphores = semaphore_registry();
+
+ for (size_t i = 0; i < semaphores.size(); ++i) {
+ if (BU_STR_EQUAL(semaphores[i], name)) {
+#ifdef DEBUGSEM
+ printf("!!! found %s = %zu\n", semaphores[i], i+1);
+#endif
+ return i+1;
+ }
+ }
+ return 0;
+}
+
+
+extern "C" int
+bu_semaphore_register(const char *name)
+{
+ std::vector<const char *> &semaphores = semaphore_registry();
+
+#ifdef DEBUGSEM
+ printf("!!! registering %s (have %zu)\n", name, semaphores.size());
+#endif
+
+ bu_semaphore_acquire(SEM_LOCK);
+ size_t idx = semaphore_registered(name);
+ if (!idx) {
+ semaphores.push_back(name);
+ idx = semaphores.size();
+ }
+ bu_semaphore_release(SEM_LOCK);
+
+#ifdef DEBUGSEM
+ printf("!!! added %s = %zu\n", name, idx);
+#endif
+
+ return idx;
+}
+
Modified: brlcad/trunk/src/libbu/thread.cpp
===================================================================
--- brlcad/trunk/src/libbu/thread.cpp 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/libbu/thread.cpp 2019-05-17 04:36:33 UTC (rev 73078)
@@ -29,6 +29,9 @@
#include "bu/parallel.h"
+extern "C" int BU_SEM_THREAD;
+
+
#if defined(HAVE_THREAD_LOCAL)
static thread_local int thread_cpu = 0;
Modified: brlcad/trunk/src/libged/check/check_adj_air.c
===================================================================
--- brlcad/trunk/src/libged/check/check_adj_air.c 2019-05-16 22:26:26 UTC
(rev 73077)
+++ brlcad/trunk/src/libged/check/check_adj_air.c 2019-05-17 04:36:33 UTC
(rev 73078)
@@ -39,9 +39,9 @@
adj_air(const struct xray* ray, const struct partition *pp, point_t pt, void*
callback_data)
{
struct adj_air_context *context = (struct adj_air_context*) callback_data;
- bu_semaphore_acquire(GED_SEM_LIST);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
add_to_list(context->adjAirList, pp->pt_back->pt_regionp->reg_name,
pp->pt_regionp->reg_name, 0.0, pt);
- bu_semaphore_release(GED_SEM_LIST);
+ bu_semaphore_release(BU_SEM_GENERAL);
if (context->plot_adjair) {
double d = pp->pt_outhit->hit_dist - pp->pt_inhit->hit_dist;
Modified: brlcad/trunk/src/libged/check/check_exp_air.c
===================================================================
--- brlcad/trunk/src/libged/check/check_exp_air.c 2019-05-16 22:26:26 UTC
(rev 73077)
+++ brlcad/trunk/src/libged/check/check_exp_air.c 2019-05-17 04:36:33 UTC
(rev 73078)
@@ -20,7 +20,6 @@
#include "common.h"
-#include "bu/parallel.h"
#include "ged.h"
#include "../ged_private.h"
@@ -33,7 +32,7 @@
int expAir_color[3];
};
-HIDDEN void
+HIDDEN void
exposed_air(const struct partition *pp,
point_t last_out_point,
point_t pt,
@@ -42,13 +41,13 @@
{
struct exp_air_context *context = (struct exp_air_context*) callback_data;
/* this shouldn't be air */
- bu_semaphore_acquire(GED_SEM_LIST);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
add_to_list(context->exposedAirList,
pp->pt_regionp->reg_name,
(char *)NULL,
pp->pt_outhit->hit_dist - pp->pt_inhit->hit_dist,
last_out_point);
- bu_semaphore_release(GED_SEM_LIST);
+ bu_semaphore_release(BU_SEM_GENERAL);
if (context->plot_exp_air) {
bu_semaphore_acquire(BU_SEM_SYSCALL);
Modified: brlcad/trunk/src/libged/check/check_gap.c
===================================================================
--- brlcad/trunk/src/libged/check/check_gap.c 2019-05-16 22:26:26 UTC (rev
73077)
+++ brlcad/trunk/src/libged/check/check_gap.c 2019-05-17 04:36:33 UTC (rev
73078)
@@ -23,7 +23,6 @@
#include <stdlib.h>
#include <string.h>
-#include "bu/parallel.h"
#include "ged.h"
#include "../ged_private.h"
@@ -41,9 +40,9 @@
{
struct gap_context *context = (struct gap_context*) callback_data;
/* we only want to report unique pairs */
- bu_semaphore_acquire(GED_SEM_LIST);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
add_to_list(context->gapList, pp->pt_regionp->reg_name,
pp->pt_back->pt_regionp->reg_name, gap_dist, pt);
- bu_semaphore_release(GED_SEM_LIST);
+ bu_semaphore_release(BU_SEM_GENERAL);
/* let's plot */
if (context->plot_gaps) {
Modified: brlcad/trunk/src/libged/check/check_overlaps.c
===================================================================
--- brlcad/trunk/src/libged/check/check_overlaps.c 2019-05-16 22:26:26 UTC
(rev 73077)
+++ brlcad/trunk/src/libged/check/check_overlaps.c 2019-05-17 04:36:33 UTC
(rev 73078)
@@ -52,6 +52,8 @@
FILE *plot_overlaps;
int overlap_color[3];
struct ged_check_plot *overlaps_overlay_plot;
+ int sem_stats;
+ int sem_lists;
};
@@ -63,9 +65,9 @@
struct overlap_list *new_op;
struct overlap_list *op;
- bu_semaphore_acquire(BU_SEM_SYSCALL);
+ bu_semaphore_acquire(callbackdata->sem_stats);
callbackdata->noverlaps++;
- bu_semaphore_release(BU_SEM_SYSCALL);
+ bu_semaphore_release(callbackdata->sem_stats);
if (!callbackdata->rpt_overlap_flag) {
bu_vls_printf(_ged_current_gedp->ged_result_str,
@@ -81,13 +83,13 @@
*/
} else {
BU_GET(new_op, struct overlap_list);
- bu_semaphore_acquire(BU_SEM_SYSCALL);
+ bu_semaphore_acquire(callbackdata->sem_stats);
for (BU_LIST_FOR(op, overlap_list, &(olist->l))) {
if ((BU_STR_EQUAL(reg1, op->reg1)) && (BU_STR_EQUAL(reg2,
op->reg2))) {
op->count++;
if (depth > op->maxdepth)
op->maxdepth = depth;
- bu_semaphore_release(BU_SEM_SYSCALL);
+ bu_semaphore_release(callbackdata->sem_stats);
bu_free((char *) new_op, "overlap list");
return;
}
@@ -111,7 +113,7 @@
new_op->maxdepth = depth;
new_op->count = 1;
BU_LIST_INSERT(&(olist->l), &(new_op->l));
- bu_semaphore_release(BU_SEM_SYSCALL);
+ bu_semaphore_release(callbackdata->sem_stats);
}
}
@@ -252,21 +254,19 @@
VJOIN1(ohit, ray->r_pt, ohitp->hit_dist, ray->r_dir);
if (context->overlaps_overlay_flag) {
- bu_semaphore_acquire(GED_SEM_WORKER);
+ bu_semaphore_acquire(context->sem_stats);
BN_ADD_VLIST(context->overlaps_overlay_plot->vbp->free_vlist_hd,
context->overlaps_overlay_plot->vhead, ihit, BN_VLIST_LINE_MOVE);
BN_ADD_VLIST(context->overlaps_overlay_plot->vbp->free_vlist_hd,
context->overlaps_overlay_plot->vhead, ohit, BN_VLIST_LINE_DRAW);
- bu_semaphore_release(GED_SEM_WORKER);
+ bu_semaphore_release(context->sem_stats);
}
- bu_semaphore_acquire(GED_SEM_LIST);
+ bu_semaphore_acquire(context->sem_lists);
check_log_overlaps(reg1->reg_name, reg2->reg_name, depth, ihit, ohit,
context);
- bu_semaphore_release(GED_SEM_LIST);
+ bu_semaphore_release(context->sem_lists);
if (context->plot_overlaps) {
- bu_semaphore_acquire(BU_SEM_SYSCALL);
pl_color(context->plot_overlaps, V3ARGS(context->overlap_color));
pdv_3line(context->plot_overlaps, ihit, ohit);
- bu_semaphore_release(BU_SEM_SYSCALL);
}
}
@@ -314,6 +314,8 @@
callbackdata.overlapList = &overlapList;
callbackdata.overlaps_overlay_flag = options->overlaps_overlay_flag;
callbackdata.overlaps_overlay_plot = &check_plot;
+ callbackdata.sem_stats = bu_semaphore_register("check_stats");
+ callbackdata.sem_lists = bu_semaphore_register("check_lists");
/* register callback */
analyze_register_overlaps_callback(state, overlap, &callbackdata);
Modified: brlcad/trunk/src/libged/check/check_unconf_air.c
===================================================================
--- brlcad/trunk/src/libged/check/check_unconf_air.c 2019-05-16 22:26:26 UTC
(rev 73077)
+++ brlcad/trunk/src/libged/check/check_unconf_air.c 2019-05-17 04:36:33 UTC
(rev 73078)
@@ -33,7 +33,7 @@
double tolerance;
};
-HIDDEN void
+HIDDEN void
unconf_air(const struct xray *ray,
const struct partition *ipart,
const struct partition *opart,
@@ -51,14 +51,14 @@
return;
}
- bu_semaphore_acquire(GED_SEM_WORKER);
-
+ bu_semaphore_acquire(BU_SEM_GENERAL);
+
add_to_list(context->unconfAirList,
ipart->pt_regionp->reg_name,
opart->pt_regionp->reg_name,
depth,
ihit);
- bu_semaphore_release(GED_SEM_WORKER);
+ bu_semaphore_release(BU_SEM_GENERAL);
if (context->plot_unconf_air) {
bu_semaphore_acquire(BU_SEM_SYSCALL);
Modified: brlcad/trunk/src/libged/gqa.c
===================================================================
--- brlcad/trunk/src/libged/gqa.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/libged/gqa.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -133,10 +133,15 @@
int v_axis; /* is being used for the U, V, or invariant vector
direction */
int i_axis;
- /* GED_SEM_WORKER protects this */
+ int sem_lists;
+ int sem_worker;
+
+ /* sem_worker protects this */
int v; /* indicates how many "grid_size" steps in the v direction
have been taken */
- /* GED_SEM_STATS protects this */
+ int sem_stats;
+
+ /* sem_stats protects this */
double *m_lenDensity;
double *m_len;
double *m_volume;
@@ -190,7 +195,7 @@
/* Access to these lists should be in sections
- * of code protected by GED_SEM_LIST
+ * of code protected by state->sem_lists
*/
/**
@@ -760,7 +765,7 @@
struct region *reg2,
struct partition *hp)
{
-
+ struct cstate *state = (struct cstate *)ap->A_STATE;
struct xray *rp = &ap->a_ray;
struct hit *ihitp = pp->pt_inhit;
struct hit *ohitp = pp->pt_outhit;
@@ -787,34 +792,30 @@
VJOIN1(ohit, rp->r_pt, ohitp->hit_dist, rp->r_dir);
if (plot_overlaps) {
- bu_semaphore_acquire(BU_SEM_SYSCALL);
pl_color(plot_overlaps, V3ARGS(overlap_color));
pdv_3line(plot_overlaps, ihit, ohit);
- bu_semaphore_release(BU_SEM_SYSCALL);
}
if (analysis_flags & ANALYSIS_PLOT_OVERLAPS) {
- bu_semaphore_acquire(GED_SEM_WORKER);
+ bu_semaphore_acquire(state->sem_worker);
BN_ADD_VLIST(ged_gqa_plot.vbp->free_vlist_hd, ged_gqa_plot.vhead, ihit,
BN_VLIST_LINE_MOVE);
BN_ADD_VLIST(ged_gqa_plot.vbp->free_vlist_hd, ged_gqa_plot.vhead, ohit,
BN_VLIST_LINE_DRAW);
- bu_semaphore_release(GED_SEM_WORKER);
+ bu_semaphore_release(state->sem_worker);
}
if (analysis_flags & ANALYSIS_OVERLAPS) {
- bu_semaphore_acquire(GED_SEM_LIST);
+ bu_semaphore_acquire(state->sem_lists);
add_unique_pair(&overlapList, reg1, reg2, depth, ihit);
- bu_semaphore_release(GED_SEM_LIST);
+ bu_semaphore_release(state->sem_lists);
if (plot_overlaps) {
- bu_semaphore_acquire(BU_SEM_SYSCALL);
pl_color(plot_overlaps, V3ARGS(overlap_color));
pdv_3line(plot_overlaps, ihit, ohit);
- bu_semaphore_release(BU_SEM_SYSCALL);
}
} else {
- bu_semaphore_acquire(GED_SEM_WORKER);
+ bu_semaphore_acquire(state->sem_worker);
bu_vls_printf(_ged_current_gedp->ged_result_str, "overlap %s %s\n",
reg1->reg_name, reg2->reg_name);
- bu_semaphore_release(GED_SEM_WORKER);
+ bu_semaphore_release(state->sem_worker);
}
/* XXX We should somehow flag the volume/weight calculations as invalid */
@@ -845,26 +846,27 @@
}
-void _gqa_exposed_air(struct partition *pp,
- point_t last_out_point,
- point_t pt,
- point_t opt)
+void _gqa_exposed_air(struct application *ap,
+ struct partition *pp,
+ point_t last_out_point,
+ point_t pt,
+ point_t opt)
{
+ struct cstate *state = (struct cstate *)ap->A_STATE;
+
/* this shouldn't be air */
- bu_semaphore_acquire(GED_SEM_LIST);
+ bu_semaphore_acquire(state->sem_lists);
add_unique_pair(&exposedAirList,
pp->pt_regionp,
(struct region *)NULL,
pp->pt_outhit->hit_dist - pp->pt_inhit->hit_dist, /* thickness */
last_out_point); /* location */
- bu_semaphore_release(GED_SEM_LIST);
+ bu_semaphore_release(state->sem_lists);
if (plot_expair) {
- bu_semaphore_acquire(BU_SEM_SYSCALL);
pl_color(plot_expair, V3ARGS(expAir_color));
pdv_3line(plot_expair, pt, opt);
- bu_semaphore_release(BU_SEM_SYSCALL);
}
}
@@ -909,10 +911,10 @@
VJOIN1(opt, ap->a_ray.r_pt, pp->pt_outhit->hit_dist, ap->a_ray.r_dir);
if (debug) {
- bu_semaphore_acquire(GED_SEM_WORKER);
+ bu_semaphore_acquire(state->sem_worker);
bu_vls_printf(_ged_current_gedp->ged_result_str, "%s %g->%g\n",
pp->pt_regionp->reg_name,
pp->pt_inhit->hit_dist, pp->pt_outhit->hit_dist);
- bu_semaphore_release(GED_SEM_WORKER);
+ bu_semaphore_release(state->sem_worker);
}
/* checking for air sticking out of the model. This is done
@@ -928,7 +930,7 @@
*/
if (pp->pt_regionp->reg_aircode &&
(air_first || gap_dist > overlap_tolerance)) {
- _gqa_exposed_air(pp, last_out_point, pt, opt);
+ _gqa_exposed_air(ap, pp, last_out_point, pt, opt);
} else {
air_first = 0;
}
@@ -945,13 +947,13 @@
if (gap_dist > overlap_tolerance) {
/* like overlaps, we only want to report unique pairs */
- bu_semaphore_acquire(GED_SEM_LIST);
+ bu_semaphore_acquire(state->sem_lists);
add_unique_pair(&gapList,
pp->pt_regionp,
pp->pt_back->pt_regionp,
gap_dist,
pt);
- bu_semaphore_release(GED_SEM_LIST);
+ bu_semaphore_release(state->sem_lists);
/* like overlaps, let's plot */
if (plot_gaps) {
@@ -958,10 +960,8 @@
vect_t gapEnd;
VJOIN1(gapEnd, pt, -gap_dist, ap->a_ray.r_dir);
- bu_semaphore_acquire(BU_SEM_SYSCALL);
pl_color(plot_gaps, V3ARGS(gap_color));
pdv_3line(plot_gaps, pt, gapEnd);
- bu_semaphore_release(BU_SEM_SYSCALL);
}
}
}
@@ -970,18 +970,18 @@
/* computing the weight of the objects */
if (analysis_flags & ANALYSIS_WEIGHTS) {
if (debug) {
- bu_semaphore_acquire(GED_SEM_WORKER);
+ bu_semaphore_acquire(state->sem_worker);
bu_vls_printf(_ged_current_gedp->ged_result_str, "Hit %s doing
weight\n", pp->pt_regionp->reg_name);
- bu_semaphore_release(GED_SEM_WORKER);
+ bu_semaphore_release(state->sem_worker);
}
/* make sure mater index is within range of densities */
if (pp->pt_regionp->reg_gmater < 0) {
- bu_semaphore_acquire(GED_SEM_WORKER);
+ bu_semaphore_acquire(state->sem_worker);
bu_vls_printf(_ged_current_gedp->ged_result_str, "density index
%d on region %s is outside of range\nSet GIFTmater on region or add entry to
density table\n",
pp->pt_regionp->reg_gmater,
pp->pt_regionp->reg_name);
- bu_semaphore_release(GED_SEM_WORKER);
+ bu_semaphore_release(state->sem_worker);
return GED_ERROR;
} else {
@@ -1029,9 +1029,9 @@
los = pp->pt_regionp->reg_los;
if (los < 1) {
- bu_semaphore_acquire(GED_SEM_WORKER);
+ bu_semaphore_acquire(state->sem_worker);
bu_vls_printf(_ged_current_gedp->ged_result_str, "bad LOS
(%d) on %s\n", los, pp->pt_regionp->reg_name);
- bu_semaphore_release(GED_SEM_WORKER);
+ bu_semaphore_release(state->sem_worker);
}
/* accumulate the total weight values */
@@ -1040,7 +1040,7 @@
prd = ((struct per_region_data *)pp->pt_regionp->reg_udata);
/* accumulate the per-region per-view weight values */
- bu_semaphore_acquire(GED_SEM_STATS);
+ bu_semaphore_acquire(state->sem_stats);
prd->r_lenDensity[state->i_axis] += val;
/* accumulate the per-object per-view weight values */
@@ -1090,7 +1090,7 @@
}
}
- bu_semaphore_release(GED_SEM_STATS);
+ bu_semaphore_release(state->sem_stats);
}
}
@@ -1099,7 +1099,7 @@
struct per_region_data *prd = ((struct per_region_data
*)pp->pt_regionp->reg_udata);
ap->A_LEN += dist; /* add to total volume */
{
- bu_semaphore_acquire(GED_SEM_STATS);
+ bu_semaphore_acquire(state->sem_stats);
/* add to region volume */
prd->r_len[state->curr_view] += dist;
@@ -1107,19 +1107,18 @@
/* add to object volume */
prd->optr->o_len[state->curr_view] += dist;
- bu_semaphore_release(GED_SEM_STATS);
+ bu_semaphore_release(state->sem_stats);
}
if (debug) {
- bu_semaphore_acquire(GED_SEM_WORKER);
+ bu_semaphore_acquire(state->sem_worker);
bu_vls_printf(_ged_current_gedp->ged_result_str, "\t\tvol hit
%s oDist:%g objVol:%g %s\n",
pp->pt_regionp->reg_name, dist,
prd->optr->o_len[state->curr_view], prd->optr->o_name);
- bu_semaphore_release(GED_SEM_WORKER);
+ bu_semaphore_release(state->sem_worker);
}
if (plot_volume) {
VJOIN1(opt, ap->a_ray.r_pt, pp->pt_outhit->hit_dist,
ap->a_ray.r_dir);
- bu_semaphore_acquire(BU_SEM_SYSCALL);
if (ap->a_user & 1) {
pl_color(plot_volume, V3ARGS(gap_color));
} else {
@@ -1127,7 +1126,6 @@
}
pdv_3line(plot_volume, pt, opt);
- bu_semaphore_release(BU_SEM_SYSCALL);
}
}
@@ -1140,19 +1138,16 @@
double d = pp->pt_outhit->hit_dist - pp->pt_inhit->hit_dist;
point_t aapt;
- bu_semaphore_acquire(GED_SEM_LIST);
+ bu_semaphore_acquire(state->sem_lists);
add_unique_pair(&adjAirList, pp->pt_back->pt_regionp,
pp->pt_regionp, 0.0, pt);
- bu_semaphore_release(GED_SEM_LIST);
+ bu_semaphore_release(state->sem_lists);
d *= 0.25;
VJOIN1(aapt, pt, d, ap->a_ray.r_dir);
- bu_semaphore_acquire(BU_SEM_SYSCALL);
pl_color(plot_adjair, V3ARGS(adjAir_color));
pdv_3line(plot_adjair, pt, aapt);
- bu_semaphore_release(BU_SEM_SYSCALL);
-
}
}
@@ -1169,7 +1164,7 @@
/* the last thing we hit was air. Make a note of that */
pp = PartHeadp->pt_back;
- _gqa_exposed_air(pp, last_out_point, pt, opt);
+ _gqa_exposed_air(ap, pp, last_out_point, pt, opt);
}
@@ -1202,7 +1197,7 @@
{
int v;
/* look for more work */
- bu_semaphore_acquire(GED_SEM_WORKER);
+ bu_semaphore_acquire(state->sem_worker);
if (state->v < state->steps[state->v_axis])
v = state->v++; /* get a row to work on */
@@ -1209,7 +1204,7 @@
else
v = 0; /* signal end of work */
- bu_semaphore_release(GED_SEM_WORKER);
+ bu_semaphore_release(state->sem_worker);
return v;
}
@@ -1255,9 +1250,9 @@
v_coord = v * gridSpacing;
if (debug) {
- bu_semaphore_acquire(GED_SEM_WORKER);
+ bu_semaphore_acquire(state->sem_worker);
bu_vls_printf(_ged_current_gedp->ged_result_str, " v = %d
v_coord=%g\n", v, v_coord);
- bu_semaphore_release(GED_SEM_WORKER);
+ bu_semaphore_release(state->sem_worker);
}
if ((v&1) || state->first) {
@@ -1271,10 +1266,10 @@
ap.a_ray.r_pt[state->i_axis] =
ap.a_rt_i->mdl_min[state->i_axis];
if (debug) {
- bu_semaphore_acquire(GED_SEM_WORKER);
+ bu_semaphore_acquire(state->sem_worker);
bu_vls_printf(_ged_current_gedp->ged_result_str, "%5g %5g
%5g -> %g %g %g\n", V3ARGS(ap.a_ray.r_pt),
V3ARGS(ap.a_ray.r_dir));
- bu_semaphore_release(GED_SEM_WORKER);
+ bu_semaphore_release(state->sem_worker);
}
ap.a_user = v;
(void)rt_shootray(&ap);
@@ -1294,10 +1289,10 @@
ap.a_ray.r_pt[state->i_axis] =
ap.a_rt_i->mdl_min[state->i_axis];
if (debug) {
- bu_semaphore_acquire(GED_SEM_WORKER);
+ bu_semaphore_acquire(state->sem_worker);
bu_vls_printf(_ged_current_gedp->ged_result_str, "%5g %5g
%5g -> %g %g %g\n", V3ARGS(ap.a_ray.r_pt),
V3ARGS(ap.a_ray.r_dir));
- bu_semaphore_release(GED_SEM_WORKER);
+ bu_semaphore_release(state->sem_worker);
}
ap.a_user = v;
(void)rt_shootray(&ap);
@@ -1307,12 +1302,13 @@
shot_cnt++;
- if (debug)
+ if (debug) {
if (u+1 < state->steps[state->u_axis]) {
- bu_semaphore_acquire(GED_SEM_WORKER);
+ bu_semaphore_acquire(state->sem_worker);
bu_vls_printf(_ged_current_gedp->ged_result_str, "
---\n");
- bu_semaphore_release(GED_SEM_WORKER);
+ bu_semaphore_release(state->sem_worker);
}
+ }
}
}
@@ -1321,9 +1317,9 @@
}
if (debug && (u == -1)) {
- bu_semaphore_acquire(GED_SEM_WORKER);
+ bu_semaphore_acquire(state->sem_worker);
bu_vls_printf(_ged_current_gedp->ged_result_str, "didn't shoot any
rays\n");
- bu_semaphore_release(GED_SEM_WORKER);
+ bu_semaphore_release(state->sem_worker);
}
/* There's nothing else left to work on in this view. It's time
@@ -1331,11 +1327,11 @@
* view and return. When all threads have been through here,
* we'll have returned to serial computation.
*/
- bu_semaphore_acquire(GED_SEM_STATS);
+ bu_semaphore_acquire(state->sem_stats);
state->shots[state->curr_view] += shot_cnt;
state->m_lenDensity[state->curr_view] += ap.A_LENDEN; /* add our
length*density value */
state->m_len[state->curr_view] += ap.A_LEN; /* add our volume value */
- bu_semaphore_release(GED_SEM_STATS);
+ bu_semaphore_release(state->sem_stats);
}
@@ -2405,6 +2401,8 @@
if (options_prep(rtip, state.span) != GED_OK) return GED_ERROR;
/* initialize some stuff */
+ state.sem_worker = bu_semaphore_register("gqa_sem_worker");
+ state.sem_stats = bu_semaphore_register("gqa_sem_stats");
state.rtip = rtip;
state.first = 1;
allocate_per_region_data(&state, start_objs, argc, argv);
Modified: brlcad/trunk/src/liboptical/photonmap.c
===================================================================
--- brlcad/trunk/src/liboptical/photonmap.c 2019-05-16 22:26:26 UTC (rev
73077)
+++ brlcad/trunk/src/liboptical/photonmap.c 2019-05-17 04:36:33 UTC (rev
73078)
@@ -1079,11 +1079,15 @@
void
BuildIrradianceCache(int pid, struct PNode *Node, struct application *ap)
{
+ static int sem_photonmap = 0;
+ if (!sem_photonmap)
+ sem_photonmap = bu_semaphore_register("sem_photonmap");
+
if (!Node)
return;
/* Determine if this pt will be used by calculating a weight */
- bu_semaphore_acquire(RT_SEM_PM);
+ bu_semaphore_acquire(sem_photonmap);
if (!Node->C) {
ICSize++;
Node->C++;
@@ -1091,10 +1095,10 @@
if (!(ICSize%(PMap[PM_GLOBAL]->MaxPhotons/8)))
bu_log(" Irradiance Cache Progress: %d%%\n",
(int)(0.5+100.0*ICSize/PMap[PM_GLOBAL]->MaxPhotons));
#endif
- bu_semaphore_release(RT_SEM_PM);
+ bu_semaphore_release(sem_photonmap);
Irradiance(pid, &Node->P, ap);
} else {
- bu_semaphore_release(RT_SEM_PM);
+ bu_semaphore_release(sem_photonmap);
}
BuildIrradianceCache(pid, Node->L, ap);
Modified: brlcad/trunk/src/librt/cache.c
===================================================================
--- brlcad/trunk/src/librt/cache.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/librt/cache.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -71,11 +71,12 @@
struct rt_cache {
char dir[MAXPATHLEN];
int read_only;
+ int semaphore;
int (*log)(const char *format, ...);
int (*debug)(const char *format, ...);
struct bu_hash_tbl *entry_hash;
};
-#define CACHE_INIT {{0}, 0, bu_log, NULL, NULL}
+#define CACHE_INIT {{0}, 0, 0, bu_log, NULL, NULL}
HIDDEN void
@@ -330,6 +331,8 @@
/* initialize database instance pointer storage */
cache->entry_hash = bu_hash_create(1024);
+ cache->semaphore = bu_semaphore_register("SEM_CACHE");
+
return 1;
}
@@ -407,17 +410,17 @@
if (!cache || !name)
return NULL;
- bu_semaphore_acquire(RT_SEM_CACHE);
+ bu_semaphore_acquire(cache->semaphore);
e = (struct rt_cache_entry *)bu_hash_get(cache->entry_hash, (const uint8_t
*)name, strlen(name));
if (e) {
- bu_semaphore_release(RT_SEM_CACHE);
+ bu_semaphore_release(cache->semaphore);
return e;
}
cache_get_objfile(cache, name, path, MAXPATHLEN);
if (!bu_file_exists(path, NULL)) {
- bu_semaphore_release(RT_SEM_CACHE);
+ bu_semaphore_release(cache->semaphore);
return NULL;
}
@@ -436,13 +439,13 @@
}
BU_PUT(e->ext, struct bu_external);
BU_PUT(e, struct rt_cache);
- bu_semaphore_release(RT_SEM_CACHE);
+ bu_semaphore_release(cache->semaphore);
return NULL;
}
e->ext->ext_buf = (uint8_t *)(e->mfp->buf);
bu_hash_set(cache->entry_hash, (const uint8_t *)name, strlen(name), e);
- bu_semaphore_release(RT_SEM_CACHE);
+ bu_semaphore_release(cache->semaphore);
return e;
}
Modified: brlcad/trunk/src/librt/db_open.c
===================================================================
--- brlcad/trunk/src/librt/db_open.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/librt/db_open.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -58,12 +58,39 @@
struct db_i *
db_open(const char *name, const char *mode)
{
+ static int sem_uses = 0;
+ extern int RT_SEM_WORKER;
+ extern int RT_SEM_RESULTS;
+ extern int RT_SEM_MODEL;
+ extern int RT_SEM_TREE0;
+ extern int RT_SEM_TREE1;
+ extern int RT_SEM_TREE2;
+ extern int RT_SEM_TREE3;
register struct db_i *dbip = DBI_NULL;
register int i;
char **argv;
- if (name == NULL) return DBI_NULL;
+ if (!sem_uses)
+ sem_uses = bu_semaphore_register("LIBRT_SEM_USES");
+ if (!RT_SEM_WORKER)
+ RT_SEM_WORKER = bu_semaphore_register("RT_SEM_WORKER");
+ if (!RT_SEM_RESULTS)
+ RT_SEM_RESULTS = bu_semaphore_register("RT_SEM_RESULTS");
+ if (!RT_SEM_MODEL)
+ RT_SEM_MODEL = bu_semaphore_register("RT_SEM_MODEL");
+ if (!RT_SEM_TREE0)
+ RT_SEM_TREE0 = bu_semaphore_register("RT_SEM_TREE0");
+ if (!RT_SEM_TREE1)
+ RT_SEM_TREE1 = bu_semaphore_register("RT_SEM_TREE1");
+ if (!RT_SEM_TREE2)
+ RT_SEM_TREE2 = bu_semaphore_register("RT_SEM_TREE2");
+ if (!RT_SEM_TREE3)
+ RT_SEM_TREE3 = bu_semaphore_register("RT_SEM_TREE3");
+
+ if (name == NULL)
+ return DBI_NULL;
+
if (RT_G_DEBUG & DEBUG_DB) {
bu_log("db_open(%s, %s)\n", name, mode);
}
@@ -85,9 +112,9 @@
if (mfp->apbuf) {
dbip = (struct db_i *)mfp->apbuf;
RT_CK_DBI(dbip);
- bu_semaphore_acquire(BU_SEM_LISTS);
+ bu_semaphore_acquire(sem_uses);
dbip->dbi_uses++;
- bu_semaphore_release(BU_SEM_LISTS);
+ bu_semaphore_release(sem_uses);
/*
* decrement the mapped file reference counter by 1,
@@ -286,6 +313,9 @@
{
register int i;
register struct directory *dp, *nextdp;
+ static int sem_uses = 0;
+ if (!sem_uses)
+ sem_uses = bu_semaphore_register("LIBRT_SEM_USES");
if (!dbip)
return;
@@ -294,13 +324,13 @@
if (RT_G_DEBUG&DEBUG_DB) bu_log("db_close(%s) %p uses=%d\n",
dbip->dbi_filename, (void *)dbip,
dbip->dbi_uses);
- bu_semaphore_acquire(BU_SEM_LISTS);
+ bu_semaphore_acquire(sem_uses);
if ((--dbip->dbi_uses) > 0) {
- bu_semaphore_release(BU_SEM_LISTS);
+ bu_semaphore_release(sem_uses);
/* others are still using this database */
return;
}
- bu_semaphore_release(BU_SEM_LISTS);
+ bu_semaphore_release(sem_uses);
/* ready to free the database -- use count is now zero */
@@ -410,11 +440,15 @@
struct db_i *
db_clone_dbi(struct db_i *dbip, long int *client)
{
+ static int sem_uses = 0;
+ if (!sem_uses)
+ sem_uses = bu_semaphore_register("LIBRT_SEM_USES");
+
RT_CK_DBI(dbip);
- bu_semaphore_acquire(BU_SEM_LISTS);
+ bu_semaphore_acquire(sem_uses);
dbip->dbi_uses++;
- bu_semaphore_release(BU_SEM_LISTS);
+ bu_semaphore_release(sem_uses);
if (client) {
bu_ptbl_ins_unique(&dbip->dbi_clients, client);
}
Modified: brlcad/trunk/src/librt/prep.c
===================================================================
--- brlcad/trunk/src/librt/prep.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/librt/prep.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -50,6 +50,15 @@
HIDDEN void rt_solid_bitfinder(register union tree *treep, struct region
*regp, struct resource *resp);
+int RT_SEM_WORKER = 0;
+int RT_SEM_RESULTS = 0;
+int RT_SEM_MODEL = 0;
+int RT_SEM_TREE0 = 0;
+int RT_SEM_TREE1 = 0;
+int RT_SEM_TREE2 = 0;
+int RT_SEM_TREE3 = 0;
+
+
/* XXX Need rt_init_rtg(), rt_clean_rtg() */
/**
@@ -825,6 +834,21 @@
BU_ASSERT(cpu_num >= 0);
BU_ASSERT(cpu_num < MAX_PSW);
+ if (!RT_SEM_WORKER)
+ RT_SEM_WORKER = bu_semaphore_register("RT_SEM_WORKER");
+ if (!RT_SEM_RESULTS)
+ RT_SEM_RESULTS = bu_semaphore_register("RT_SEM_RESULTS");
+ if (!RT_SEM_MODEL)
+ RT_SEM_MODEL = bu_semaphore_register("RT_SEM_MODEL");
+ if (!RT_SEM_TREE0)
+ RT_SEM_TREE0 = bu_semaphore_register("RT_SEM_TREE0");
+ if (!RT_SEM_TREE1)
+ RT_SEM_TREE1 = bu_semaphore_register("RT_SEM_TREE1");
+ if (!RT_SEM_TREE2)
+ RT_SEM_TREE2 = bu_semaphore_register("RT_SEM_TREE2");
+ if (!RT_SEM_TREE3)
+ RT_SEM_TREE3 = bu_semaphore_register("RT_SEM_TREE3");
+
if (rtip)
RT_CK_RTI(rtip);
Modified: brlcad/trunk/src/librt/primitives/brep/brep.cpp
===================================================================
--- brlcad/trunk/src/librt/primitives/brep/brep.cpp 2019-05-16 22:26:26 UTC
(rev 73077)
+++ brlcad/trunk/src/librt/primitives/brep/brep.cpp 2019-05-17 04:36:33 UTC
(rev 73078)
@@ -552,7 +552,7 @@
index = -1;
/* figure out which face to work on next */
- bu_semaphore_acquire(BU_SEM_LISTS);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
for (size_t i = 0; i < faceCount; i++) {
if (bbbp->faces[i] == NULL) {
index = i;
@@ -560,7 +560,7 @@
break;
}
}
- bu_semaphore_release(BU_SEM_LISTS);
+ bu_semaphore_release(BU_SEM_GENERAL);
if (index != -1) {
/* bu_log("thread %d: preparing face %d of %d\n", cpu, index+1,
faceCount); */
Modified: brlcad/trunk/src/librt/tree.c
===================================================================
--- brlcad/trunk/src/librt/tree.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/librt/tree.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -420,9 +420,9 @@
/* Enter an exclusive critical section to protect nsolids.
* nsolids++ needs to be locked to a SINGLE thread
*/
- bu_semaphore_acquire(RT_SEM_STATS);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
stp->st_bit = rtip->nsolids++;
- bu_semaphore_release(RT_SEM_STATS);
+ bu_semaphore_release(BU_SEM_GENERAL);
/*
* Fill in the last little bit of the structure in full parallel
Modified: brlcad/trunk/src/proc-db/pix2g.c
===================================================================
--- brlcad/trunk/src/proc-db/pix2g.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/proc-db/pix2g.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -37,8 +37,6 @@
/* workers acquire semaphore number 0 on smp machines */
-#define P2G_WORKER RT_SEM_LAST
-#define P2G_INIT_COUNT P2G_WORKER+1
#define MAXSIZE 256
int done=0;
int ncpu=1;
@@ -86,10 +84,10 @@
struct wmember scanlineList;
BU_LIST_INIT(&scanlineList.l);
- bu_semaphore_acquire(P2G_WORKER);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
i=nextAvailableRow;
nextAvailableRow++;
- bu_semaphore_release(P2G_WORKER);
+ bu_semaphore_release(BU_SEM_GENERAL);
if (i >= height) {
break;
@@ -125,9 +123,9 @@
* of the regions will use it.
***
sprintf(solidName, "%dx%d.s", i+1, j+1);
- bu_semaphore_acquire(P2G_WORKER);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
mk_sph(db_fp, solidName, p1, objectSize/2.0);
- bu_semaphore_release(P2G_WORKER);
+ bu_semaphore_release(BU_SEM_GENERAL);
*/
/* make the region */
@@ -145,9 +143,9 @@
MAT_IDN(matrix);
MAT_DELTAS(matrix, p1[0], p1[1], 0.0);
- bu_semaphore_acquire(P2G_WORKER);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
mk_lcomb(db_fp, scratch, &wm_hd, is_region, NULL, NULL, rgb, 0);
- bu_semaphore_release(P2G_WORKER);
+ bu_semaphore_release(BU_SEM_GENERAL);
mk_addmember(scratch, &scanlineList.l, matrix, WMOP_UNION);
}
@@ -154,9 +152,9 @@
/* write out a combination for each scanline */
sprintf(scratch, "%d.c", i+1);
- bu_semaphore_acquire(P2G_WORKER);
+ bu_semaphore_acquire(BU_SEM_GENERAL);
mk_lcomb(db_fp, scratch, &scanlineList, 0, NULL, NULL, NULL, 0);
- bu_semaphore_release(P2G_WORKER);
+ bu_semaphore_release(BU_SEM_GENERAL);
/* all threads keep track of the scan line (in case they get to the end
first */
sprintf(scratch, "%d.c", i+1);
Modified: brlcad/trunk/src/rt/worker.c
===================================================================
--- brlcad/trunk/src/rt/worker.c 2019-05-16 22:26:26 UTC (rev 73077)
+++ brlcad/trunk/src/rt/worker.c 2019-05-17 04:36:33 UTC (rev 73078)
@@ -431,10 +431,10 @@
pixelTime = rt_get_timer(NULL,NULL); /* FIXME: needs to use
bu_gettime() */
/* bu_log("PixelTime = %lf X:%d Y:%d\n", pixelTime, a.a_x, a.a_y); */
- bu_semaphore_acquire(RT_SEM_LAST-2);
+ bu_semaphore_acquire(RT_SEM_RESULTS);
timeTable = timeTable_init(width, height);
timeTable_input(a.a_x, a.a_y, pixelTime, timeTable);
- bu_semaphore_release(RT_SEM_LAST-2);
+ bu_semaphore_release(RT_SEM_RESULTS);
}
/* we're done */
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits