Discussion:
[brlcad-devel] [brlcad-commits] SF.net SVN: brlcad:[69742] brlcad/trunk/src/external/CREO/util.cpp
Christopher Sean Morrison
2017-05-03 01:26:08 UTC
Permalink
Cliff,

I think we already have this filed in TODO. The problem is that Bu malloc and logging use the same semaphore. Since your logging callback uses VLS, which uses malloc, it ends up deadlocked.

Workaround is to either not call Bu functions in the callback or not use Bu logging. Fix is really simple, make Bu use different semaphores.

Cheers!
Sean
Revision: 69742
http://sourceforge.net/p/brlcad/code/69742
Author: starseeker
Date: 2017-05-02 23:16:03 +0000 (Tue, 02 May 2017)
-----------
bu_log and CREO seem to be arguing about locking somehow or other...
--------------
brlcad/trunk/src/external/CREO/util.cpp
Modified: brlcad/trunk/src/external/CREO/util.cpp
===================================================================
--- brlcad/trunk/src/external/CREO/util.cpp 2017-05-02 21:28:17 UTC (rev 69741)
+++ brlcad/trunk/src/external/CREO/util.cpp 2017-05-02 23:16:03 UTC (rev 69742)
@@ -25,25 +25,41 @@
#include <regex.h>
#include "creo-brl.h"
-int creo_logging_opts(void *data, void *vstr){
+extern "C" void
+creo_log(struct creo_conv_info *cinfo, int msg_type, const char *fmt, ...) {
+ /* NOTE - need creo specific semaphore lock for this if it's going to be used
+ * in multi-threading situations... - probably can't use libbu's logging safely */
+
+ /* CREO gui */
+ ProFileName msgfil = {'\0'};
+ ProStringToWstring(msgfil, CREO_BRL_MSG_FILE);
+
+ /* Can't do nested variable argument functions, so printf the message here */
+ va_list ap;
+ char msg[CREO_MSG_MAX];
+ va_start(ap, fmt);
+ vsprintf(msg, fmt, ap);
+ va_end(ap);
+
+ /* Set the type and hooks, then call libbu */
+ if (cinfo && msg_type != MSG_STATUS) {
+ cinfo->curr_msg_type = msg_type;
struct bu_vls msg = BU_VLS_INIT_ZERO;
- struct creo_conv_info *cinfo = (struct creo_conv_info *)data;
- const char *str = (const char *)vstr;
- if (cinfo->logger_type == LOGGER_TYPE_NONE) return 0;
+ if (cinfo->logger_type == LOGGER_TYPE_NONE) return;
switch (cinfo->curr_msg_type) {
- bu_vls_sprintf(&msg, "FAILURE: %s", str);
+ bu_vls_sprintf(&msg, "FAILURE: %s", msg);
break;
- bu_vls_sprintf(&msg, "SUCCESS: %s", str);
+ bu_vls_sprintf(&msg, "SUCCESS: %s", msg);
break;
- bu_vls_sprintf(&msg, "DEBUG: %s", str);
+ bu_vls_sprintf(&msg, "DEBUG: %s", msg);
break;
- bu_vls_sprintf(&msg, "%s", str);
+ bu_vls_sprintf(&msg, "%s", msg);
break;
}
@@ -56,39 +72,8 @@
fprintf(cinfo->logger, "%s", bu_vls_addr(&msg));
fflush(cinfo->logger);
}
- if (cinfo->print_to_console) {
- if (LIKELY(stderr != NULL)) {
- fprintf(stderr, "%s", bu_vls_addr(&msg));
- fflush(stderr);
- }
- }
}
bu_vls_free(&msg);
- return 0;
-}
-
-extern "C" void
-creo_log(struct creo_conv_info *cinfo, int msg_type, const char *fmt, ...) {
- /* NOTE - need creo specific semaphore lock for this if it's going to be used
- * in multi-threading situations... - probably can't use libbu's logging safely */
-
- /* CREO gui */
- ProFileName msgfil = {'\0'};
- ProStringToWstring(msgfil, CREO_BRL_MSG_FILE);
-
- /* Can't do nested variable argument functions, so printf the message here */
- va_list ap;
- char msg[CREO_MSG_MAX];
- va_start(ap, fmt);
- vsprintf(msg, fmt, ap);
- va_end(ap);
-
- /* Set the type and hooks, then call libbu */
- if (cinfo && msg_type != MSG_STATUS) {
- cinfo->curr_msg_type = msg_type;
- bu_log_add_hook(creo_logging_opts, (void *)cinfo);
- bu_log("%s", msg);
- bu_log_delete_hook(creo_logging_opts, (void *)cinfo);
}
if (msg_type == MSG_STATUS) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
BRL-CAD Source Commits mailing list
https://lists.sourceforge.net/lists/listinfo/brlcad-commits
Loading...