Skip to content

Commit d6d566c

Browse files
indent
1 parent 4dbec06 commit d6d566c

14 files changed

Lines changed: 390 additions & 281 deletions

File tree

CHANGES

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,12 @@ Released 2020-12-25
5353

5454
- Add counters
5555
- Add abort
56+
57+
Version 2.3
58+
===========
59+
60+
Released 2021-01-02
61+
62+
* New features:
63+
64+
- Pool refactoring

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
libdynamic v2.2
1+
libdynamic v2.3
22
===============
33

44
.. image:: https://travis-ci.org/fredrikwidlund/libdynamic.svg?branch=master
@@ -47,9 +47,9 @@ Build from release
4747

4848
.. code-block:: shell
4949
50-
wget https://github.com/fredrikwidlund/libdynamic/releases/download/v2.2.0/libdynamic-2.2.0.tar.gz
51-
tar fxz libdynamic-2.2.0.tar.gz
52-
cd libdynamic-2.2.0
50+
wget https://github.com/fredrikwidlund/libdynamic/releases/download/v2.3.0/libdynamic-2.3.0.tar.gz
51+
tar fxz libdynamic-2.3.0.tar.gz
52+
cd libdynamic-2.3.0
5353
./configure
5454
make install
5555

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AC_INIT([libdynamic], [2.2.0], [fredrik.widlund@gmail.com])
1+
AC_INIT([libdynamic],[2.3.0],[fredrik.widlund@gmail.com])
22
AC_CONFIG_AUX_DIR(autotools)
33
AC_CONFIG_MACRO_DIR([m4])
44
AM_INIT_AUTOMAKE([-Wall -Werror foreign no-define])
@@ -7,7 +7,7 @@ AM_INIT_AUTOMAKE([-Wall -Werror foreign no-define])
77
: ${CXXFLAGS="-Wall -Wextra -Wpedantic"}
88

99
AM_PROG_AR
10-
AC_PROG_LIBTOOL
10+
LT_INIT
1111
AM_PROG_CC_C_O
1212
AC_PROG_CXX
1313

examples/async.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,15 @@ struct state
1616
_Atomic size_t jobs;
1717
};
1818

19-
void async(void *state)
20-
{
21-
usleep(10000);
22-
((struct state *) state)->jobs++;
23-
}
24-
25-
core_status collect(core_event *event)
19+
static core_status async(core_event *event)
2620
{
2721
struct state *state = event->state;
28-
void *result;
29-
30-
do
31-
result = pool_collect(&state->pool, POOL_DONTWAIT);
32-
while (result);
3322

23+
if (event->type == POOL_REQUEST)
24+
{
25+
usleep(10000);
26+
state->jobs++;
27+
}
3428
return CORE_OK;
3529
}
3630

@@ -68,12 +62,12 @@ int main()
6862
struct state state = {0};
6963

7064
core_construct(&state.core);
71-
pool_construct(&state.pool);
65+
pool_construct(&state.pool, &state.core);
66+
pool_limits(&state.pool, 1, 32);
7267

7368
state.timer = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK | TFD_CLOEXEC);
7469
timerfd_settime(state.timer, 0, (struct itimerspec[]) {{{1, 0}, {1, 0}}}, NULL);
7570
core_add(&state.core, timeout, &state, state.timer, EPOLLIN | EPOLLET);
76-
core_add(&state.core, collect, &state, pool_fd(&state.pool), EPOLLIN | EPOLLET);
7771

7872
core_loop(&state.core);
7973

src/dynamic.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef DYNAMIC_H_INCLUDED
22
#define DYNAMIC_H_INCLUDED
33

4-
#define DYNAMIC_VERSION "2.2.0"
4+
#define DYNAMIC_VERSION "2.3.0"
55
#define DYNAMIC_VERSION_MAJOR 2
6-
#define DYNAMIC_VERSION_MINOR 2
6+
#define DYNAMIC_VERSION_MINOR 3
77
#define DYNAMIC_VERSION_PATCH 0
88

99
#define dynamic_likely(x) __builtin_expect(!!(x), 1)
@@ -27,8 +27,8 @@ extern "C" {
2727
#include <dynamic/map.h>
2828
#include <dynamic/maps.h>
2929
#include <dynamic/mapi.h>
30-
#include <dynamic/pool.h>
3130
#include <dynamic/core.h>
31+
#include <dynamic/pool.h>
3232

3333
#ifdef __cplusplus
3434
}

src/dynamic/buffer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef BUFFER_H_INCLUDED
2-
#define BUFFER_H_INCLUDED
1+
#ifndef DYNAMIC_BUFFER_H_INCLUDED
2+
#define DYNAMIC_BUFFER_H_INCLUDED
33

44
typedef struct buffer buffer;
55
struct buffer
@@ -29,4 +29,4 @@ void buffer_clear(buffer *);
2929
/* element access */
3030
void *buffer_data(buffer *);
3131

32-
#endif /* BUFFER_H_INCLUDED */
32+
#endif /* DYNAMIC_BUFFER_H_INCLUDED */

src/dynamic/core.c

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "buffer.h"
99
#include "vector.h"
1010
#include "core.h"
11+
#include "segment.h"
12+
#include "utility.h"
1113

1214
static __thread core core_default = {0};
1315

@@ -19,28 +21,13 @@ static core_status core_default_callback(core_event *event __attribute__((unused
1921
return CORE_OK;
2022
}
2123

22-
static uint64_t core_tsc(void)
23-
{
24-
#if defined(__x86_64__) || defined(__amd64__)
25-
uint32_t lo, hi;
26-
__asm__ volatile("RDTSC"
27-
: "=a"(lo), "=d"(hi));
28-
return (((uint64_t) hi) << 32) | lo;
29-
#else
30-
return 0;
31-
#endif
32-
}
33-
3424
static core *core_get(core *core)
3525
{
3626
return core ? core : &core_default;
3727
}
3828

3929
void core_construct(core *core)
4030
{
41-
if (core)
42-
*core = (struct core) {0};
43-
4431
core = core_get(core);
4532
if (!core->ref)
4633
{
@@ -85,20 +72,20 @@ void core_loop(core *core)
8572
uint64_t t0, t1;
8673
int n, i;
8774

88-
t1 = core_tsc();
75+
t1 = utility_tsc();
8976
core = core_get(core);
9077
while (core->active && core->errors == 0 && (core->handlers_active || vector_size(&core->next)))
9178
{
9279
for (i = 0; (size_t) i < vector_size(&core->next); i++)
9380
(void) core_dispatch(vector_at(&core->next, i), 0, 0);
9481
vector_clear(&core->next, NULL);
9582

96-
t0 = core_tsc();
83+
t0 = utility_tsc();
9784
core->time = 0;
9885
n = core->handlers_active ? epoll_wait(core->fd, events, CORE_MAX_EVENTS, -1) : 0;
9986
core->errors += n == -1;
10087
core->counters.awake += t0 - t1;
101-
t1 = core_tsc();
88+
t1 = utility_tsc();
10289
core->counters.sleep += t1 - t0;
10390
core->counters.polls++;
10491
core->counters.events += n;
@@ -158,7 +145,7 @@ void core_delete(core *core, int fd)
158145
core->handlers_active--;
159146
}
160147

161-
int core_next(core *core, core_callback *callback, void *state)
148+
core_id core_next(core *core, core_callback *callback, void *state)
162149
{
163150
core_handler handler = {.callback = callback, .state = state};
164151

@@ -167,7 +154,7 @@ int core_next(core *core, core_callback *callback, void *state)
167154
return vector_size(&core->next);
168155
}
169156

170-
void core_cancel(core *core, int id)
157+
void core_cancel(core *core, core_id id)
171158
{
172159
core_handler *handlers;
173160

@@ -179,7 +166,7 @@ void core_cancel(core *core, int id)
179166
handlers[id - 1] = core_handler_default;
180167
}
181168

182-
int core_errors(core *core)
169+
size_t core_errors(core *core)
183170
{
184171
core = core_get(core);
185172
return core->errors;

src/dynamic/core.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef CORE_H_INCLUDED
2-
#define CORE_H_INCLUDED
1+
#ifndef DYNAMIC_CORE_H_INCLUDED
2+
#define DYNAMIC_CORE_H_INCLUDED
33

44
#define CORE_MAX_EVENTS 16
55

@@ -9,6 +9,7 @@ enum core_status
99
CORE_ABORT = -1
1010
};
1111

12+
typedef uintptr_t core_id;
1213
typedef enum core_status core_status;
1314
typedef struct core_event core_event;
1415
typedef core_status core_callback(core_event *);
@@ -42,7 +43,7 @@ struct core
4243
size_t ref;
4344
int fd;
4445
int active;
45-
int errors;
46+
size_t errors;
4647
vector handlers;
4748
size_t handlers_active;
4849
vector next;
@@ -58,11 +59,11 @@ void core_loop(core *);
5859
void core_add(core *, core_callback *, void *, int, int);
5960
void core_modify(core *, int, int);
6061
void core_delete(core *, int);
61-
int core_next(core *, core_callback *, void *);
62-
void core_cancel(core *, int);
63-
int core_errors(core *);
62+
core_id core_next(core *, core_callback *, void *);
63+
void core_cancel(core *, core_id);
64+
size_t core_errors(core *);
6465
uint64_t core_now(core *);
6566
core_counters *core_get_counters(core *);
6667
void core_clear_counters(core *);
6768

68-
#endif /* CORE_H_INCLUDED */
69+
#endif /* DYNAMIC_CORE_H_INCLUDED */

src/dynamic/hash.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#ifndef HASH_H_INCLUDED
2-
#define HASH_H_INCLUDED
1+
#ifndef DYNAMIC_HASH_HINCLUDED
2+
#define DYNAMIC_HASH_HINCLUDED
33

44
uint64_t hash_string(char *);
55
uint64_t hash_data(void *, size_t);
66
uint64_t hash_uint64(uint64_t);
77

8-
#endif /* HASH_H_INCLUDED */
8+
#endif /* DYNAMIC_HASH_HINCLUDED */

0 commit comments

Comments
 (0)