Made Xorriso_process_msg_queues() thread-safe

This commit is contained in:
2012-09-13 13:09:54 +00:00
parent a2507830fb
commit cce834f76f
6 changed files with 220 additions and 62 deletions

View File

@ -470,8 +470,12 @@ cannot:;
int Xorriso_process_msg_queues(struct XorrisO *xorriso, int flag)
{
int ret, error_code= 0, os_errno= 0, count= 0, pass, imgid, tunneled;
int name_prefix_code, locked= 0, uret;
char severity[80];
int name_prefix_code;
char severity[80], *text= NULL;
#ifdef Xorriso_fetch_with_msg_queueS
int locked= 0, uret;
#endif
#ifdef Xorriso_with_libjtE
char *msg;
@ -481,26 +485,35 @@ int Xorriso_process_msg_queues(struct XorrisO *xorriso, int flag)
ret= 1; goto ex;
}
#ifdef Xorriso_fetch_with_msg_queueS
Xorriso_alloc_meM(text, char, sizeof(xorriso->info_text));
ret= pthread_mutex_lock(&(xorriso->lib_msg_queue_lock));
if(ret != 0) {
Xorriso_msgs_submit(xorriso, 0,
"Cannot aquire mutex lock for processing library message queues",
errno, "FATAL", 0);
ret= -1; goto ex;
}
locked= 1;
ret, "FATAL", 0);
} else
locked= 1;
#else /* Xorriso_fetch_with_msg_queueS */
text= xorriso->info_text;
#endif /* ! Xorriso_fetch_with_msg_queueS */
for(pass= 0; pass< 3; pass++) {
while(1) {
tunneled= 0;
if(pass==0) {
ret= 0;
#ifdef Xorriso_with_libjtE
if(xorriso->libjte_handle != NULL) {
msg= libjte_get_next_message(xorriso->libjte_handle);
if(msg != NULL) {
sprintf(xorriso->info_text, "%1.4095s", msg);
sprintf(text, "%1.4095s", msg);
free(msg);
strcpy(severity, "NOTE");
error_code= 0;
@ -511,11 +524,9 @@ int Xorriso_process_msg_queues(struct XorrisO *xorriso, int flag)
#endif /* Xorriso_with_libjtE */
} else if(pass==1)
ret= iso_obtain_msgs("ALL", &error_code, &imgid,
xorriso->info_text, severity);
ret= iso_obtain_msgs("ALL", &error_code, &imgid, text, severity);
else {
ret= burn_msgs_obtain("ALL", &error_code, xorriso->info_text, &os_errno,
severity);
ret= burn_msgs_obtain("ALL", &error_code, text, &os_errno, severity);
if((error_code>=0x00030000 && error_code<0x00040000) ||
(error_code>=0x00050000 && error_code<0x00060000))
tunneled= -1; /* "libisofs:" */
@ -538,28 +549,44 @@ int Xorriso_process_msg_queues(struct XorrisO *xorriso, int flag)
name_prefix_code= 0;
else
name_prefix_code= pass + tunneled;
Xorriso_msgs_submit(xorriso, error_code, xorriso->info_text, os_errno,
Xorriso_msgs_submit(xorriso, error_code, text, os_errno,
severity, name_prefix_code << 2);
count++;
}
}
if(xorriso->library_msg_direct_print && count>0) {
sprintf(xorriso->info_text," (%d library messages repeated by xorriso)\n",
count);
sprintf(text," (%d library messages repeated by xorriso)\n", count);
#ifdef Xorriso_fetch_with_msg_queueS
Xorriso_msgs_submit(xorriso, 0, text, 0, "NOTE", 256);
#else /* Xorriso_fetch_with_msg_queueS */
Xorriso_info(xorriso, 0);
#endif /* Xorriso_fetch_with_msg_queueS */
}
ret= 1;
ex:;
#ifdef Xorriso_fetch_with_msg_queueS
if(locked) {
uret= pthread_mutex_unlock(&(xorriso->lib_msg_queue_lock));
if(uret != 0) {
Xorriso_msgs_submit(xorriso, 0,
"Cannot release mutex lock for processing library message queues",
errno, "FATAL", 0);
uret, "FATAL", 0);
ret= -1;
}
}
return(1);
Xorriso_free_meM(text);
#endif /* Xorriso_fetch_with_msg_queueS */
return(ret);
}