Skip to content

Commit

Permalink
refactor: naming of "job end callback list"
Browse files Browse the repository at this point in the history
The names of variables and functions for the
job end callback functionality was absurd.

This commit tries to use better names that make
the whole functionality understandable.
  • Loading branch information
pstorz committed Apr 27, 2017
1 parent 864ce89 commit c58c71a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/dird/dird.c
Expand Up @@ -565,7 +565,7 @@ static bool init_sighandler_sighup()
* last reload, then the old resources will be immediately release.
* A console is considered a job because it may have pointers to
* resources, but a SYSTEM job is not since it *should* not have any
* permanent pointers to jobs.
* permanent pointers to resources.
*/
bool do_reload_config()
{
Expand Down Expand Up @@ -646,7 +646,7 @@ bool do_reload_config()
memcpy(new_table, &prev_config, sizeof(resource_table_reference));
}
new_table->job_count++;
job_end_push(jcr, reload_job_end_cb, (void *)new_table);
register_job_end_callback(jcr, reload_job_end_cb, (void *)new_table);
njobs++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dird/job.c
Expand Up @@ -1549,7 +1549,7 @@ void dird_free_jcr(JCR *jcr)
*/
free_rwstorage(jcr);

jcr->job_end_push.destroy();
jcr->job_end_callbacks.destroy();

if (jcr->JobId != 0) {
write_state_file(me->working_directory, "bareos-dir", get_first_port_host_order(me->DIRaddrs));
Expand Down
4 changes: 2 additions & 2 deletions src/include/jcr.h
Expand Up @@ -265,7 +265,7 @@ struct CMPRS_CTX {
} workset;
};

struct job_push_item {
struct job_callback_item {
void (*job_end_cb)(JCR *jcr, void *);
void *ctx;
};
Expand Down Expand Up @@ -338,7 +338,7 @@ class JCR {
dlist *msg_queue; /**< Queued messages */
pthread_mutex_t msg_queue_mutex; /**< message queue mutex */
bool dequeuing_msgs; /**< Set when dequeuing messages */
alist job_end_push; /**< Job end pushed calls */
alist job_end_callbacks; /**< callbacks called at Job end */
POOLMEM *VolumeName; /**< Volume name desired -- pool_memory */
POOLMEM *errmsg; /**< Edited error message */
char Job[MAX_NAME_LENGTH]; /**< Unique name of this Job */
Expand Down
28 changes: 14 additions & 14 deletions src/lib/jcr.c
Expand Up @@ -304,33 +304,33 @@ bool JCR::JobReads()
}

/*
* Push a job_push_item onto the job end callback stack.
* Push a job_callback_item onto the job end callback stack.
*/
void job_end_push(JCR *jcr, void job_end_cb(JCR *jcr, void *), void *ctx)
void register_job_end_callback(JCR *jcr, void job_end_cb(JCR *jcr, void *), void *ctx)
{
job_push_item *item;
job_callback_item *item;

item = (job_push_item *)malloc(sizeof(job_push_item));
item = (job_callback_item *)malloc(sizeof(job_callback_item));

item->job_end_cb = job_end_cb;
item->ctx = ctx;

jcr->job_end_push.push((void *)item);
jcr->job_end_callbacks.push((void *)item);
}

/*
* Pop each job_push_item and process it.
* Pop each job_callback_item and process it.
*/
static void job_end_pop(JCR *jcr)
static void call_job_end_callbacks(JCR *jcr)
{
job_push_item *item;
job_callback_item *item;

if (jcr->job_end_push.size() > 0) {
item = (job_push_item *)jcr->job_end_push.pop();
if (jcr->job_end_callbacks.size() > 0) {
item = (job_callback_item *)jcr->job_end_callbacks.pop();
while (item) {
item->job_end_cb(jcr, item->ctx);
free(item);
item = (job_push_item *)jcr->job_end_push.pop();
item = (job_callback_item *)jcr->job_end_callbacks.pop();
}
}
}
Expand Down Expand Up @@ -408,7 +408,7 @@ JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr)
}

jcr->my_thread_id = pthread_self();
jcr->job_end_push.init(1, false);
jcr->job_end_callbacks.init(1, false);
jcr->sched_time = time(NULL);
jcr->initial_sched_time = jcr->sched_time;
jcr->daemon_free_jcr = daemon_free_jcr; /* plug daemon free routine */
Expand Down Expand Up @@ -438,7 +438,7 @@ JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr)
* Locking jobs is a global lock that is needed
* so that the Director can stop new jobs from being
* added to the jcr chain while it processes a new
* conf file and does the job_end_push().
* conf file and does the register_job_end_callback().
*/
lock_jobs();
lock_jcr_chain();
Expand Down Expand Up @@ -597,7 +597,7 @@ void free_jcr(JCR *jcr)
unlock_jcr_chain();

dequeue_messages(jcr);
job_end_pop(jcr); /* pop and call hooked routines */
call_job_end_callbacks(jcr); /* call registered callbacks */

Dmsg1(dbglvl, "End job=%d\n", jcr->JobId);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/protos.h
Expand Up @@ -248,7 +248,7 @@ void unlock_last_jobs_list();
bool read_last_jobs_list(int fd, uint64_t addr);
uint64_t write_last_jobs_list(int fd, uint64_t addr);
void write_state_file(char *dir, const char *progname, int port);
void job_end_push(JCR *jcr, void job_end_cb(JCR *jcr,void *), void *ctx);
void register_job_end_callback(JCR *jcr, void job_end_cb(JCR *jcr,void *), void *ctx);
void lock_jobs();
void unlock_jobs();
JCR *jcr_walk_start();
Expand Down

0 comments on commit c58c71a

Please sign in to comment.