Create queue_print function.

Since we are here, also make it dependant on an extra debug macro,
DEBUGP, and add "static [inline]" wherever missing.
This commit is contained in:
Érico Nogueira 2021-10-03 01:06:46 -03:00
parent 0e80093346
commit be074ea79e
1 changed files with 16 additions and 7 deletions

View File

@ -38,7 +38,20 @@ static struct queue queue = {0};
pthread_mutex_t fd_mtx = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t fd_cond = PTHREAD_COND_INITIALIZER;
int queue_add(struct queue *q, char *path, unsigned char type, struct task *parent)
static inline void queue_print(struct queue *q)
{
#ifdef DEBUGP
puts("begin========================");
for (size_t i=0; i < q->len; i++) {
printf("item %010zu: '%s'\n", i, q->tasks[i].path);
}
puts("end==========================");
#else
(void)q;
#endif
}
static inline int queue_add(struct queue *q, char *path, unsigned char type, struct task *parent)
{
int rv = 0;
@ -66,7 +79,7 @@ error:
static long nproc;
static int queue_remove(struct queue *q, struct task *t)
static inline int queue_remove(struct queue *q, struct task *t)
{
int rv = 0;
pthread_mutex_lock(&q->mtx);
@ -83,11 +96,7 @@ static int queue_remove(struct queue *q, struct task *t)
rv = EAGAIN;
goto error;
}
puts("begin========================");
for (size_t i=0; i < q->len; i++) {
printf("item %010zu: '%s'\n", i, q->tasks[i].path);
}
puts("end==========================");
queue_print(q);
*t = q->tasks[--(q->len)];
/* the caller owns the path buffer now */