mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-24 17:06:25 -05:00
Use a single scheduling point for sync
This commit is contained in:
parent
d2bad33af8
commit
541665db46
3 changed files with 56 additions and 3 deletions
34
cmdline/io.c
34
cmdline/io.c
|
|
@ -489,7 +489,7 @@ static void io_write_next_outside(struct snapraid_io* io)
|
|||
*
|
||||
* It must be called inside the lock.
|
||||
*/
|
||||
static void io_write_next_inside(struct snapraid_io* io, unsigned blockcur, int skip, int* writer_error)
|
||||
static void io_write_next_inside(struct snapraid_io* io, block_off_t blockcur, int skip, int* writer_error)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
|
|
@ -537,6 +537,38 @@ void io_write_next(struct snapraid_io* io, unsigned blockcur, int skip, int* wri
|
|||
#endif
|
||||
}
|
||||
|
||||
block_off_t io_write_and_read_next(struct snapraid_io* io, block_off_t blockcur, int skip, int* writer_error, void*** buffer)
|
||||
{
|
||||
block_off_t blockcur_schedule;
|
||||
block_off_t blockcur_caller;
|
||||
|
||||
io_write_next_outside(io);
|
||||
blockcur_schedule = io_read_next_outside(io);
|
||||
|
||||
/* the synchronization is protected by the io mutex */
|
||||
pthread_mutex_lock(&io->mutex);
|
||||
|
||||
io_write_next_inside(io, blockcur, skip, writer_error);
|
||||
|
||||
blockcur_caller = io_read_next_inside(io, blockcur_schedule, buffer);
|
||||
|
||||
#ifndef CHECKER
|
||||
/* without the thread checker unlock before signaling, */
|
||||
/* this reduces the number of context switches */
|
||||
pthread_mutex_unlock(&io->mutex);
|
||||
#endif
|
||||
|
||||
/* signal all the workers that there is a new pending task */
|
||||
pthread_cond_broadcast(&io->write_sched);
|
||||
pthread_cond_broadcast(&io->read_sched);
|
||||
|
||||
#ifdef CHECKER
|
||||
pthread_mutex_unlock(&io->mutex);
|
||||
#endif
|
||||
|
||||
return blockcur_caller;
|
||||
}
|
||||
|
||||
void io_refresh(struct snapraid_io* io)
|
||||
{
|
||||
unsigned i;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue