mirror of
https://github.com/amadvance/snapraid.git
synced 2026-12-03 21:30:14 -05:00
Allow compilation without pthread support
This commit is contained in:
parent
fe3ad31cbb
commit
8d3cefb302
4 changed files with 37 additions and 15 deletions
|
|
@ -737,7 +737,9 @@ struct snapraid_disk* disk_alloc(const char* name, const char* dir, uint64_t dev
|
||||||
/* ensure that the dir terminate with "/" if it isn't empty */
|
/* ensure that the dir terminate with "/" if it isn't empty */
|
||||||
pathslash(disk->dir, sizeof(disk->dir));
|
pathslash(disk->dir, sizeof(disk->dir));
|
||||||
|
|
||||||
|
#if HAVE_PTHREAD
|
||||||
thread_mutex_init(&disk->fs_mutex, 0);
|
thread_mutex_init(&disk->fs_mutex, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
disk->smartctl[0] = 0;
|
disk->smartctl[0] = 0;
|
||||||
disk->device = dev;
|
disk->device = dev;
|
||||||
|
|
@ -782,19 +784,29 @@ void disk_free(struct snapraid_disk* disk)
|
||||||
tommy_list_foreach(&disk->dirlist, (tommy_foreach_func*)dir_free);
|
tommy_list_foreach(&disk->dirlist, (tommy_foreach_func*)dir_free);
|
||||||
tommy_hashdyn_done(&disk->dirset);
|
tommy_hashdyn_done(&disk->dirset);
|
||||||
|
|
||||||
|
#if HAVE_PTHREAD
|
||||||
thread_mutex_destroy(&disk->fs_mutex);
|
thread_mutex_destroy(&disk->fs_mutex);
|
||||||
|
#endif
|
||||||
|
|
||||||
free(disk);
|
free(disk);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void fs_lock(struct snapraid_disk* disk)
|
static inline void fs_lock(struct snapraid_disk* disk)
|
||||||
{
|
{
|
||||||
|
#if HAVE_PTHREAD
|
||||||
thread_mutex_lock(&disk->fs_mutex);
|
thread_mutex_lock(&disk->fs_mutex);
|
||||||
|
#else
|
||||||
|
(void)disk;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void fs_unlock(struct snapraid_disk* disk)
|
static inline void fs_unlock(struct snapraid_disk* disk)
|
||||||
{
|
{
|
||||||
|
#if HAVE_PTHREAD
|
||||||
thread_mutex_unlock(&disk->fs_mutex);
|
thread_mutex_unlock(&disk->fs_mutex);
|
||||||
|
#else
|
||||||
|
(void)disk;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
struct chunk_disk_empty {
|
struct chunk_disk_empty {
|
||||||
|
|
|
||||||
|
|
@ -355,6 +355,7 @@ struct snapraid_disk {
|
||||||
int mapping_idx; /**< Index in the mapping vector. Used only as buffer when writing the content file. */
|
int mapping_idx; /**< Index in the mapping vector. Used only as buffer when writing the content file. */
|
||||||
int skip_access; /**< If the disk is inaccessible and it should be skipped. */
|
int skip_access; /**< If the disk is inaccessible and it should be skipped. */
|
||||||
|
|
||||||
|
#if HAVE_PTHREAD
|
||||||
/**
|
/**
|
||||||
* Mutex for protecting the filesystem structure.
|
* Mutex for protecting the filesystem structure.
|
||||||
*
|
*
|
||||||
|
|
@ -365,6 +366,7 @@ struct snapraid_disk {
|
||||||
* change during multithread processing.
|
* change during multithread processing.
|
||||||
*/
|
*/
|
||||||
pthread_mutex_t fs_mutex;
|
pthread_mutex_t fs_mutex;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapping of chunks in the parity.
|
* Mapping of chunks in the parity.
|
||||||
|
|
|
||||||
36
cmdline/io.c
36
cmdline/io.c
|
|
@ -19,18 +19,6 @@
|
||||||
|
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
|
||||||
/**
|
|
||||||
* At now pthread is required.
|
|
||||||
*/
|
|
||||||
#if !HAVE_PTHREAD
|
|
||||||
#error Pthread library is required for InputOutput!
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline int io_thread(struct snapraid_io* io)
|
|
||||||
{
|
|
||||||
return io->io_max > 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next block position to process.
|
* Get the next block position to process.
|
||||||
*/
|
*/
|
||||||
|
|
@ -273,6 +261,9 @@ static void io_stop_mono(struct snapraid_io* io)
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* multi thread */
|
/* multi thread */
|
||||||
|
|
||||||
|
/* disable multithread if pthread is not present */
|
||||||
|
#if HAVE_PTHREAD
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next task to work on for a reader.
|
* Get the next task to work on for a reader.
|
||||||
*
|
*
|
||||||
|
|
@ -847,6 +838,8 @@ static void io_stop_thread(struct snapraid_io* io)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* global */
|
/* global */
|
||||||
|
|
||||||
|
|
@ -862,6 +855,8 @@ void io_init(struct snapraid_io* io, struct snapraid_state* state,
|
||||||
size_t allocated;
|
size_t allocated;
|
||||||
|
|
||||||
io->state = state;
|
io->state = state;
|
||||||
|
|
||||||
|
#if HAVE_PTHREAD
|
||||||
if (io_cache == 0) {
|
if (io_cache == 0) {
|
||||||
/* default is 8 MiB of cache */
|
/* default is 8 MiB of cache */
|
||||||
/* this seems to be a good tradeoff between speed and memory usage */
|
/* this seems to be a good tradeoff between speed and memory usage */
|
||||||
|
|
@ -873,6 +868,12 @@ void io_init(struct snapraid_io* io, struct snapraid_state* state,
|
||||||
} else {
|
} else {
|
||||||
io->io_max = io_cache;
|
io->io_max = io_cache;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
(void)io_cache;
|
||||||
|
|
||||||
|
/* without pthread force the mono thread mode */
|
||||||
|
io->io_max = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
assert(io->io_max == 1 || (io->io_max >= IO_MIN && io->io_max <= IO_MAX));
|
assert(io->io_max == 1 || (io->io_max >= IO_MIN && io->io_max <= IO_MAX));
|
||||||
|
|
||||||
|
|
@ -943,7 +944,8 @@ void io_init(struct snapraid_io* io, struct snapraid_state* state,
|
||||||
worker->buffer_skew = handle_max;
|
worker->buffer_skew = handle_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (io_thread(io)) {
|
#if HAVE_PTHREAD
|
||||||
|
if (io->io_max > 1) {
|
||||||
io_read_next = io_read_next_thread;
|
io_read_next = io_read_next_thread;
|
||||||
io_write_preset = io_write_preset_thread;
|
io_write_preset = io_write_preset_thread;
|
||||||
io_write_next = io_write_next_thread;
|
io_write_next = io_write_next_thread;
|
||||||
|
|
@ -959,7 +961,9 @@ void io_init(struct snapraid_io* io, struct snapraid_state* state,
|
||||||
thread_cond_init(&io->read_sched, 0);
|
thread_cond_init(&io->read_sched, 0);
|
||||||
thread_cond_init(&io->write_done, 0);
|
thread_cond_init(&io->write_done, 0);
|
||||||
thread_cond_init(&io->write_sched, 0);
|
thread_cond_init(&io->write_sched, 0);
|
||||||
} else {
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
io_read_next = io_read_next_mono;
|
io_read_next = io_read_next_mono;
|
||||||
io_write_preset = io_write_preset_mono;
|
io_write_preset = io_write_preset_mono;
|
||||||
io_write_next = io_write_next_mono;
|
io_write_next = io_write_next_mono;
|
||||||
|
|
@ -986,12 +990,14 @@ void io_done(struct snapraid_io* io)
|
||||||
free(io->writer_map);
|
free(io->writer_map);
|
||||||
free(io->writer_list);
|
free(io->writer_list);
|
||||||
|
|
||||||
if (io_thread(io)) {
|
#if HAVE_PTHREAD
|
||||||
|
if (io->io_max > 1) {
|
||||||
thread_mutex_destroy(&io->io_mutex);
|
thread_mutex_destroy(&io->io_mutex);
|
||||||
thread_cond_destroy(&io->read_done);
|
thread_cond_destroy(&io->read_done);
|
||||||
thread_cond_destroy(&io->read_sched);
|
thread_cond_destroy(&io->read_sched);
|
||||||
thread_cond_destroy(&io->write_done);
|
thread_cond_destroy(&io->write_done);
|
||||||
thread_cond_destroy(&io->write_sched);
|
thread_cond_destroy(&io->write_sched);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -814,7 +814,9 @@ int main(int argc, char* argv[])
|
||||||
opt.force_stats = 1;
|
opt.force_stats = 1;
|
||||||
break;
|
break;
|
||||||
case OPT_TEST_COND_SIGNAL_OUTSIDE :
|
case OPT_TEST_COND_SIGNAL_OUTSIDE :
|
||||||
|
#if HAVE_PTHREAD
|
||||||
thread_cond_signal_outside = 1;
|
thread_cond_signal_outside = 1;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
/* LCOV_EXCL_START */
|
/* LCOV_EXCL_START */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue