/*
Bacula® - The Network Backup Solution
- Copyright (C) 2008-2008 Free Software Foundation Europe e.V.
+ Copyright (C) 2008-2009 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
}
void _dump(FILE *fp) {
- fprintf(fp, "threadid=0x%x max=%i current=%i\n", (int)thread_id, max, current);
+ fprintf(fp, "threadid=%p max=%i current=%i\n",
+ (void *)thread_id, max, current);
for(int i=0; i<=current; i++) {
- fprintf(fp, " lock=%p state=%c %s:%i\n",
- lock_list[i].lock, lock_list[i].state,
- lock_list[i].file, lock_list[i].line);
- }
+ fprintf(fp, " lock=%p state=%s %s:%i\n",
+ lock_list[i].lock,
+ (lock_list[i].state=='W')?"Wanted ":"Granted",
+ lock_list[i].file, lock_list[i].line);
+ }
}
void dump(FILE *fp) {
pthread_once_t key_lmgr_once = PTHREAD_ONCE_INIT;
static pthread_key_t lmgr_key; /* used to get lgmr_thread_t object */
-static dlist *global_mgr=NULL; /* used to store all lgmr_thread_t objects */
+static dlist *global_mgr = NULL; /* used to store all lgmr_thread_t objects */
static pthread_mutex_t lmgr_global_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_t undertaker;
/*
* !!! WARNING !!!
- * Use this function only after a fatal signal
- * We don't use any lock to display information
+ * Use this function is used only after a fatal signal
+ * We don't use locking to display the information
*/
void dbg_print_lock(FILE *fp)
{
}
/* This object is used when LMGR is not initialized */
-lmgr_dummy_thread_t dummy_lmgr;
+static lmgr_dummy_thread_t dummy_lmgr;
/*
* Retrieve the lmgr_thread_t object from the stack
lmgr_thread_t *n=NULL;
global_mgr = New(dlist(n, &n->link));
- if (pthread_create(&undertaker, NULL, check_deadlock, NULL) != 0) {
+ status = pthread_create(&undertaker, NULL, check_deadlock, NULL);
+ if (status != 0) {
berrno be;
Pmsg1(000, _("pthread_create failed: ERR=%s\n"),
be.bstrerror(status));
{
dlist *temp;
+ if (!global_mgr) {
+ return;
+ }
pthread_cancel(undertaker);
lmgr_cleanup_thread();
pthread_mutex_lock(&lmgr_global_mutex);
{
temp = global_mgr;
- global_mgr=NULL;
+ global_mgr = NULL;
delete temp;
}
pthread_mutex_unlock(&lmgr_global_mutex);
/* TODO: check this
*/
int lmgr_cond_wait(pthread_cond_t *cond,
- pthread_mutex_t *mutex)
+ pthread_mutex_t *mutex,
+ const char *file, int line)
{
int ret;
lmgr_thread_t *self = lmgr_get_thread_info();
- self->do_V(mutex);
+ self->do_V(mutex, file, line);
ret = pthread_cond_wait(cond, mutex);
- self->pre_P(mutex);
+ self->pre_P(mutex, file, line);
self->post_P();
return ret;
}
* pthread_mutex_lock(m);
* lmgr_post_lock(m);
*/
-void lmgr_pre_lock(void *m)
+void lmgr_pre_lock(void *m, const char *file, int line)
{
lmgr_thread_t *self = lmgr_get_thread_info();
- self->pre_P(m);
+ self->pre_P(m, file, line);
}
/*
/*
* Do directly pre_P and post_P (used by trylock)
*/
-void lmgr_do_lock(void *m)
+void lmgr_do_lock(void *m, const char *file, int line)
{
lmgr_thread_t *self = lmgr_get_thread_info();
- self->pre_P(m);
+ self->pre_P(m, file, line);
self->post_P();
}
const pthread_attr_t *attr,
void *(*start_routine)(void*), void *arg)
{
+ /* lmgr should be active (lmgr_init_thread() call in main()) */
+ ASSERT(lmgr_is_active());
/* Will be freed by the child */
lmgr_thread_arg_t *a = (lmgr_thread_arg_t*) malloc(sizeof(lmgr_thread_arg_t));
a->start_routine = start_routine;
a->arg = arg;
- return pthread_create(thread, attr, lmgr_thread_launcher, a);
+ return pthread_create(thread, attr, lmgr_thread_launcher, a);
}
#else /* _USE_LOCKMGR */
/*
* !!! WARNING !!!
- * Use this function only after a fatal signal
- * We don't use any lock to display information
+ * Use this function is used only after a fatal signal
+ * We don't use locking to display information
*/
void dbg_print_lock(FILE *fp)
{