Skip to content

Commit

Permalink
update/revert renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Aug 12, 2024
1 parent 40f95b6 commit 7e70514
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 33 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
./go_channel
./go_sleep
./go_select
./go_work_group
./go_wait_group
./go_panic
./co_uv_fs
./co_uv_spawn
Expand All @@ -59,11 +59,11 @@ jobs:
- name: Run test examples
shell: cmd
run: |
cd build\Release
cd build\Debug
.\go_channel.exe
.\go_sleep.exe
.\go_select.exe
.\go_work_group.exe
.\go_wait_group.exe
.\go_panic.exe
.\co_uv_fs.exe
.\co_uv_spawn.exe
2 changes: 1 addition & 1 deletion .github/workflows/ci_qemu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
./go_channel
./go_sleep
./go_select
./go_work_group
./go_wait_group
./go_panic
./co_cpp_future_wait
./co_uv_fs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_qemu_others.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
./go_sleep
./go_select
if [ "${{ matrix.target }}" != "arm" ]; then
./go_work_group
./go_wait_group
./go_panic
fi
./co_uv_fs
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ There are five simple ways to create coroutines:
this is a shortcut to `coroutine_create(callable, *args, CO_STACK_SIZE)`.
2. `co_await(callable, *args);` returns your _value_ inside a generic union **value_t** type, after coroutine fully completes.
- This is a combine shortcut to four functions:
1. `work_group();` returns **hash-table** storing _coroutine-id's_ of any future created,
1. `wait_group();` returns **hash-table** storing _coroutine-id's_ of any future created,
2. `co_go(callable, *args);` calls, will end with a call to,
3. `co_wait(hash-table);` will suspend current coroutine, process coroutines until all are completed,
returns **hash-table** of results for,
4. `work_group_result(hash-table, coroutine-id);` returns your _value_ inside a generic union **value_t** type.
4. `wait_result(hash-table, coroutine-id);` returns your _value_ inside a generic union **value_t** type.
3. `co_execute(function, *args)` creates coroutine and immediately execute, does not return any value.
4. `co_event(callable, *args)` same as `co_await()` but for **libuv** or any event driven like library.
5. `co_handler(function, *handle, destructor)` initial setup for coroutine background handling of **http** _request/response_,
Expand Down Expand Up @@ -110,14 +110,14 @@ a terminated/finish status.

The initialization ends when `co_wait()` is called, as such current coroutine will pause, and
execution will begin for the group of coroutines, and wait for all to finished. */
C_API wait_group_t *work_group(void);
C_API wait_group_t *wait_group(void);

/* Pauses current coroutine, and begin execution for given coroutine wait group object, will
wait for all to finished. Returns hast table of results, accessible by coroutine id. */
C_API wait_result_t co_wait(wait_group_t *);

/* Returns results of the given completed coroutine id, value in union value_t storage format. */
C_API value_t work_group_result(wait_result_t *, int);
C_API value_t wait_result(wait_result_t *, int);

/* Creates an unbuffered channel, similar to golang channels. */
C_API channel_t *channel(void);
Expand Down Expand Up @@ -619,7 +619,7 @@ void_t worker(void_t arg)
int co_main(int argc, char **argv)
{
int cid[5];
wait_group_t *wg = work_group();
wait_group_t *wg = wait_group();
for (int i = 1; i <= 5; i++)
{
cid[i-1] = co_go(worker, &i);
Expand All @@ -628,10 +628,10 @@ int co_main(int argc, char **argv)

printf("\nWorker # %d returned: %d\n",
cid[2],
work_group_result(wgr, cid[2]).integer);
wait_result(wgr, cid[2]).integer);
printf("\nWorker # %d returned: %s\n",
cid[1],
work_group_result(wgr, cid[1]).string);
wait_result(wgr, cid[1]).string);
return 0;
}
```
Expand Down
14 changes: 7 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ There are five simple ways to create coroutines:
this is a shortcut to `coroutine_create(callable, *args, CO_STACK_SIZE)`.
2. `co_await(callable, *args);` returns your _value_ inside a generic union **value_t** type, after coroutine fully completes.
- This is a combine shortcut to four functions:
1. `work_group();` returns **hash-table** storing _coroutine-id's_ of any future created,
1. `wait_group();` returns **hash-table** storing _coroutine-id's_ of any future created,
2. `co_go(callable, *args);` calls, will end with a call to,
3. `co_wait(hash-table);` will suspend current coroutine, process coroutines until all are completed,
returns **hash-table** of results for,
4. `work_group_result(hash-table, coroutine-id);` returns your _value_ inside a generic union **value_t** type.
4. `wait_result(hash-table, coroutine-id);` returns your _value_ inside a generic union **value_t** type.
3. `co_execute(function, *args)` creates coroutine and immediately execute, does not return any value.
4. `co_event(callable, *args)` same as `co_await()` but for **libuv** or any event driven like library.
5. `co_handler(function, *handle, destructor)` initial setup for coroutine background handling of **http** _request/response_,
Expand Down Expand Up @@ -110,14 +110,14 @@ a terminated/finish status.

The initialization ends when `co_wait()` is called, as such current coroutine will pause, and
execution will begin for the group of coroutines, and wait for all to finished. */
C_API wait_group_t *work_group(void);
C_API wait_group_t *wait_group(void);

/* Pauses current coroutine, and begin execution for given coroutine wait group object, will
wait for all to finished. Returns hast table of results, accessible by coroutine id. */
C_API wait_result_t co_wait(wait_group_t *);

/* Returns results of the given completed coroutine id, value in union value_t storage format. */
C_API value_t work_group_result(wait_result_t *, int);
C_API value_t wait_result(wait_result_t *, int);

/* Creates an unbuffered channel, similar to golang channels. */
C_API channel_t *channel(void);
Expand Down Expand Up @@ -634,18 +634,18 @@ void_t worker(void_t arg) {
int co_main(int argc, char **argv)
{
int cid[5];
wait_group_t *wg = work_group();
wait_group_t *wg = wait_group();
for (int i = 1; i <= 5; i++) {
cid[i-1] = co_go(worker, &i);
}
wait_result_t *wgr = co_wait(wg);
printf("\nWorker # %d returned: %d\n",
cid[2],
work_group_result(wgr, cid[2]).integer);
wait_result(wgr, cid[2]).integer);
printf("\nWorker # %d returned: %s\n",
cid[1],
work_group_result(wgr, cid[1]).string);
wait_result(wgr, cid[1]).string);
return 0;
}
</code></pre>
Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8...3.14)

add_subdirectory(echo-server)

set(TARGET_LIST child co_json co_cpp_future_wait co_cpp_future test_delay chan_3 primes co_uv_fs co_uv_stream co_uv_listen co_uv_connect co_uv_spawn co_uv_url co_http_request co_http_response co_parse_http go_channel go_sleep go_select go_work_group go_panic go_readfile go_multi_args benchmark)
set(TARGET_LIST child co_json co_cpp_future_wait co_cpp_future test_delay chan_3 primes co_uv_fs co_uv_stream co_uv_listen co_uv_connect co_uv_spawn co_uv_url co_http_request co_http_response co_parse_http go_channel go_sleep go_select go_wait_group go_panic go_readfile go_multi_args benchmark)
foreach (TARGET ${TARGET_LIST})
add_executable(${TARGET} ${TARGET}.c)
target_link_libraries(${TARGET} coroutine)
Expand Down
4 changes: 2 additions & 2 deletions examples/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ int co_main(int argc, char **argv) {
if (argc > 1)
numRoutines = (u32)atoi(argv[1]);

work_group_capacity(Kb(25));
wait_group_t *wg = work_group();
wait_capacity(Kb(25));
wait_group_t *wg = wait_group();
for (i = 0; i < numRoutines; i++) {
co_go(func, NULL);
}
Expand Down
6 changes: 3 additions & 3 deletions examples/go_work_group.c → examples/go_wait_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ void *worker(void *arg) {
int co_main(int argc, char **argv) {
int cid[100], i;

wait_group_t *wg = work_group();
wait_group_t *wg = wait_group();
for (i = 0; i < 100; i++) {
cid[i] = co_go(worker, args_for("i", i));
}
wait_result_t *wgr = co_wait(wg);

printf("\nWorker # %d returned: %d\n", cid[2], work_group_result(wgr, cid[2]).integer);
printf("\nWorker # %d returned: %s\n", cid[1], work_group_result(wgr, cid[1]).char_ptr);
printf("\nWorker # %d returned: %d\n", cid[2], wait_result(wgr, cid[2]).integer);
printf("\nWorker # %d returned: %s\n", cid[1], wait_result(wgr, cid[1]).char_ptr);
return 0;
}
6 changes: 3 additions & 3 deletions include/coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -909,17 +909,17 @@ C_API ht_string_t *ht_string_init(void);
All coroutines here behaves like regular functions, meaning they return values, and indicate a terminated/finish status.
The initialization ends when `co_wait()` is called, as such current coroutine will pause, and execution will begin for the group of coroutines, and wait for all to finished. */
C_API wait_group_t *work_group(void);
C_API wait_group_t *wait_group(void);

/* Set global wait group `hash table` initial capacity. */
C_API void work_group_capacity(u32);
C_API void wait_capacity(u32);

/* Pauses current coroutine, and begin execution for given coroutine wait group object, will wait for all to finish.
Returns hast table of results, accessible by coroutine id. */
C_API wait_result_t *co_wait(wait_group_t *);

/* Returns results of the given completed coroutine id, value in union value_t storage format. */
C_API value_t work_group_result(wait_result_t *, u32);
C_API value_t wait_result(wait_result_t *, u32);

C_API void co_result_set(routine_t *, void_t);
C_API void co_plain_set(routine_t *, size_t);
Expand Down
10 changes: 5 additions & 5 deletions src/coroutine.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ CO_FORCE_INLINE bool co_terminated(routine_t *co) {
}

value_t co_await(callable_t fn, void_t arg) {
wait_group_t *wg = work_group();
wait_group_t *wg = wait_group();
u32 cid = co_go(fn, arg);
wait_result_t *wgr = co_wait(wg);
if (is_empty(wgr))
return;

return work_group_result(wgr, cid);
return wait_result(wgr, cid);
}

value_t co_event(callable_t fn, void_t arg) {
Expand Down Expand Up @@ -185,11 +185,11 @@ void co_process(func_t fn, void_t args) {
hash_free(eg);
}

CO_FORCE_INLINE void work_group_capacity(u32 size) {
CO_FORCE_INLINE void wait_capacity(u32 size) {
hash_capacity(size + (size * 0.333334));
}

wait_group_t *work_group(void) {
wait_group_t *wait_group(void) {
routine_t *c = co_active();
wait_group_t *wg = ht_group_init();
c->wait_active = true;
Expand Down Expand Up @@ -262,7 +262,7 @@ wait_result_t *co_wait(wait_group_t *wg) {
return has_erred ? NULL : wgr;
}

value_t work_group_result(wait_result_t *wgr, u32 cid) {
value_t wait_result(wait_result_t *wgr, u32 cid) {
if (is_empty(wgr))
return;

Expand Down

0 comments on commit 7e70514

Please sign in to comment.