+ crc = crc32c(crc, item->data->data, item->data->len);
+
+ crc = crc32c(crc, (const char *)&footer,
+ sizeof(footer) - sizeof(uint32_t));
+ footer.crc = crc32c_finalize(crc);
+ writebuf(log->fd, (const char *)&footer, sizeof(footer));
+
+ logsize += sizeof(header) + sizeof(footer);
+ logsize += strlen(item->key) + item->data->len;
+
+ committed = g_slist_prepend(committed, item);
+
+ /* Force an fsync either if we will be closing this log segment and
+ * opening a new file, or if there are no other log items currently
+ * waiting to be written. */
+
+ if (logsize >= LOG_SEGMENT_SIZE
+ || g_async_queue_length(log->queue) <= 0)
+ {
+ int batchsize = 0;
+ fdatasync(log->fd);
+ while (committed != NULL) {
+ item = (BlueSkyLogItem *)committed->data;
+ item->committed = TRUE;
+ g_cond_signal(item->cond);
+ g_mutex_unlock(item->lock);
+ committed = g_slist_delete_link(committed, committed);
+ batchsize++;
+ }
+ /* if (batchsize > 1)
+ g_print("Log batch size: %d\n", batchsize); */
+ }