aboutsummaryrefslogtreecommitdiffstats
path: root/libibex/ibex_block.c
diff options
context:
space:
mode:
author1 <NotZed@Ximian.com>2001-11-01 03:58:02 +0800
committerMichael Zucci <zucchi@src.gnome.org>2001-11-01 03:58:02 +0800
commitb40eb5b8a47737304a6df0bb379b3a6ed83b062a (patch)
treed999678a9375dfa72d8ad2cb116ee1fff3a21e24 /libibex/ibex_block.c
parent72ab189eac80cff19d8debdf524327ff9dd1a1e2 (diff)
downloadgsoc2013-evolution-b40eb5b8a47737304a6df0bb379b3a6ed83b062a.tar.gz
gsoc2013-evolution-b40eb5b8a47737304a6df0bb379b3a6ed83b062a.tar.zst
gsoc2013-evolution-b40eb5b8a47737304a6df0bb379b3a6ed83b062a.zip
Added a trylock, used by ibex_use.
2001-10-31 <NotZed@Ximian.com> * ibex_internal.h (IBEX_TRYLOCK): Added a trylock, used by ibex_use. * ibex_block.c (ibex_use): Do to a trylock on the ibex we're checking to close, as it might be locked elsewhere in an obivously simple deadlock. svn path=/trunk/; revision=14547
Diffstat (limited to 'libibex/ibex_block.c')
-rw-r--r--libibex/ibex_block.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/libibex/ibex_block.c b/libibex/ibex_block.c
index d8dade7986..a6f810d4ae 100644
--- a/libibex/ibex_block.c
+++ b/libibex/ibex_block.c
@@ -35,7 +35,7 @@ static int ibex_open_threshold = IBEX_OPEN_THRESHOLD;
#ifdef ENABLE_THREADS
#include <pthread.h>
static pthread_mutex_t ibex_list_lock = PTHREAD_MUTEX_INITIALIZER;
-int ibex_opened; /* count of actually opened ibexe's */
+static int ibex_opened; /* count of actually opened ibexe's */
#define IBEX_LIST_LOCK(ib) (pthread_mutex_lock(&ibex_list_lock))
#define IBEX_LIST_UNLOCK(ib) (pthread_mutex_unlock(&ibex_list_lock))
#else
@@ -89,27 +89,19 @@ static void ibex_use(ibex *ib)
/* check for other ibex's we can close now to not over-use fd's.
we can't do this first for locking issues */
- if (ibex_opened > ibex_open_threshold) {
- wb = (ibex *)ibex_list.head;
- wn = wb->next;
- while (wn) {
- if (wb != ib) {
- IBEX_LOCK(wb);
- if (wb->usecount == 0 && wb->blocks != NULL) {
- o(printf("Forcing close of obex '%s', total = %d\n", wb->name, ibex_opened-1));
- close_backend(wb);
- IBEX_UNLOCK(wb);
- /* optimise the next scan? */
- /*ibex_list_remove((struct _listnode *)wb);
- ibex_list_addtail(&ibex_list, (struct _listnode *)wb);*/
- ibex_opened--;
- break;
- }
- IBEX_UNLOCK(wb);
+ wb = (ibex *)ibex_list.head;
+ wn = wb->next;
+ while (wn && ibex_opened > ibex_open_threshold) {
+ if (wb != ib && IBEX_TRYLOCK(wb) == 0) {
+ if (wb->usecount == 0 && wb->blocks != NULL) {
+ o(printf("Forcing close of obex '%s', total = %d\n", wb->name, ibex_opened-1));
+ close_backend(wb);
+ ibex_opened--;
}
- wb = wn;
- wn = wn->next;
+ IBEX_UNLOCK(wb);
}
+ wb = wn;
+ wn = wn->next;
}
IBEX_LIST_UNLOCK(ib);