8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 21:23:04 +01:00

Threading cleanup. More to follow.

This commit is contained in:
dimitr 2006-04-30 17:03:26 +00:00
parent 4c06b5a5c5
commit 5331015d9b
4 changed files with 10 additions and 55 deletions

View File

@ -73,14 +73,8 @@ bool DLS_get_temp_space(ULONG size, sort_work_file* sfb)
mutexed_dir_list* ptr = DLS_get_access(); mutexed_dir_list* ptr = DLS_get_access();
#ifdef V4_THREADING Firebird::MutexLockGuard guard(ptr->mdls_mutex);
if (!ptr->mdls_mutex_init) {
V4_MUTEX_INIT(ptr->mdls_mutex);
ptr->mdls_mutex_init = true;
}
V4_MUTEX_LOCK(ptr->mdls_mutex);
#endif
if (!sfb->sfb_dls) { if (!sfb->sfb_dls) {
/* allocate temp. space starting search from the begining of the dir_list */ /* allocate temp. space starting search from the begining of the dir_list */
for (sfb->sfb_dls = ptr->mdls_dls; for (sfb->sfb_dls = ptr->mdls_dls;
@ -101,11 +95,8 @@ bool DLS_get_temp_space(ULONG size, sort_work_file* sfb)
result = true; result = true;
} }
} }
#ifdef V4_THREADING
V4_MUTEX_UNLOCK(ptr->mdls_mutex);
#endif
return (result); return result;
} }
@ -123,18 +114,12 @@ void DLS_put_temp_space(sort_work_file* sfb)
**************************************/ **************************************/
if (sfb && sfb->sfb_dls) { if (sfb && sfb->sfb_dls) {
mutexed_dir_list* ptr = DLS_get_access(); mutexed_dir_list* ptr = DLS_get_access();
#ifdef V4_THREADING Firebird::MutexLockGuard guard(ptr->mdls_mutex);
fb_assert(ptr->mdls_mutex_init);
V4_MUTEX_LOCK(ptr->mdls_mutex);
#endif
fb_assert(sfb->sfb_dls->dls_inuse >= sfb->sfb_file_size); fb_assert(sfb->sfb_dls->dls_inuse >= sfb->sfb_file_size);
if (sfb->sfb_dls->dls_inuse > sfb->sfb_file_size) if (sfb->sfb_dls->dls_inuse > sfb->sfb_file_size)
sfb->sfb_dls->dls_inuse -= sfb->sfb_file_size; sfb->sfb_dls->dls_inuse -= sfb->sfb_file_size;
else else
sfb->sfb_dls->dls_inuse = 0; sfb->sfb_dls->dls_inuse = 0;
#ifdef V4_THREADING
V4_MUTEX_UNLOCK(ptr->mdls_mutex);
#endif
} }
} }
@ -168,16 +153,7 @@ bool DLS_add_dir(ULONG size, const TEXT* dir_name)
mutexed_dir_list* mdls = DLS_get_access(); mutexed_dir_list* mdls = DLS_get_access();
#ifdef V4_THREADING Firebird::MutexLockGuard guard(mdls->mdls_mutex);
/* lock mutex, initialize it in case of the first access */
if (!mdls->mdls_mutex_init) {
V4_MUTEX_INIT(mdls->mdls_mutex);
mdls->mdls_mutex_init = true;
}
V4_MUTEX_LOCK(mdls->mdls_mutex);
#endif
/* add new entry to the end of list */ /* add new entry to the end of list */
@ -191,12 +167,6 @@ bool DLS_add_dir(ULONG size, const TEXT* dir_name)
dls_iterator->dls_next = new_dls; dls_iterator->dls_next = new_dls;
} }
#ifdef V4_THREADING
/* release lock */
V4_MUTEX_UNLOCK(mdls->mdls_mutex);
#endif
return true; return true;
} }

View File

@ -47,11 +47,10 @@ struct dir_list {
struct mutexed_dir_list { struct mutexed_dir_list {
dir_list* mdls_dls; /* Pointer to the directory list */ dir_list* mdls_dls; /* Pointer to the directory list */
bool mdls_mutex_init; MUTX_T mdls_mutex; /* Mutex for directory list. Must
MUTX_T mdls_mutex[1]; /* Mutex for directory list. Must
be locked before list operations */ be locked before list operations */
mutexed_dir_list() mutexed_dir_list()
: mdls_dls(0), mdls_mutex_init(false) {} : mdls_dls(NULL) {}
}; };
/* external function directory list */ /* external function directory list */

View File

@ -199,19 +199,15 @@ struct wlck_t {
int THD_wlck_lock(wlck_t*, enum WLCK_type); int THD_wlck_lock(wlck_t*, enum WLCK_type);
int THD_wlck_unlock(wlck_t*); int THD_wlck_unlock(wlck_t*);
#define V4_MUTEX_LOCK(mutx) THD_mutex_lock (mutx) #define V4_RW_LOCK_LOCK(wlck, type) THD_wlck_lock(wlck, type)
#define V4_MUTEX_UNLOCK(mutx) THD_mutex_unlock (mutx) #define V4_RW_LOCK_UNLOCK(wlck) THD_wlck_unlock(wlck)
#define V4_GLOBAL_MUTEX_LOCK THD_mutex_lock_global()
#define V4_GLOBAL_MUTEX_UNLOCK THD_mutex_unlock_global()
#define V4_RW_LOCK_LOCK(wlck, type) THD_wlck_lock (wlck, type)
#define V4_RW_LOCK_UNLOCK(wlck) THD_wlck_unlock (wlck)
#endif // V4_THREADING #endif // V4_THREADING
#ifdef ANY_THREADING #ifdef ANY_THREADING
#define THD_GLOBAL_MUTEX_LOCK THD_mutex_lock_global() #define THD_GLOBAL_MUTEX_LOCK THD_mutex_lock_global()
#define THD_GLOBAL_MUTEX_UNLOCK THD_mutex_unlock_global() #define THD_GLOBAL_MUTEX_UNLOCK THD_mutex_unlock_global()
#define THD_MUTEX_LOCK(mutx) THD_mutex_lock (mutx) #define THD_MUTEX_LOCK(mutx) THD_mutex_lock(mutx)
#define THD_MUTEX_UNLOCK(mutx) THD_mutex_unlock (mutx) #define THD_MUTEX_UNLOCK(mutx) THD_mutex_unlock(mutx)
#else #else
#define THD_GLOBAL_MUTEX_LOCK #define THD_GLOBAL_MUTEX_LOCK
#define THD_GLOBAL_MUTEX_UNLOCK #define THD_GLOBAL_MUTEX_UNLOCK

View File

@ -1620,10 +1620,6 @@ Record* VIO_gc_record(thread_db* tdbb, jrd_rel* relation)
Database* dbb = tdbb->tdbb_database; Database* dbb = tdbb->tdbb_database;
CHECK_DBB(dbb); CHECK_DBB(dbb);
/* This will require mutex synchronization for pre-emptive multithreading. */
/* V4_MUTEX_LOCK (&relation->rel_mutex); */
/* Allocate a vector of garbage collect record blocks for relation. */ /* Allocate a vector of garbage collect record blocks for relation. */
vec<Record*>* vector = relation->rel_gc_rec; vec<Record*>* vector = relation->rel_gc_rec;
if (!vector) { if (!vector) {
@ -1638,7 +1634,6 @@ Record* VIO_gc_record(thread_db* tdbb, jrd_rel* relation)
Record* record = *rec_ptr; Record* record = *rec_ptr;
if (record && !(record->rec_flags & REC_gc_active)) { if (record && !(record->rec_flags & REC_gc_active)) {
record->rec_flags |= REC_gc_active; record->rec_flags |= REC_gc_active;
/* V4_MUTEX_UNLOCK (&relation->rel_mutex); */
return record; return record;
} }
} }
@ -1659,7 +1654,6 @@ Record* VIO_gc_record(thread_db* tdbb, jrd_rel* relation)
} }
(*vector)[slot] = record; (*vector)[slot] = record;
/* V4_MUTEX_UNLOCK (&relation->rel_mutex); */
return record; return record;
} }
@ -4624,8 +4618,6 @@ static Record* replace_gc_record(jrd_rel* relation, Record** gc_record, USHORT l
* *
**************************************/ **************************************/
/* V4_MUTEX_LOCK (&relation->rel_mutex); */
vec<Record*>* vector = relation->rel_gc_rec; vec<Record*>* vector = relation->rel_gc_rec;
vec<Record*>::iterator rec_ptr, end; vec<Record*>::iterator rec_ptr, end;
for (rec_ptr = vector->begin(), end = vector->end(); rec_ptr < end; for (rec_ptr = vector->begin(), end = vector->end(); rec_ptr < end;
@ -4635,12 +4627,10 @@ static Record* replace_gc_record(jrd_rel* relation, Record** gc_record, USHORT l
// 26 Sep 2002, SKIDDER: Failure to do so (*gc_record = ...) causes nasty memory corruption in // 26 Sep 2002, SKIDDER: Failure to do so (*gc_record = ...) causes nasty memory corruption in
// some cases. // some cases.
*gc_record = realloc_record(*rec_ptr, length); *gc_record = realloc_record(*rec_ptr, length);
/* V4_MUTEX_UNLOCK (&relation->rel_mutex); */
return *rec_ptr; return *rec_ptr;
} }
} }
/* V4_MUTEX_UNLOCK (&relation->rel_mutex); */
BUGCHECK(288); /* msg 288 garbage collect record disappeared */ BUGCHECK(288); /* msg 288 garbage collect record disappeared */
return NULL; /* Added to remove compiler warnings */ return NULL; /* Added to remove compiler warnings */
} }