Skip to content

Commit 69ff70a

Browse files
Ole-Hjalmar KristensenOle-Hjalmar Kristensen
authored andcommitted
Merge branch 'mysql-5.7' into mysql-trunk
2 parents 983aabb + 194ff94 commit 69ff70a

File tree

10 files changed

+123
-90
lines changed

10 files changed

+123
-90
lines changed

rapid/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/app_data.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@
3434
#include "synode_no.h"
3535
#include "xcom_vp_str.h"
3636

37+
define_xdr_funcs(synode_no)
38+
define_xdr_funcs(app_data_ptr)
39+
3740
static app_data_list nextp(app_data_list l);
41+
static unsigned long msg_count(app_data_ptr a);
3842

3943
/**
4044
Debug a single app_data struct.
@@ -358,7 +362,7 @@ void follow(app_data_list l, app_data_ptr p) {
358362
/**
359363
Count the number of messages in a list.
360364
*/
361-
unsigned long msg_count(app_data_ptr a) {
365+
static unsigned long msg_count(app_data_ptr a) {
362366
unsigned long n = 0;
363367
while (a) {
364368
n++;
@@ -367,7 +371,6 @@ unsigned long msg_count(app_data_ptr a) {
367371
return n;
368372
}
369373

370-
define_xdr_funcs(app_data_ptr)
371374

372375
/* {{{ Message constructors */
373376

rapid/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/app_data.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ app_data_ptr new_exit();
4848
app_data_ptr new_nodes(u_int n, node_address *names, cargo_type cargo);
4949
app_data_ptr new_reset(cargo_type type);
5050

51-
d_xdr_funcs(app_data_ptr) unsigned long msg_count(app_data_ptr a);
5251
void _replace_app_data_list(app_data_list target, app_data_ptr source);
5352
char *dbg_app_data(app_data_ptr a);
5453
void follow(app_data_list l, app_data_ptr p);

rapid/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/synode_no.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ extern "C" {
3232
#define SY_FMT_DEF "%x %" PRIu64 " %u"
3333
#define SY_MEM(s) (s).group_id, (uint64_t)(s).msgno, (s).node
3434

35-
d_xdr_funcs(synode_no)
36-
37-
int synode_eq(synode_no x, synode_no y);
35+
int synode_eq(synode_no x, synode_no y);
3836
int synode_gt(synode_no x, synode_no y);
3937
int synode_lt(synode_no x, synode_no y);
4038
static const synode_no null_synode = NULL_SYNODE;

rapid/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/task.c

Lines changed: 82 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,14 @@
6767
#include "task_net.h"
6868
#include "task_os.h"
6969
#include "xcom_cfg.h"
70+
#ifndef _WIN32
7071
#ifndef USE_SELECT
7172
#include <poll.h>
7273
#endif
74+
#endif
7375

7476
#include "retry.h"
77+
#include "xdr_utils.h"
7578

7679
extern char *pax_op_to_str(int x);
7780

@@ -89,17 +92,33 @@ struct iotasks {
8992
linkage tasks; /* OHKFIX Should be one each for read and write */
9093
};
9194
#else
95+
typedef struct {
96+
u_int pollfd_array_len;
97+
pollfd *pollfd_array_val;
98+
} pollfd_array;
99+
100+
typedef task_env* task_env_p;
101+
102+
typedef struct {
103+
u_int task_env_p_array_len;
104+
task_env_p *task_env_p_array_val;
105+
} task_env_p_array;
106+
107+
define_xdr_funcs(pollfd)
108+
define_xdr_funcs(task_env_p)
109+
92110
struct iotasks {
93111
int nwait;
94-
struct pollfd fd[MAXFILES];
95-
task_env *tasks[MAXFILES];
112+
pollfd_array fd;
113+
task_env_p_array tasks;
96114
};
97115
#endif
98116
int task_errno = 0;
99117
static task_env *extract_first_delayed();
100118
static task_env *task_ref(task_env *t);
101119
static task_env *task_unref(task_env *t);
102120
static void wake_all_io();
121+
static void task_sys_deinit();
103122

104123
/* Return time as seconds */
105124
static double _now = 0.0;
@@ -506,6 +525,7 @@ static void task_delete(task_env *t) {
506525
#if 1
507526
free(deactivate(t)); /* Deactivate and free task */
508527
#else
528+
deactivate(t);
509529
link_into(&t->l, &free_tasks);
510530
#endif
511531
active_tasks--;
@@ -536,7 +556,7 @@ task_env *task_deactivate(task_env *t) { return deactivate(t); }
536556
/* Set terminate flag and activate task */
537557
task_env *task_terminate(task_env *t) {
538558
if (t) {
539-
MAY_DBG(FN; PTREXP(t); STREXP(t->name));
559+
DBGOUT(FN; PTREXP(t); STREXP(t->name); NDBG(t->refcnt, d));
540560
t->terminate = KILL; /* Set terminate flag */
541561
activate(t); /* and get it running */
542562
}
@@ -577,6 +597,11 @@ static void iotasks_init(iotasks *iot) {
577597
link_init(&iot->tasks, type_hash("task_env"));
578598
}
579599

600+
static void iotasks_deinit(iotasks *iot)
601+
{
602+
DBGOUT(FN);
603+
}
604+
580605
#if TASK_DBUG_ON
581606
static void poll_debug() MY_ATTRIBUTE((unused));
582607
static void poll_debug() {
@@ -706,14 +731,20 @@ void remove_and_wakeup(int fd) {
706731
}
707732

708733
#else
709-
static int active_io() { return iot.nwait > 0; }
734+
static void iotasks_init(iotasks *iot)
735+
{
736+
DBGOUT(FN);
737+
iot->nwait = 0;
738+
init_pollfd_array(&iot->fd);
739+
init_task_env_p_array(&iot->tasks);
740+
}
710741

711-
static void iotasks_init(iotasks *iot) {
712-
int i;
742+
static void iotasks_deinit(iotasks *iot)
743+
{
744+
DBGOUT(FN);
713745
iot->nwait = 0;
714-
for (i = 0; i < MAXFILES; i++) {
715-
iot->tasks[i] = 0;
716-
}
746+
free_pollfd_array(&iot->fd);
747+
free_task_env_p_array(&iot->tasks);
717748
}
718749

719750
#if TASK_DBUG_ON
@@ -729,26 +760,27 @@ static void poll_debug() {
729760
}
730761
#endif
731762

732-
static void poll_wakeup(int i) {
733-
activate(task_unref(iot.tasks[i]));
734-
iot.tasks[i] = NULL;
763+
static void poll_wakeup(int i)
764+
{
765+
activate(task_unref(get_task_env_p(&iot.tasks,i)));
766+
set_task_env_p(&iot.tasks, NULL,i);
735767
iot.nwait--; /* Shrink array of pollfds */
736-
iot.fd[i] = iot.fd[iot.nwait];
737-
iot.tasks[i] = iot.tasks[iot.nwait];
768+
set_pollfd(&iot.fd, get_pollfd(&iot.fd,iot.nwait),i);
769+
set_task_env_p(&iot.tasks, get_task_env_p(&iot.tasks,iot.nwait),i);
738770
}
739771

740772
static int poll_wait(int ms) {
741773
result nfds = {0, 0};
774+
int wake = 0;
742775

743776
/* Wait at most ms milliseconds */
744777
MAY_DBG(FN; NDBG(ms, d));
745-
int wake = 0;
746778
if (ms < 0 || ms > 1000) ms = 1000; /* Wait at most 1000 ms */
747779
SET_OS_ERR(0);
748-
while ((nfds.val = poll(iot.fd, iot.nwait, ms)) == -1) {
749-
nfds.err = to_errno(GET_OS_ERR);
750-
if (nfds.err != SOCK_EINTR) {
751-
task_dump_err(nfds.err);
780+
while ((nfds.val = poll(iot.fd.pollfd_array_val, iot.nwait, ms)) == -1) {
781+
nfds.funerr = to_errno(GET_OS_ERR);
782+
if (nfds.funerr != SOCK_EINTR) {
783+
task_dump_err(nfds.funerr);
752784
MAY_DBG(FN; STRLIT("poll failed"));
753785
abort();
754786
}
@@ -760,11 +792,12 @@ static int poll_wait(int ms) {
760792
int interrupt = 0;
761793
while (i < iot.nwait) {
762794
interrupt =
763-
(iot.tasks[i]->time != 0.0 && iot.tasks[i]->time < task_now());
795+
(get_task_env_p(&iot.tasks,i)->time != 0.0 &&
796+
get_task_env_p(&iot.tasks,i)->time < task_now());
764797
if (interrupt || /* timeout ? */
765-
iot.fd[i].revents) {
798+
get_pollfd(&iot.fd,i).revents) {
766799
/* if(iot.fd[i].revents & POLLERR) abort(); */
767-
iot.tasks[i]->interrupt = interrupt;
800+
get_task_env_p(&iot.tasks,i)->interrupt = interrupt;
768801
poll_wakeup(i);
769802
wake = 1;
770803
} else {
@@ -779,28 +812,37 @@ static void add_fd(task_env *t, int fd, int op) {
779812
int events = 'r' == op ? POLLIN | POLLRDNORM : POLLOUT;
780813
MAY_DBG(FN; PTREXP(t); NDBG(fd, d); NDBG(op, d));
781814
assert(fd >= 0);
782-
assert(fd < MAXFILES);
783815
t->waitfd = fd;
784816
deactivate(t);
785817
task_ref(t);
786-
iot.tasks[iot.nwait] = t;
787-
iot.fd[iot.nwait].fd = fd;
788-
iot.fd[iot.nwait].events = events;
789-
iot.fd[iot.nwait].revents = 0;
818+
set_task_env_p(&iot.tasks, t, iot.nwait);
819+
{
820+
pollfd x;
821+
x.fd = fd;
822+
x.events = events;
823+
x.revents = 0;
824+
set_pollfd(&iot.fd, x, iot.nwait);
825+
}
790826
iot.nwait++;
791827
}
792828

793829
void unpoll(int i) {
794-
assert(i < MAXFILES);
795-
iot.tasks[i] = NULL;
796-
iot.fd[i].fd = -1;
830+
task_unref(get_task_env_p(&iot.tasks, i));
831+
set_task_env_p(&iot.tasks, NULL,i);
832+
{
833+
pollfd x;
834+
x.fd = -1;
835+
x.events = 0;
836+
x.revents = 0;
837+
set_pollfd(&iot.fd, x, i);
838+
}
797839
}
798840

799841
static void wake_all_io() {
800842
int i;
801843
for (i = 0; i < iot.nwait; i++) {
844+
activate(get_task_env_p(&iot.tasks,i));
802845
unpoll(i);
803-
activate(task_unref(iot.tasks[i]));
804846
}
805847
iot.nwait = 0;
806848
}
@@ -809,7 +851,7 @@ void remove_and_wakeup(int fd) {
809851
int i = 0;
810852
MAY_DBG(FN; NDBG(fd, d));
811853
while (i < iot.nwait) {
812-
if (iot.fd[i].fd == fd) {
854+
if (get_pollfd(&iot.fd,i).fd == fd) {
813855
poll_wakeup(i);
814856
} else {
815857
i++;
@@ -819,36 +861,6 @@ void remove_and_wakeup(int fd) {
819861

820862
#endif
821863
task_env *stack = NULL;
822-
/* Locks needed to get atomic reads and writes by protecting file descriptors
823-
while the task has been suspended by wait_io */
824-
static task_env *io_wait_locks[MAXFILES][2];
825-
/* purecov: begin deadcode */
826-
int is_locked(int fd) { return io_wait_locks[fd][0] || io_wait_locks[fd][1]; }
827-
828-
int lock_fd(int fd, task_env *t, int lock) {
829-
if (fd < 0) return 0;
830-
lock = lock != 'r';
831-
if (io_wait_locks[fd][lock]) {
832-
DBGOUT(FN; NDBG(fd, d); PTREXP(t); STRLIT(" failed"));
833-
return 0;
834-
} else {
835-
io_wait_locks[fd][lock] = t;
836-
return 1;
837-
}
838-
}
839-
840-
int unlock_fd(int fd, task_env *t, int lock) {
841-
if (fd < 0) return 0;
842-
lock = lock != 'r';
843-
if (io_wait_locks[fd][lock] != t) {
844-
DBGOUT(FN; NDBG(fd, d); PTREXP(t); STRLIT(" failed"));
845-
return 0;
846-
} else {
847-
io_wait_locks[fd][lock] = NULL;
848-
return 1;
849-
}
850-
}
851-
/* purecov: end */
852864

853865
task_env *wait_io(task_env *t, int fd, int op) {
854866
t->time = 0.0;
@@ -1158,6 +1170,7 @@ void task_loop() {
11581170
idle_time += seconds() - time;
11591171
}
11601172
}
1173+
task_sys_deinit();
11611174
}
11621175

11631176
static int init_sockaddr(char *server, struct sockaddr_in *sock_addr,
@@ -1471,6 +1484,13 @@ void task_sys_init() {
14711484
/* task_new(statistics_task, null_arg, "statistics_task", 1); */
14721485
}
14731486

1487+
1488+
static void task_sys_deinit()
1489+
{
1490+
DBGOUT(FN);
1491+
iotasks_deinit(&iot);
1492+
}
1493+
14741494
/* purecov: begin deadcode */
14751495
int is_running(task_env *t) { return t && t->terminate == RUN; }
14761496
/* purecov: end */

rapid/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/task.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extern "C" {
4040
Nonblocking IO and event handling need to be rewritten for each new OS.
4141
*/
4242

43-
#define USE_SELECT
43+
/* #define USE_SELECT */
4444
#ifdef TASK_EVENT_TRACE
4545
void add_base_event(double when, char const *file, int state);
4646
#define ADD_BASE_EVENT \
@@ -262,8 +262,6 @@ struct task_queue {
262262
};
263263
typedef struct task_queue task_queue;
264264

265-
#define MAXFILES MAXTASKS
266-
267265
#define _ep ((struct env *)(stack->sp->ptr))
268266

269267
#define TASK_ALLOC(pool, type) (task_allocate(pool, (unsigned int)sizeof(type)))
@@ -272,7 +270,7 @@ typedef struct task_queue task_queue;
272270
#define TASK_DEBUG(x) \
273271
if (stack->debug) { \
274272
DBGOUT(FN; STRLIT(x " task "); PTREXP((void *)stack); \
275-
STRLIT(stack->name)); \
273+
STRLIT(stack->name); NDBG(stack->sp->state,d));\
276274
}
277275
#else
278276
#define TASK_DEBUG(x)

rapid/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/task_os.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ static inline int hard_select_err(int err) {
5252
return err != 0 && from_errno(err) != WSAEINTR;
5353
}
5454

55+
56+
#if(_WIN32_WINNT < 0x0600)
57+
#error "Need _WIN32_WINNT >= 0x0600"
58+
#endif
59+
60+
typedef ULONG nfds_t;
61+
typedef struct pollfd pollfd;
62+
static inline int poll(pollfd * fds, nfds_t nfds, int timeout) {
63+
return WSAPoll(fds, nfds, timeout);
64+
}
65+
5566
#else
5667
#include <errno.h>
5768
#include <netdb.h>
@@ -87,6 +98,8 @@ static inline int hard_select_err(int err) {
8798
return from_errno(err) != 0 && from_errno(err) != EINTR;
8899
}
89100

101+
typedef struct pollfd pollfd;
102+
90103
#endif
91104

92105
extern void remove_and_wakeup(int fd);

0 commit comments

Comments
 (0)