-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* machinarium/channels: add get_size funcs Can be used in some debuggin workarounds Signed-off-by: rkhapov <[email protected]> * machinarium/wait_list* This patch adds mm_wait_list_t type which will be used as condition variable everywhere it needed. Ex.: wait_bus in router creates it's own wait_list, but with channels and therefore it has memory leaks because of inconsistency of it usages. Signed-off-by: rkhapov <[email protected]> * sources/route.h: fix wait_bus inconsistency route->wait_bus was implemented with channels. This leads to memory leaks because of inconsystency of queued clients notifications. This patch replaces channel with wait_list, which will not lead to memory leaks. Signed-off-by: rkhapov <[email protected]> * sources/config_reader.c: fix small memleak just to silence asan Signed-off-by: rkhapov <[email protected]> --------- Signed-off-by: rkhapov <[email protected]> Co-authored-by: rkhapov <[email protected]>
- Loading branch information
Showing
18 changed files
with
653 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include <machinarium.h> | ||
#include <odyssey_test.h> | ||
|
||
static inline void producer_coroutine(void *arg) | ||
{ | ||
machine_wait_list_t *wl = arg; | ||
|
||
machine_sleep(500); | ||
machine_wait_list_notify(wl); | ||
} | ||
|
||
static inline void consumer_coroutine(void *arg) | ||
{ | ||
machine_wait_list_t *wl = arg; | ||
|
||
uint64_t start, end, total_time; | ||
int rc; | ||
|
||
start = machine_time_ms(); | ||
rc = machine_wait_list_wait(wl, 1000); | ||
end = machine_time_ms(); | ||
test(rc == 0); | ||
total_time = end - start; | ||
test(total_time > 400 && total_time < 1000); | ||
} | ||
|
||
static inline void test_notify_after_wait(void *arg) | ||
{ | ||
(void)arg; | ||
|
||
machine_wait_list_t *wl = machine_wait_list_create(); | ||
|
||
int consumer_id; | ||
consumer_id = machine_coroutine_create(consumer_coroutine, wl); | ||
test(consumer_id != -1); | ||
|
||
int producer_id; | ||
producer_id = machine_coroutine_create(producer_coroutine, wl); | ||
test(producer_id != -1); | ||
|
||
machine_sleep(0); | ||
|
||
int rc; | ||
rc = machine_join(producer_id); | ||
test(rc == 0); | ||
|
||
rc = machine_join(consumer_id); | ||
test(rc == 0); | ||
|
||
machine_wait_list_destroy(wl); | ||
} | ||
|
||
void machinarium_test_wait_list_notify_after_wait() | ||
{ | ||
machinarium_init(); | ||
|
||
int id; | ||
id = machine_create("test_wait_list_notify_after_wait", | ||
test_notify_after_wait, NULL); | ||
test(id != -1); | ||
|
||
int rc; | ||
rc = machine_wait(id); | ||
test(rc != -1); | ||
|
||
machinarium_free(); | ||
} |
108 changes: 108 additions & 0 deletions
108
test/machinarium/test_wait_list_one_producer_multiple_consumers.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#include <machinarium.h> | ||
#include <odyssey_test.h> | ||
|
||
static inline void producer_coroutine(void *arg) | ||
{ | ||
machine_wait_list_t *wl = arg; | ||
|
||
uint64_t start, current; | ||
start = machine_time_ms(); | ||
current = start; | ||
|
||
while ((current - start) < 4000) { | ||
machine_wait_list_notify(wl); | ||
machine_sleep(300); | ||
current = machine_time_ms(); | ||
} | ||
} | ||
|
||
typedef struct { | ||
machine_wait_list_t *wl; | ||
int count; | ||
int64_t id; | ||
} consumer_arg_t; | ||
|
||
static inline void consumer_thread(void *arg) | ||
{ | ||
consumer_arg_t *ca = arg; | ||
machine_wait_list_t *wl = ca->wl; | ||
int *count = &ca->count; | ||
|
||
uint64_t start, current; | ||
int rc; | ||
start = machine_time_ms(); | ||
current = start; | ||
|
||
while ((current - start) < 3000) { | ||
rc = machine_wait_list_wait(wl, 1000); | ||
test(rc == 0); | ||
++(*count); | ||
current = machine_time_ms(); | ||
} | ||
} | ||
|
||
static inline void test_multiple_consumers(void *arg) | ||
{ | ||
(void)arg; | ||
|
||
machine_wait_list_t *wl = machine_wait_list_create(); | ||
|
||
int producer_id; | ||
producer_id = machine_coroutine_create(producer_coroutine, wl); | ||
test(producer_id != -1); | ||
|
||
consumer_arg_t a1, a2, a3; | ||
int c1, c2, c3; | ||
|
||
a1.count = a2.count = a3.count = 0; | ||
a1.wl = a2.wl = a3.wl = wl; | ||
|
||
c1 = machine_create("consumer1", consumer_thread, &a1); | ||
test(c1 != -1); | ||
a1.id = c1; | ||
|
||
c2 = machine_create("consumer2", consumer_thread, &a2); | ||
test(c2 != -1); | ||
a2.id = c2; | ||
|
||
c3 = machine_create("consumer3", consumer_thread, &a3); | ||
test(c3 != -1); | ||
a3.id = c3; | ||
|
||
machine_sleep(0); | ||
|
||
int rc; | ||
rc = machine_join(producer_id); | ||
test(rc == 0); | ||
|
||
rc = machine_wait(c1); | ||
test(rc == 0); | ||
|
||
rc = machine_wait(c2); | ||
test(rc == 0); | ||
|
||
rc = machine_wait(c3); | ||
test(rc == 0); | ||
|
||
test(a1.count >= 3); | ||
test(a2.count >= 3); | ||
test(a3.count >= 3); | ||
|
||
machine_wait_list_destroy(wl); | ||
} | ||
|
||
void machinarium_test_wait_list_one_producer_multiple_consumers() | ||
{ | ||
machinarium_init(); | ||
|
||
int id; | ||
id = machine_create("test_wait_list_one_producer_multiple_consumers", | ||
test_multiple_consumers, NULL); | ||
test(id != -1); | ||
|
||
int rc; | ||
rc = machine_wait(id); | ||
test(rc != -1); | ||
|
||
machinarium_free(); | ||
} |
100 changes: 100 additions & 0 deletions
100
test/machinarium/test_wait_list_one_producer_multiple_consumers_threads.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include <machinarium.h> | ||
#include <odyssey_test.h> | ||
|
||
static inline void producer_coroutine(void *arg) | ||
{ | ||
machine_wait_list_t *wl = arg; | ||
|
||
uint64_t start, current; | ||
start = machine_time_ms(); | ||
current = start; | ||
|
||
while ((current - start) < 4000) { | ||
machine_wait_list_notify(wl); | ||
machine_sleep(300); | ||
current = machine_time_ms(); | ||
} | ||
} | ||
|
||
typedef struct { | ||
machine_wait_list_t *wl; | ||
int count; | ||
int64_t id; | ||
} consumer_arg_t; | ||
|
||
static inline void consumer_coroutine(void *arg) | ||
{ | ||
consumer_arg_t *ca = arg; | ||
machine_wait_list_t *wl = ca->wl; | ||
int *count = &ca->count; | ||
|
||
uint64_t start, current; | ||
int rc; | ||
start = machine_time_ms(); | ||
current = start; | ||
|
||
while ((current - start) < 3000) { | ||
rc = machine_wait_list_wait(wl, 1000); | ||
test(rc == 0); | ||
++(*count); | ||
current = machine_time_ms(); | ||
} | ||
} | ||
|
||
static inline void test_multiple_consumers(void *arg) | ||
{ | ||
(void)arg; | ||
|
||
machine_wait_list_t *wl = machine_wait_list_create(); | ||
|
||
int producer_id; | ||
producer_id = machine_coroutine_create(producer_coroutine, wl); | ||
test(producer_id != -1); | ||
|
||
consumer_arg_t a1, a2, a3; | ||
int c1, c2, c3; | ||
|
||
a1.count = a2.count = a3.count = 0; | ||
a1.wl = a2.wl = a3.wl = wl; | ||
|
||
c1 = machine_coroutine_create(consumer_coroutine, &a1); | ||
test(c1 != -1); | ||
a1.id = c1; | ||
|
||
c2 = machine_coroutine_create(consumer_coroutine, &a2); | ||
test(c2 != -1); | ||
a2.id = c2; | ||
|
||
c3 = machine_coroutine_create(consumer_coroutine, &a3); | ||
test(c3 != -1); | ||
a3.id = c3; | ||
|
||
machine_sleep(0); | ||
|
||
int rc; | ||
rc = machine_join(producer_id); | ||
test(rc == 0); | ||
|
||
test(a1.count >= 3); | ||
test(a2.count >= 3); | ||
test(a3.count >= 3); | ||
|
||
machine_wait_list_destroy(wl); | ||
} | ||
|
||
void machinarium_test_wait_list_one_producer_multiple_consumers_threads() | ||
{ | ||
machinarium_init(); | ||
|
||
int id; | ||
id = machine_create( | ||
"test_wait_list_one_producer_multiple_consumers_threads", | ||
test_multiple_consumers, NULL); | ||
test(id != -1); | ||
|
||
int rc; | ||
rc = machine_wait(id); | ||
test(rc != -1); | ||
|
||
machinarium_free(); | ||
} |
Oops, something went wrong.