#include <inttypes.h>
#include <siri/file/pointer.h>
+#include <uv.h>
siri_fh_t * siri_fh_new(uint16_t size);
+void siri_fh_close(siri_fh_t * fh);
void siri_fh_free(siri_fh_t * fh);
int siri_fopen(
siri_fh_t * fh,
uint16_t size;
uint16_t idx;
siri_fp_t ** fpointers;
+ uv_mutex_t lock_;
};
#endif /* SIRI_FH_H_ */
#define SIRIDB_VERSION_MAJOR 2
#define SIRIDB_VERSION_MINOR 0
-#define SIRIDB_VERSION_PATCH 49
+#define SIRIDB_VERSION_PATCH 50
/*
* Use SIRIDB_VERSION_PRE_RELEASE for alpha release versions.
* Note that debian alpha packages should use versions like this:
* 2.0.34-0alpha0
*/
-#define SIRIDB_VERSION_PRE_RELEASE ""
+#define SIRIDB_VERSION_PRE_RELEASE "-alpha-1"
#ifndef NDEBUG
#define SIRIDB_VERSION_BUILD_RELEASE "+debug"
}
/* this will close the file, even when other references exist */
+ uv_mutex_lock(&siri.fh->lock_);
+
siri_fp_decref(shard->fp);
+ uv_mutex_unlock(&siri.fh->lock_);
+
free(shard->fn);
free(shard);
}
free(fh);
fh = NULL;
}
+ uv_mutex_init(&fh->lock_);
}
return fh;
}
/*
- * Destroy file handler. (closes all open files in the file handler)
+ * Close file handler. (closes all open files in the file handler)
* In case closing an open file fails, a SIGNAL will be raised.
*/
-void siri_fh_free(siri_fh_t * fh)
+void siri_fh_close(siri_fh_t * fh)
{
siri_fp_t ** fp;
uint16_t i;
}
siri_fp_decref(*fp);
}
+}
+
+/*
+ * Destroy file handler. (closes all open files in the file handler)
+ * In case closing an open file fails, a SIGNAL will be raised.
+ */
+void siri_fh_free(siri_fh_t * fh)
+{
free(fh->fpointers);
+ uv_mutex_destroy(&fh->lock_);
free(fh);
}
+
/*
* Returns 0 if successful or -1 in case of an error.
*/
const char * fn,
const char * modes)
{
- siri_fp_t ** dest = fh->fpointers + fh->idx;
+ siri_fp_t ** dest;
+ uv_mutex_lock(&fh->lock_);
+ dest = fh->fpointers + fh->idx;
/* close and possible free file pointer at next position */
if (*dest != NULL)
if ((fp->fp = fopen(fn, modes)) == NULL)
{
log_critical("Cannot open file: '%s' using mode '%s'", fn, modes);
+ uv_mutex_unlock(&fh->lock_);
return -1;
}
/* set file handler pointer to next position */
fh->idx = (fh->idx + 1) % fh->size;
-
+ uv_mutex_unlock(&fh->lock_);
return 0;
}
}
}
- /* first free the File Handler. (this will close all open shard files) */
- siri_fh_free(siri.fh);
+ /* first close the File Handler. (this will close all open shard files) */
+ siri_fh_close(siri.fh);
/* this will free each SiriDB database and the list */
llist_free_cb(siri.siridb_list, (llist_cb) siridb_decref_cb, NULL);
/* free config */
siri_cfg_destroy(&siri);
+ /* free the file handler */
+ siri_fh_free(siri.fh);
+
/* free event loop */
free(siri.loop);
}