From 0eb80acad6918b9899fe1eceae923c20f69320fe Mon Sep 17 00:00:00 2001 From: angelo Date: Wed, 20 Sep 1995 09:44:28 +0000 Subject: [PATCH] Rif. mod. 95/33. Sistemata la DB_delkeys() e la DB_add() sui lock. Cambiata la DB_locked(). Sostituite le msg_box() di debug con yesnofatal_box(). Eliminati i messaggi di warning in compilazione. git-svn-id: svn://10.65.10.50/trunk@1858 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/codeb.c | 65 ++++++++++++++++++++++++++++++++----------------- include/codeb.h | 5 ++-- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/include/codeb.c b/include/codeb.c index a5cac7b78..1fd49c370 100755 --- a/include/codeb.c +++ b/include/codeb.c @@ -396,6 +396,8 @@ int DB_delkey(int handle, char* key, long recno) INDEX4* i; TAG4* t; int rt=0; + int is_locked = 0; /* Diverso da 0 se il file e' bloccato in modo esclusivo */ + /* (dati o indice) da me stesso*/ char fn[64]; if(dbdata[handle]==0) return(-1); @@ -406,16 +408,21 @@ int DB_delkey(int handle, char* key, long recno) else strcpy(fn,dbdata[handle]->file.name); if ((i=d4index(dbdata[handle],fn)) == NULL) - return(e4index); - while ((rt=i4lock(i)) == r4locked) + return(e4index); + is_locked = DB_file_locked(handle); + if (is_locked == 0) /* Se non e' stato bloccato in modo esclusivo */ + { + while ((rt=i4lock(i)) == r4locked) #ifdef DBG - message_box("Sono in attesa nella DB_delkeys"); + yesnofatal_box("Sono in attesa nella DB_delkeys"); #else - u4delay_sec(); + u4delay_sec(); #endif + } if (rt == 0) rt=t4remove_calc(t,recno); - i4unlock(i); + if (is_locked == 0) /* Siccome ho fatto il lock dell'indice, devo anche sbloccarlo */ + i4unlock(i); return(rt); } @@ -428,7 +435,7 @@ int DB_flush(int handle) while ((rt = d4flush(dbdata[handle])) == r4locked) #ifdef DBG - message_box("Sono in attesa nella DB_add (d4append)"); + yesnofatal_box("Sono in attesa nella DB_flush"); #else u4delay_sec(); #endif @@ -444,7 +451,7 @@ int DB_rewrite(int handle) if(dbdata[handle]==0) return(-1); while ((rt=d4write(dbdata[handle],d4recno(dbdata[handle]))) == r4locked) #ifdef DBG - message_box("Sono in attesa nella DB_rewrite"); + yesnofatal_box("Sono in attesa nella DB_rewrite"); #else u4delay_sec(); #endif @@ -452,7 +459,7 @@ int DB_rewrite(int handle) { while ((rt = d4flush(dbdata[handle])) == r4locked) #ifdef DBG - message_box("Sono in attesa nella DB_add (d4append)"); + yesnofatal_box("Sono in attesa nella DB_rewrite (d4flush)"); #else u4delay_sec(); #endif @@ -460,7 +467,8 @@ int DB_rewrite(int handle) if (rt == e4unique) { DB_get_error(); - fatal_box("Errore : chiave duplicata nell' indice %d", dbdata[handle]->rec_num + 1); + fatal_box("Errore in DB_rewrite(): chiave duplicata nell' indice %d, file %s", + dbdata[handle]->rec_num + 1, dbdata[handle]->file.name); } rt=DB_unlock(handle); return (rt); @@ -473,18 +481,23 @@ int DB_rewrite(int handle) int DB_add(int handle) { int rt; + int is_locked = 0; DATA4 * data = dbdata[handle]; if (data==0) return(-1); - while (file4lock(&data->file, L4LOCK_POS_OLD, 1L) == r4locked) + is_locked = DB_file_locked(handle); + if (is_locked == 0) /* Se non e' stato gia' bloccato in modo esclusivo */ + { + while (file4lock(&data->file, L4LOCK_POS_OLD, 1L) == r4locked) #ifdef DBG - message_box("Sono in attesa nella DB_add"); + yesnofatal_box("Sono in attesa nella DB_add"); #else - u4delay_sec(); + u4delay_sec(); #endif + } while ((rt = d4append_start(data,0)) == r4locked) #ifdef DBG - message_box("Sono in attesa nella DB_add (d4append_start)"); + yesnofatal_box("Sono in attesa nella DB_add (d4append_start)"); #else u4delay_sec(); #endif @@ -493,7 +506,7 @@ int DB_add(int handle) d4recall(data); while ((rt = d4append(data)) == r4locked) #ifdef DBG - message_box("Sono in attesa nella DB_add (d4append)"); + yesnofatal_box("Sono in attesa nella DB_add (d4append)"); #else u4delay_sec(); #endif @@ -501,7 +514,8 @@ int DB_add(int handle) { DB_get_error(); if (data->rec_num > 0) - fatal_box("Errore : chiave duplicata nell' indice %d", data->rec_num + 1); + fatal_box("Errore in DB_add(): chiave duplicata nell' indice %d, file %s", + data->rec_num + 1, data->file.name); else rt = _isreinsert; } @@ -510,14 +524,17 @@ int DB_add(int handle) { while ((rt = d4flush(data)) == r4locked) #ifdef DBG - message_box("Sono in attesa nella DB_add (d4append)"); + yesnofatal_box("Sono in attesa nella DB_add (d4flush)"); #else u4delay_sec(); #endif } } DB_unlock(handle); - file4unlock(&data->file, L4LOCK_POS_OLD, 1L); + if (is_locked == 0) + { + file4unlock(&data->file, L4LOCK_POS_OLD, 1L); + } return(rt); } @@ -721,8 +738,8 @@ int DB_packindex(short vis, const char * filename, RecDes *r, long *peod) progind_create((long)r->NKeys,s,1,1,1); #endif } - if (ff == NULL || *ff == NULL) - ff = filename; + if ((ff == NULL) || *ff == '\0') + ff = (char *)filename; else ff++; do_key(ff,r,tags); @@ -824,7 +841,7 @@ int DB_build(const char * filename, RecDes *r) field_info[i].len=0; field_info[i].dec=0; - if (ff == NULL || *ff == NULL) + if (ff == NULL || *ff == '\0') ff = (char *) filename; else ff++; @@ -971,18 +988,20 @@ int DB_lock_rec(int handle,long nrec) } /*------------------------------------------------------------------------- - Ritorna vero se il file e' bloccato in modo exclusive + Ritorna vero(non zero) se il file dati od indice sono stati bloccati + in modo esclusivo dalla presente applicazione, non da altri programmi!!! --------------------------------------------------------------------------*/ int DB_file_locked(int handle) { if(dbdata[handle]==0) return(-1); - return(d4lock_test_file(dbdata[handle])); + return(d4lock_test_file(dbdata[handle]) + d4lock_test_index(dbdata[handle])); } /*------------------------------------------------------------------------- - Ritorna vero se il record nrec e' bloccato + Ritorna vero se il record nrec e' bloccato dalla presente applicazione, + non da altri programmi!!! --------------------------------------------------------------------------*/ int DB_rec_locked(int handle,long nrec) diff --git a/include/codeb.h b/include/codeb.h index 41a175a3d..3a81a8cd5 100755 --- a/include/codeb.h +++ b/include/codeb.h @@ -38,7 +38,6 @@ extern "C" { int DB_prev(int handle); int DB_skip(int handle,long int recno); int DB_lock(int handle); - int DB_lockrec(int handle, long recno); // Per sbloccare il record basta la DB_unlock() int DB_unlock(int handle); int DB_seek(int handle,char *key); int DB_eof(int handle); @@ -50,7 +49,7 @@ extern "C" { int DB_flush(int handle); int DB_rewrite(int handle); int DB_add(int handle); - int DB_lockfile(int handle); // Per sbloccare il file basta la DB_unlock() + int DB_lockfile(int handle); /* Per sbloccare il record basta la DB_unlock()*/ int DB_packfile(short vis, const char * filename, long eod); int DB_packindex(short vis, const char * filename, RecDes *r, long *peod ); int DB_build(const char * filename, RecDes *r); @@ -65,7 +64,7 @@ extern "C" { int DB_file_locked(int handle); int DB_rec_locked(int handle,long nrec); long DB_getconf(); - long DB_changed(int handle); // returns true if the index of the key is changed + long DB_changed(int handle); /* returns true if the index of the key is changed */ #ifdef __cplusplus }; #endif