Skip to content

Commit

Permalink
CLEANUP: item_start_scrub() function.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpark816 committed Jun 3, 2018
1 parent 95b7394 commit 1257150
Showing 1 changed file with 40 additions and 29 deletions.
69 changes: 40 additions & 29 deletions engines/default/items.c
Original file line number Diff line number Diff line change
Expand Up @@ -7864,48 +7864,59 @@ bool item_start_scrub(struct default_engine *engine, int mode, bool autorun)
assert(mode == (int)SCRUB_MODE_NORMAL || mode == (int)SCRUB_MODE_STALE);
bool restarted = false;
bool ret = false;
pthread_mutex_lock(&engine->scrubber.lock);
if (engine->scrubber.enabled && !engine->scrubber.running) {
engine->scrubber.started = time(NULL);
engine->scrubber.stopped = 0;
engine->scrubber.visited = 0;
engine->scrubber.cleaned = 0;
engine->scrubber.restart = false;
engine->scrubber.runmode = (enum scrub_mode)mode;
engine->scrubber.running = true;

pthread_t t;
pthread_attr_t attr;

if (pthread_attr_init(&attr) != 0 ||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0 ||
pthread_create(&t, &attr, item_scrubber_main, engine) != 0)
{
engine->scrubber.running = false;
pthread_mutex_lock(&engine->scrubber.lock);
if (engine->scrubber.enabled) {
if (!engine->scrubber.running) {
engine->scrubber.started = time(NULL);
engine->scrubber.stopped = 0;
engine->scrubber.visited = 0;
engine->scrubber.cleaned = 0;
engine->scrubber.restart = false;
engine->scrubber.runmode = (enum scrub_mode)mode;
engine->scrubber.running = true;

pthread_t t;
pthread_attr_t attr;

if (pthread_attr_init(&attr) != 0 ||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0 ||
pthread_create(&t, &attr, item_scrubber_main, engine) != 0)
{
engine->scrubber.running = false;
} else {
ret = true;
}
} else {
ret = true;
if (autorun == true && mode == SCRUB_MODE_STALE) {
restarted = true;
engine->scrubber.restart = restarted;
engine->scrubber.runmode = (enum scrub_mode)mode;
ret = true;
}
}
}
else if (engine->scrubber.enabled && autorun == true
&& mode == SCRUB_MODE_STALE) {
restarted = true;
engine->scrubber.restart = restarted;
engine->scrubber.runmode = (enum scrub_mode)mode;
ret = true;
}
pthread_mutex_unlock(&engine->scrubber.lock);

if (ret) {
if (!restarted) {
logger->log(EXTENSION_LOG_INFO, NULL,
"Scrub is succesfully started.\n");
"Scrub is succesfully started.\n");
} else {
logger->log(EXTENSION_LOG_INFO, NULL,
"Scrub is arleady running. Restart scrub.n");
"Scrub is arleady running. Restarted the scrub.\n");
}
} else {
logger->log(EXTENSION_LOG_WARNING, NULL,
"Failed to start scrub. Scrub is already running.\n");
if (!engine->scrubber.enabled) {
logger->log(EXTENSION_LOG_WARNING, NULL,
"Failed to start scrub. Scrub is disabled.\n");
} else if (engine->scrubber.running) {
logger->log(EXTENSION_LOG_WARNING, NULL,
"Failed to start scrub. Scrub is already running.\n");
} else {
logger->log(EXTENSION_LOG_WARNING, NULL,
"Failed to start scrub. Scrub thread creation problem.\n");
}
}
return ret;
}
Expand Down

0 comments on commit 1257150

Please sign in to comment.