add functions common_blocked_queue_empty/count
parent
793d683d2a
commit
5f34bc872b
|
|
@ -95,6 +95,36 @@ void common_blocked_queue_return_nodes(struct common_blocked_queue *queue,
|
||||||
void *common_blocked_queue_pop_ex(struct common_blocked_queue *queue,
|
void *common_blocked_queue_pop_ex(struct common_blocked_queue *queue,
|
||||||
const bool blocked);
|
const bool blocked);
|
||||||
|
|
||||||
|
static inline bool common_blocked_queue_empty(
|
||||||
|
struct common_blocked_queue *queue)
|
||||||
|
{
|
||||||
|
bool empty;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&queue->lc_pair.lock);
|
||||||
|
empty = (queue->head == NULL);
|
||||||
|
pthread_mutex_unlock(&queue->lc_pair.lock);
|
||||||
|
return empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int common_blocked_queue_count(
|
||||||
|
struct common_blocked_queue *queue)
|
||||||
|
{
|
||||||
|
int count;
|
||||||
|
struct common_blocked_node *node;
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
pthread_mutex_lock(&queue->lc_pair.lock);
|
||||||
|
node = queue->head;
|
||||||
|
while (node != NULL)
|
||||||
|
{
|
||||||
|
++count;
|
||||||
|
node = node->next;
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&queue->lc_pair.lock);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define common_blocked_queue_pop(queue) \
|
#define common_blocked_queue_pop(queue) \
|
||||||
common_blocked_queue_pop_ex(queue, true)
|
common_blocked_queue_pop_ex(queue, true)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,23 @@ static inline bool fc_queue_empty(struct fc_queue *queue)
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int fc_queue_count(struct fc_queue *queue)
|
||||||
|
{
|
||||||
|
int count;
|
||||||
|
void *data;
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
pthread_mutex_lock(&queue->lc_pair.lock);
|
||||||
|
data = queue->head;
|
||||||
|
while (data != NULL)
|
||||||
|
{
|
||||||
|
++count;
|
||||||
|
data = FC_QUEUE_NEXT_PTR(queue, data);
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&queue->lc_pair.lock);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
void *fc_queue_timedpop(struct fc_queue *queue,
|
void *fc_queue_timedpop(struct fc_queue *queue,
|
||||||
const int timeout, const int time_unit);
|
const int timeout, const int time_unit);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -711,7 +711,7 @@ int getOccurCount(const char *src, const char seperator)
|
||||||
p = strchr(src, seperator);
|
p = strchr(src, seperator);
|
||||||
while (p != NULL)
|
while (p != NULL)
|
||||||
{
|
{
|
||||||
count++;
|
++count;
|
||||||
p = strchr(p + 1, seperator);
|
p = strchr(p + 1, seperator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -721,7 +721,7 @@ int getOccurCount(const char *src, const char seperator)
|
||||||
int fc_get_file_line_count_ex(const char *filename,
|
int fc_get_file_line_count_ex(const char *filename,
|
||||||
const int64_t until_offset, int64_t *line_count)
|
const int64_t until_offset, int64_t *line_count)
|
||||||
{
|
{
|
||||||
#define READ_BUFFER_SIZE (256 * 1024)
|
#define READ_BUFFER_SIZE (256 * 1024 * 1024)
|
||||||
int fd;
|
int fd;
|
||||||
int result;
|
int result;
|
||||||
int read_bytes;
|
int read_bytes;
|
||||||
|
|
@ -752,8 +752,8 @@ int fc_get_file_line_count_ex(const char *filename,
|
||||||
}
|
}
|
||||||
|
|
||||||
while (remain_bytes > 0) {
|
while (remain_bytes > 0) {
|
||||||
read_bytes = remain_bytes >= READ_BUFFER_SIZE ?
|
read_bytes = (remain_bytes >= READ_BUFFER_SIZE ?
|
||||||
(READ_BUFFER_SIZE - 1) : remain_bytes;
|
(READ_BUFFER_SIZE - 1) : remain_bytes);
|
||||||
read_bytes = read(fd, buff, read_bytes);
|
read_bytes = read(fd, buff, read_bytes);
|
||||||
if (read_bytes == 0) {
|
if (read_bytes == 0) {
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue