Skip to content

Commit 55b5bf6

Browse files
committed
Added descriptions
1 parent 43cf9a3 commit 55b5bf6

File tree

4 files changed

+1276
-14
lines changed

4 files changed

+1276
-14
lines changed

UNITTESTS/events/equeue/test_equeue.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define DISPATCH_INFINITE -1
2727
#define ITERATION_TIMES 10
2828

29-
extern unsigned int global_time;
29+
extern unsigned int equeue_global_time;
3030

3131
class TestEqueue : public testing::Test {
3232
virtual void SetUp()
@@ -50,8 +50,8 @@ static void simple_func(void *p)
5050

5151
static void sloth_func(void *p)
5252
{
53-
global_time += 10;
54-
usleep(10000);
53+
// adding to equeue_global_time becouse this simulates that this function takes some time
54+
equeue_global_time += 10;
5555
(*(reinterpret_cast<uint8_t *>(p)))++;
5656
}
5757

@@ -125,8 +125,8 @@ static void nest_func(void *p)
125125
{
126126
struct nest *nst = reinterpret_cast<struct nest *>(p);
127127
equeue_call(nst->q, nst->cb, nst->data);
128-
global_time += 10;
129-
usleep(10000);
128+
// adding to equeue_global_time becouse this simulates that this function takes some time
129+
equeue_global_time += 10;
130130
}
131131

132132
static void *multithread_thread(void *p)
@@ -141,7 +141,6 @@ static void multithread_func(void *p)
141141
if ((*(reinterpret_cast<uint8_t *>(p))) < 200) {
142142
(*(reinterpret_cast<uint8_t *>(p)))++;
143143
}
144-
usleep(10);
145144
}
146145

147146
static void background_func(void *p, int ms)
@@ -171,8 +170,8 @@ static void simple_breaker(void *p)
171170
{
172171
struct count_and_queue *caq = reinterpret_cast<struct count_and_queue *>(p);
173172
equeue_break(caq->q);
174-
global_time += 10;
175-
usleep(10000);
173+
// adding to equeue_global_time becouse this simulates that this function takes some time
174+
equeue_global_time += 10;
176175
caq->p++;
177176
}
178177

UNITTESTS/stubs/EqueuePosix_stub.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@
1919

2020
#if defined(EQUEUE_PLATFORM_POSIX)
2121

22-
#include <time.h>
23-
#include <sys/time.h>
2422
#include <errno.h>
2523

26-
unsigned int global_time = 0;
24+
/*
25+
* Using global variable as a simulation of passing time. Use of sleep functions may cause problems with thread preempting, which can lead to bad timings.
26+
* This problem does not occur on targets.
27+
* This variable is only increased in equeue_sema_wait function and in functions that simulate pass of time.
28+
*/
29+
unsigned int equeue_global_time = 0;
2730

2831
// Tick operations
2932
void equeue_tick_init(void) {}
3033

3134
unsigned equeue_tick(void)
3235
{
33-
return global_time;
36+
return equeue_global_time;
3437
}
3538

3639

@@ -95,10 +98,11 @@ bool equeue_sema_wait(equeue_sema_t *s, int ms)
9598
pthread_cond_wait(&s->cond, &s->mutex);
9699
} else {
97100
for (int i = 0; i < ms; i++) {
98-
global_time++;
101+
equeue_global_time++;
99102
}
103+
// If ms == 0 increase time so functions don't get stuck in infinite loops.
100104
if (ms == 0) {
101-
global_time++;
105+
equeue_global_time++;
102106
}
103107
}
104108
}

0 commit comments

Comments
 (0)