added ref counts for shared fellers and fixed some bugs
Warning, cannot access the index:
_darcs/index: opening of '_darcs/index' failed: permission denied (Permission denied)
diff -rN -u old-repo/src/feller.c new-repo/src/feller.c
--- old-repo/src/feller.c 2022-09-28 11:24:47.935028540 +0200
+++ new-repo/src/feller.c 2022-09-28 11:24:47.935028540 +0200
@@ -16,6 +16,7 @@
FILE *file;
char prefix[PREFIX_LENGTH+1];
unsigned int hash;
+ unsigned refcount;
struct feller *next;
};
@@ -37,6 +38,7 @@
this = firstFeller; /* ignore pvt */
while (this) {
if (strncmp(message, this->prefix, 10)==0) {
+ assert(this->file);
fputs(message + PREFIX_LENGTH, this->file);
}
this = this->next;
@@ -71,21 +73,29 @@
this = this->next;
}
if (!this) {
+ FILE *file = fopen(filename, "a");
+ if (!file) {
+ errlogPrintf("fellerCreate: error cannot open file '%s'"
+ " for appending\n", filename);
+ epicsMutexUnlock(mutex);
+ return NULL;
+ }
this = calloc(1,sizeof(struct feller));
if (!this) {
errlogPrintf("fellerCreate: out of memory\n");
epicsMutexUnlock(mutex);
return NULL;
}
+ this->file = file;
this->next = firstFeller;
firstFeller = this;
this->hash = hash;
+ epicsSnprintf(this->prefix, PREFIX_LENGTH+1, "[%08x]", hash);
} else {
errlogPrintf("fellerCreate: warning re-using already existing instance"
" for file '%s'\n", filename);
}
- epicsSnprintf(this->prefix, PREFIX_LENGTH+1, "[%08x]", hash);
- this->file = fopen(filename, "a");
+ this->refcount++;
epicsMutexUnlock(mutex);
return this;
}
@@ -99,22 +109,28 @@
errlogPrintf("fellerDestroy: mutex unavailable\n");
return;
}
- if (firstFeller == this) {
- firstFeller = this->next;
- } else {
- struct feller *other = firstFeller;
- while (other) {
- if (other->next == this) {
- other->next = this->next;
- break;
- } else {
- other = other->next;
+ if (--this->refcount == 0) {
+ if (firstFeller == this) {
+ firstFeller = this->next;
+ } else {
+ struct feller *other = firstFeller;
+ while (other) {
+ if (other->next == this) {
+ other->next = this->next;
+ break;
+ } else {
+ other = other->next;
+ }
}
}
+ assert(this->file);
+ fflush(this->file);
+ fclose(this->file);
+ free(this);
+ } else {
+ errlogPrintf("fellerDestroy: warning not yet destroying"
+ " shared feller instance\n");
}
- fflush(this->file);
- fclose(this->file);
- free(this);
epicsMutexUnlock(mutex);
}
patch 897d5cc5829ddd612b78d975377a3cbdbc407800
Author: benjamin.franksen@helmholtz-berlin.de
Date: Fri Jun 21 21:27:36 CEST 2013
* added ref counts for shared fellers and fixed some bug