Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Queue] change param #218

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/libnnstreamer-edge/nnstreamer-edge-internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,7 @@ nns_edge_set_info (nns_edge_h edge_h, const char *key, const char *value)
} else if (0 == strcasecmp (key, "QUEUE_SIZE")) {
char *s;
unsigned int limit;
nns_edge_queue_leak_e leaky = NNS_EDGE_QUEUE_LEAK_UNKNOWN;
nns_edge_queue_leak_e leaky = NNS_EDGE_QUEUE_LEAK_NEW;

s = strstr (value, ":");
if (s) {
Expand All @@ -2088,7 +2088,8 @@ nns_edge_set_info (nns_edge_h edge_h, const char *key, const char *value)
limit = (unsigned int) strtoull (value, NULL, 10);
}

nns_edge_queue_set_limit (eh->send_queue, limit, leaky);
if (ret == NNS_EDGE_ERROR_NONE)
nns_edge_queue_set_limit (eh->send_queue, limit, leaky);
} else if (0 == strcasecmp (key, "my-ip") ||
0 == strcasecmp (key, "clean-session") ||
0 == strcasecmp (key, "custom-broker") ||
Expand Down
21 changes: 12 additions & 9 deletions src/libnnstreamer-edge/nnstreamer-edge-queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,28 @@ nns_edge_queue_destroy (nns_edge_queue_h handle)
}

/**
* @brief Get the length of the queue.
* @brief Get the number of data in the queue.
*/
unsigned int
nns_edge_queue_get_length (nns_edge_queue_h handle)
int
nns_edge_queue_get_length (nns_edge_queue_h handle, unsigned int *length)
{
nns_edge_queue_s *q = (nns_edge_queue_s *) handle;
unsigned int len;

if (!q) {
nns_edge_loge ("[Queue] Invalid param, queue is null.");
return 0;
return NNS_EDGE_ERROR_INVALID_PARAMETER;
}

if (!length) {
nns_edge_loge ("[Queue] Invalid param, length is null.");
return NNS_EDGE_ERROR_INVALID_PARAMETER;
}

nns_edge_lock (q);
len = q->length;
*length = q->length;
nns_edge_unlock (q);

return len;
return NNS_EDGE_ERROR_NONE;
}

/**
Expand All @@ -163,8 +167,7 @@ nns_edge_queue_set_limit (nns_edge_queue_h handle, unsigned int limit,

nns_edge_lock (q);
q->max_data = limit;
if (leaky != NNS_EDGE_QUEUE_LEAK_UNKNOWN)
q->leaky = leaky;
q->leaky = leaky;
nns_edge_unlock (q);

return NNS_EDGE_ERROR_NONE;
Expand Down
12 changes: 7 additions & 5 deletions src/libnnstreamer-edge/nnstreamer-edge-queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ typedef void *nns_edge_queue_h;
* @brief Enumeration for the queue leaky option.
*/
typedef enum {
NNS_EDGE_QUEUE_LEAK_UNKNOWN = 0,
NNS_EDGE_QUEUE_LEAK_NEW,
NNS_EDGE_QUEUE_LEAK_NEW = 0,
NNS_EDGE_QUEUE_LEAK_OLD
} nns_edge_queue_leak_e;

Expand All @@ -52,11 +51,14 @@ int nns_edge_queue_create (nns_edge_queue_h *handle);
int nns_edge_queue_destroy (nns_edge_queue_h handle);

/**
* @brief Get the length of the queue.
* @brief Get the number of data in the queue.
* @param[in] handle The queue handle.
* @return The number of data in the queue.
* @param[out] The number of data in the queue.
* @return 0 on success. Otherwise a negative error value.
* @retval #NNS_EDGE_ERROR_NONE Successful.
* @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid.
*/
unsigned int nns_edge_queue_get_length (nns_edge_queue_h handle);
int nns_edge_queue_get_length (nns_edge_queue_h handle, unsigned int *length);

/**
* @brief Set the max length of the queue.
Expand Down
57 changes: 32 additions & 25 deletions tests/unittest_nnstreamer-edge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3432,7 +3432,7 @@ TEST_F(edgeQueue, pushData)
{
void *data1, *data2, *data3, *result;
nns_size_t dsize, rsize;
unsigned int i, len;
unsigned int i, len = 0U;

dsize = 5 * sizeof (unsigned int);

Expand All @@ -3452,20 +3452,20 @@ TEST_F(edgeQueue, pushData)
((unsigned int *) data3)[i] = i + 30U;

EXPECT_EQ (nns_edge_queue_push (queue_h, data1, dsize, NULL), NNS_EDGE_ERROR_NONE);
len = nns_edge_queue_get_length (queue_h);
EXPECT_EQ (nns_edge_queue_get_length (queue_h, &len), NNS_EDGE_ERROR_NONE);
EXPECT_EQ (len, 1U);

EXPECT_EQ (nns_edge_queue_push (queue_h, data2, dsize, NULL), NNS_EDGE_ERROR_NONE);
len = nns_edge_queue_get_length (queue_h);
EXPECT_EQ (nns_edge_queue_get_length (queue_h, &len), NNS_EDGE_ERROR_NONE);
EXPECT_EQ (len, 2U);

EXPECT_EQ (nns_edge_queue_push (queue_h, data3, dsize, NULL), NNS_EDGE_ERROR_NONE);
len = nns_edge_queue_get_length (queue_h);
EXPECT_EQ (nns_edge_queue_get_length (queue_h, &len), NNS_EDGE_ERROR_NONE);
EXPECT_EQ (len, 3U);

rsize = 0U;
EXPECT_EQ (nns_edge_queue_pop (queue_h, &result, &rsize), NNS_EDGE_ERROR_NONE);
len = nns_edge_queue_get_length (queue_h);
EXPECT_EQ (nns_edge_queue_get_length (queue_h, &len), NNS_EDGE_ERROR_NONE);
EXPECT_EQ (len, 2U);
EXPECT_EQ (result, data1);
EXPECT_EQ (dsize, rsize);
Expand All @@ -3474,7 +3474,7 @@ TEST_F(edgeQueue, pushData)

rsize = 0U;
EXPECT_EQ (nns_edge_queue_pop (queue_h, &result, &rsize), NNS_EDGE_ERROR_NONE);
len = nns_edge_queue_get_length (queue_h);
EXPECT_EQ (nns_edge_queue_get_length (queue_h, &len), NNS_EDGE_ERROR_NONE);
EXPECT_EQ (len, 1U);
EXPECT_EQ (result, data2);
EXPECT_EQ (dsize, rsize);
Expand All @@ -3483,23 +3483,23 @@ TEST_F(edgeQueue, pushData)

rsize = 0U;
EXPECT_EQ (nns_edge_queue_pop (queue_h, &result, &rsize), NNS_EDGE_ERROR_NONE);
len = nns_edge_queue_get_length (queue_h);
EXPECT_EQ (nns_edge_queue_get_length (queue_h, &len), NNS_EDGE_ERROR_NONE);
EXPECT_EQ (len, 0U);
EXPECT_EQ (result, data3);
EXPECT_EQ (dsize, rsize);
for (i = 0; i < 5U; i++)
EXPECT_EQ (((unsigned int *) result)[i], i + 30U);

EXPECT_EQ (nns_edge_queue_push (queue_h, data1, dsize, nns_edge_free), NNS_EDGE_ERROR_NONE);
len = nns_edge_queue_get_length (queue_h);
EXPECT_EQ (nns_edge_queue_get_length (queue_h, &len), NNS_EDGE_ERROR_NONE);
EXPECT_EQ (len, 1U);

EXPECT_EQ (nns_edge_queue_push (queue_h, data2, dsize, nns_edge_free), NNS_EDGE_ERROR_NONE);
len = nns_edge_queue_get_length (queue_h);
EXPECT_EQ (nns_edge_queue_get_length (queue_h, &len), NNS_EDGE_ERROR_NONE);
EXPECT_EQ (len, 2U);

EXPECT_EQ (nns_edge_queue_push (queue_h, data3, dsize, nns_edge_free), NNS_EDGE_ERROR_NONE);
len = nns_edge_queue_get_length (queue_h);
EXPECT_EQ (nns_edge_queue_get_length (queue_h, &len), NNS_EDGE_ERROR_NONE);
EXPECT_EQ (len, 3U);
}

Expand Down Expand Up @@ -3530,10 +3530,10 @@ TEST_F(edgeQueue, pushDataOnThread)
SAFE_FREE (result);
}

retry = 0U;
len = retry = 0U;
do {
usleep (20000);
len = nns_edge_queue_get_length (queue_h);
EXPECT_EQ (nns_edge_queue_get_length (queue_h, &len), NNS_EDGE_ERROR_NONE);
} while (len < 3U && retry++ < 200U);
}

Expand All @@ -3558,10 +3558,17 @@ TEST_F(edgeQueue, destroyInvalidParam01_n)
*/
TEST_F(edgeQueue, getLengthInvalidParam01_n)
{
unsigned int len;
unsigned int len = 0U;

len = nns_edge_queue_get_length (NULL);
EXPECT_EQ (len, 0U);
EXPECT_EQ (nns_edge_queue_get_length (NULL, &len), NNS_EDGE_ERROR_INVALID_PARAMETER);
}

/**
* @brief Get length of queue - invalid param.
*/
TEST_F(edgeQueue, getLengthInvalidParam02_n)
{
EXPECT_EQ (nns_edge_queue_get_length (queue_h, NULL), NNS_EDGE_ERROR_INVALID_PARAMETER);
}

/**
Expand All @@ -3571,7 +3578,7 @@ TEST_F(edgeQueue, setLimit)
{
void *data;
nns_size_t dsize;
unsigned int i, len;
unsigned int i, len = 0U;

dsize = sizeof (unsigned int);
data = malloc (dsize);
Expand All @@ -3582,7 +3589,7 @@ TEST_F(edgeQueue, setLimit)
for (i = 0; i < 5U; i++)
nns_edge_queue_push (queue_h, data, dsize, NULL);

len = nns_edge_queue_get_length (queue_h);
EXPECT_EQ (nns_edge_queue_get_length (queue_h, &len), NNS_EDGE_ERROR_NONE);
EXPECT_EQ (len, 3U);

SAFE_FREE (data);
Expand All @@ -3595,7 +3602,7 @@ TEST_F(edgeQueue, setLeaky)
{
void *data;
nns_size_t dsize, rsize;
unsigned int i, len;
unsigned int i, len = 0U;
int ret;

/* leaky option new */
Expand All @@ -3618,7 +3625,7 @@ TEST_F(edgeQueue, setLeaky)
}
}

len = nns_edge_queue_get_length (queue_h);
EXPECT_EQ (nns_edge_queue_get_length (queue_h, &len), NNS_EDGE_ERROR_NONE);
EXPECT_EQ (len, 3U);

EXPECT_EQ (nns_edge_queue_pop (queue_h, &data, &rsize), NNS_EDGE_ERROR_NONE);
Expand All @@ -3631,7 +3638,7 @@ TEST_F(edgeQueue, setLeaky)
EXPECT_EQ (*((unsigned int *) data), 3U);
SAFE_FREE (data);

len = nns_edge_queue_get_length (queue_h);
EXPECT_EQ (nns_edge_queue_get_length (queue_h, &len), NNS_EDGE_ERROR_NONE);
EXPECT_EQ (len, 0U);

/* leaky option old */
Expand All @@ -3646,7 +3653,7 @@ TEST_F(edgeQueue, setLeaky)
EXPECT_EQ (nns_edge_queue_push (queue_h, data, dsize, nns_edge_free), NNS_EDGE_ERROR_NONE);
}

len = nns_edge_queue_get_length (queue_h);
EXPECT_EQ (nns_edge_queue_get_length (queue_h, &len), NNS_EDGE_ERROR_NONE);
EXPECT_EQ (len, 3U);

EXPECT_EQ (nns_edge_queue_pop (queue_h, &data, &rsize), NNS_EDGE_ERROR_NONE);
Expand All @@ -3659,7 +3666,7 @@ TEST_F(edgeQueue, setLeaky)
EXPECT_EQ (*((unsigned int *) data), 5U);
SAFE_FREE (data);

len = nns_edge_queue_get_length (queue_h);
EXPECT_EQ (nns_edge_queue_get_length (queue_h, &len), NNS_EDGE_ERROR_NONE);
EXPECT_EQ (len, 0U);
}

Expand Down Expand Up @@ -3764,7 +3771,7 @@ TEST_F(edgeQueue, waitPopInvalidParam01_n)
void *data;
nns_size_t size;

EXPECT_EQ (nns_edge_queue_wait_pop (NULL, 0U, &data, &size), NNS_EDGE_ERROR_INVALID_PARAMETER);
EXPECT_EQ (nns_edge_queue_wait_pop (NULL, 10U, &data, &size), NNS_EDGE_ERROR_INVALID_PARAMETER);
}

/**
Expand All @@ -3774,7 +3781,7 @@ TEST_F(edgeQueue, waitPopInvalidParam02_n)
{
nns_size_t size;

EXPECT_EQ (nns_edge_queue_wait_pop (queue_h, 0U, NULL, &size), NNS_EDGE_ERROR_INVALID_PARAMETER);
EXPECT_EQ (nns_edge_queue_wait_pop (queue_h, 10U, NULL, &size), NNS_EDGE_ERROR_INVALID_PARAMETER);
}

/**
Expand All @@ -3784,7 +3791,7 @@ TEST_F(edgeQueue, waitPopInvalidParam03_n)
{
void *data;

EXPECT_EQ (nns_edge_queue_wait_pop (queue_h, 0U, &data, NULL), NNS_EDGE_ERROR_INVALID_PARAMETER);
EXPECT_EQ (nns_edge_queue_wait_pop (queue_h, 10U, &data, NULL), NNS_EDGE_ERROR_INVALID_PARAMETER);
}

/**
Expand Down
Loading