Equipped libdax_msgs with reference counter. Completed its mutex protection.

ZeroFourZero
Thomas Schmitt 15 years ago
parent f379a2c91a
commit 361a110274
  1. 2
      cdrskin/cdrskin_timestamp.h
  2. 12
      libburn/init.c
  3. 5
      libburn/libburn.h
  4. 81
      libburn/libdax_msgs.c
  5. 23
      libburn/libdax_msgs.h

@ -1 +1 @@
#define Cdrskin_timestamP "2007.09.15.172141"
#define Cdrskin_timestamP "2007.09.15.204320"

@ -25,8 +25,6 @@
#include "libdax_msgs.h"
struct libdax_msgs *libdax_messenger= NULL;
static int libdax_messenger_is_own = 1;
int burn_running = 0;
@ -309,10 +307,12 @@ void burn_allow_untested_profiles(int yes)
/* ts A70915 : API */
int burn_set_messenger(void *messenger)
{
if (libdax_messenger_is_own)
libdax_msgs_destroy(&libdax_messenger, 0);
libdax_messenger = (struct libdax_msgs *) messenger;
libdax_messenger_is_own = 0;
struct libdax_msgs *pt;
if (libdax_msgs_refer(&pt, messenger, 0) <= 0)
return 0;
libdax_msgs_destroy(&libdax_messenger, 0);
libdax_messenger = (struct libdax_msgs *) pt;
return 1;
}

@ -1877,9 +1877,8 @@ int burn_msgs_obtain(char *minimum_severity,
/* ts A70915 */
/** Replace the messenger object handle of libburn by a compatible handle
obtained from a related library. The own message object gets destroyed,
so it is IMPORTANT to shut down libburn BEFORE the library which provides
the messenger object. See also: libisofs, API function iso_get_messenger().
obtained from a related library.
See also: libisofs, API function iso_get_messenger().
@param messenger The foreign but compatible message handle.
@return 1 : success, <=0 : failure
*/

@ -138,6 +138,7 @@ int libdax_msgs_new(struct libdax_msgs **m, int flag)
(*m)= o= (struct libdax_msgs *) malloc(sizeof(struct libdax_msgs));
if(o==NULL)
return(-1);
o->refcount= 1;
o->oldest= NULL;
o->youngest= NULL;
o->count= 0;
@ -153,6 +154,36 @@ int libdax_msgs_new(struct libdax_msgs **m, int flag)
}
static int libdax_msgs_lock(struct libdax_msgs *m, int flag)
{
#ifndef LIBDAX_MSGS_SINGLE_THREADED
int ret;
ret= pthread_mutex_lock(&(m->lock_mutex));
if(ret!=0)
return(0);
#endif
return(1);
}
static int libdax_msgs_unlock(struct libdax_msgs *m, int flag)
{
#ifndef LIBDAX_MSGS_SINGLE_THREADED
int ret;
ret= pthread_mutex_unlock(&(m->lock_mutex));
if(ret!=0)
return(0);
#endif
return(1);
}
int libdax_msgs_destroy(struct libdax_msgs **m, int flag)
{
struct libdax_msgs *o;
@ -161,6 +192,14 @@ int libdax_msgs_destroy(struct libdax_msgs **m, int flag)
o= *m;
if(o==NULL)
return(0);
if(o->refcount > 1) {
if(libdax_msgs_lock(*m,0)<=0)
return(-1);
o->refcount--;
libdax_msgs_unlock(*m,0);
*m= NULL;
return(1);
}
#ifndef LIBDAX_MSGS_SINGLE_THREADED
if(pthread_mutex_destroy(&(o->lock_mutex))!=0) {
@ -179,43 +218,27 @@ int libdax_msgs_destroy(struct libdax_msgs **m, int flag)
}
int libdax_msgs_set_severities(struct libdax_msgs *m, int queue_severity,
int print_severity, char *print_id, int flag)
int libdax_msgs_refer(struct libdax_msgs **pt, struct libdax_msgs *m, int flag)
{
m->queue_severity= queue_severity;
m->print_severity= print_severity;
strncpy(m->print_id,print_id,80);
m->print_id[80]= 0;
return(1);
}
static int libdax_msgs_lock(struct libdax_msgs *m, int flag)
{
#ifndef LIBDAX_MSGS_SINGLE_THREADED
int ret;
ret= pthread_mutex_lock(&(m->lock_mutex));
if(ret!=0)
if(libdax_msgs_lock(m,0)<=0)
return(0);
#endif
m->refcount++;
*pt= m;
libdax_msgs_unlock(m,0);
return(1);
}
static int libdax_msgs_unlock(struct libdax_msgs *m, int flag)
int libdax_msgs_set_severities(struct libdax_msgs *m, int queue_severity,
int print_severity, char *print_id, int flag)
{
#ifndef LIBDAX_MSGS_SINGLE_THREADED
int ret;
ret= pthread_mutex_unlock(&(m->lock_mutex));
if(ret!=0)
if(libdax_msgs_lock(m,0)<=0)
return(0);
#endif
m->queue_severity= queue_severity;
m->print_severity= print_severity;
strncpy(m->print_id,print_id,80);
m->print_id[80]= 0;
libdax_msgs_unlock(m,0);
return(1);
}

@ -43,6 +43,8 @@ struct libdax_msgs_item {
struct libdax_msgs {
int refcount;
struct libdax_msgs_item *oldest;
struct libdax_msgs_item *youngest;
int count;
@ -176,7 +178,8 @@ struct libdax_msgs_item;
/* Calls initiated from inside the direct owner (e.g. from libburn) */
/** Create new empty message handling facility with queue.
/** Create new empty message handling facility with queue and issue a first
official reference to it.
@param flag Bitfield for control purposes (unused yet, submit 0)
@return >0 success, <=0 failure
*/
@ -185,12 +188,28 @@ int libdax_msgs_new(struct libdax_msgs **m, int flag);
/** Destroy a message handling facility and all its eventual messages.
The submitted pointer gets set to NULL.
Actually only the last destroy call of all offical references to the object
will really dispose it. All others just decrement the reference counter.
Call this function only with official reference pointers obtained by
libdax_msgs_new() or libdax_msgs_refer(), and only once per such pointer.
@param flag Bitfield for control purposes (unused yet, submit 0)
@return 1 for success, 0 for pointer to NULL
@return 1 for success, 0 for pointer to NULL, -1 for fatal error
*/
int libdax_msgs_destroy(struct libdax_msgs **m, int flag);
/** Create an official reference to an existing libdax_msgs object. The
references keep the object alive at least until it is released by
a matching number of destroy calls. So each reference MUST be revoked
by exactly one call to libdax_msgs_destroy().
@param pt The pointer to be set and registered
@param m A pointer to the existing object
@param flag Bitfield for control purposes (unused yet, submit 0)
@return 1 for success, 0 for failure
*/
int libdax_msgs_refer(struct libdax_msgs **pt, struct libdax_msgs *o, int flag);
/** Submit a message to a message handling facility.
@param driveno program specific drive number. Use -1 if no number is known.
@param error_code Unique error code. Use only registered codes. See below.

Loading…
Cancel
Save