From e820e36aa3361d3b63cba1668a78ea8164ba7d7f Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Tue, 11 Jun 2013 14:58:21 +0100 Subject: [PATCH] Updated structure and added makefile --- compila | 6 - core/Makefile | 27 ++++ core/atomic.c | 49 ++++++ core/buffer.c | 151 ++++++++++++++++++ gateway.c => core/gateway.c | 51 +++--- .../gateway_mysql_protocol.c | 58 +++---- gw_utils.c => core/gw_utils.c | 48 +++--- core/spinlock.c | 98 ++++++++++++ utils.c => core/utils.c | 47 +++--- include/atomic.h | 32 ++++ include/buffer.h | 64 ++++++++ dcb.h => include/dcb.h | 12 +- gateway_mysql.h => include/gateway_mysql.h | 46 +++--- gw.h => include/gw.h | 0 mysql_protocol.h => include/mysql_protocol.h | 2 +- session.h => include/session.h | 2 +- include/spinlock.h | 51 ++++++ include/thread.h | 25 +++ 18 files changed, 642 insertions(+), 127 deletions(-) delete mode 100644 compila create mode 100644 core/Makefile create mode 100644 core/atomic.c create mode 100644 core/buffer.c rename gateway.c => core/gateway.c (88%) rename gateway_mysql_protocol.c => core/gateway_mysql_protocol.c (95%) rename gw_utils.c => core/gw_utils.c (80%) create mode 100644 core/spinlock.c rename utils.c => core/utils.c (96%) create mode 100644 include/atomic.h create mode 100644 include/buffer.h rename dcb.h => include/dcb.h (92%) rename gateway_mysql.h => include/gateway_mysql.h (83%) rename gw.h => include/gw.h (100%) rename mysql_protocol.h => include/mysql_protocol.h (98%) rename session.h => include/session.h (97%) create mode 100644 include/spinlock.h create mode 100644 include/thread.h diff --git a/compila b/compila deleted file mode 100644 index 009d1322d..000000000 --- a/compila +++ /dev/null @@ -1,6 +0,0 @@ -rm *.o -gcc -c gateway_mysql_protocol.c -gcc -c utils.c -gcc -c gw_utils.c -gcc -c gateway.c -gcc -o gateway gw_utils.o gateway.o utils.o gateway_mysql_protocol.o -lssl diff --git a/core/Makefile b/core/Makefile new file mode 100644 index 000000000..ddfd293b2 --- /dev/null +++ b/core/Makefile @@ -0,0 +1,27 @@ +# This file is distributed as part of the SkySQL Gateway. It is free +# software: you can redistribute it and/or modify it under the terms of the +# GNU General Public License as published by the Free Software Foundation, +# version 2. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Copyright SkySQL Ab 2013 + +CC=cc +CFLAGS=-c -I../include +SRCS= atomic.c buffer.c spinlock.c gateway.c gateway_mysql_protocol.c gw_utils.c utils.c +OBJ=$(SRCS:.c=.o) +LIBS=-lssl + +gateway: $(OBJ) + $(CC) $(LDFLAGS) $(OBJ) $(LIBS) -o $@ + +.c.o: + $(CC) $(CFLAGS) $< -o $@ diff --git a/core/atomic.c b/core/atomic.c new file mode 100644 index 000000000..aa3763025 --- /dev/null +++ b/core/atomic.c @@ -0,0 +1,49 @@ +/* + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + */ + +/* + * atomic.c - Implementation of atomic opertions for the gateway + * + * Revision History + * + * Date Who Description + * 10/06/13 Mark Riddoch Initial implementation + * + */ + +/* + * Implementation of an atomic add operation for the X86 processor. + * Adds a value to the contents of a location pointed to by the first parameter. + * The add operation is atomic and the return value is the value stored in the location + * prior to the operation. The number that is added may be signed, therefore atomic_subtract + * is merely an atomic add with a negative value. + * + * @param variable Pointer the the variable to add to + * @param value Value to be added + * @return The value of *variable before the add occured + */ +int +atomic_add(int *variable, int value) +{ + asm volatile( + "lock; xaddl %%eax, %2;" + :"=a" (value) + : "a" (value), "m" (*variable) + : "memory" ); + return value; +} diff --git a/core/buffer.c b/core/buffer.c new file mode 100644 index 000000000..ce8b879a6 --- /dev/null +++ b/core/buffer.c @@ -0,0 +1,151 @@ +/* + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + */ + +/* + * buffer.h - The Gateway buffer management functions + * + * Revision History + * + * Date Who Description + * 10/06/13 Mark Riddoch Initial implementation + * + */ +#include +#include + + +/* + * Allocate a new gateway buffer structure of size bytes. + * + * For now we allocate memory directly from malloc for buffer the management + * structure and the actual data buffer itself. We may swap at a future date + * to a more effecient mechanism. + * + * @param size The size in bytes of the data area required + * @return Pointer to the buffer structure or NULL if memory could not + * be allocated. + */ +GWBUF * +gwbuf_alloc(unsigned int size) +{ +GWBUF *rval; + + // Allocate the buffer header + if ((rval = (GWBUF *)malloc(sizeof(GWBUF))) == NULL) + { + return NULL; + } + + // Allocate the space for the actual data + if ((rval->data = (unsigned char *)malloc(size)) == NULL) + { + free(rval); + return NULL; + } + rval->start = rval->data; + rval->end = rval->start + size; + rval->next = NULL; + + return rval; +} + +/* + * Free a gateway buffer + * + * @param buf The buffer to free + */ +void +gwbuf_free(GWBUF *buf) +{ + free(buf->data); + free(buf); +} + +/* + * Append a buffer onto a linked list of buffer structures. + * + * This call should be made with the caller holding the lock for the linked + * list. + * + * @param head The current head of the linked list + * @param tail The new buffer to make the tail of the linked list + * @return The new head of the linked list + */ +GWBUF * +gwbuf_append(GWBUF *head, GWBUF *tail) +{ +GWBUF *ptr = head; + + if (!head) + return tail; + while (ptr->next) + { + ptr = ptr->next; + } + ptr->next = tail; + return head; +} + +/* + * Consume data from a buffer in the linked list. The assumption is to consume + * n bytes from the buffer chain. + * + * If after consuming the bytes from the first buffer that buffer becomes + * empty it will be freed and the linked list updated. + * + * The return value is the new head of the linked list. + * + * This call should be made with the caller holding the lock for the linked + * list. + * + * @param head The head of the linked list + * @param length The amount of data to consume + * @return The head of the linked list + */ +GWBUF * +gwbuf_consume(GWBUF *head, unsigned int length) +{ +GWBUF *rval = head; + + GWBUF_CONSUME(head, length); + if (GWBUF_EMPTY(head)) + { + rval = head->next; + gwbuf_free(head); + } + return rval; +} + +/* + * Return the number of bytes of data in the linked list. + * + * @param head The current head of the linked list + * @return The number of bytes of data in the linked list + */ +unsigned int +gwbuf_length(GWBUF *head) +{ +int rval = 0; + + while (head) + { + rval += GWBUF_LENGTH(head); + head = head->next; + } + return rval; +} diff --git a/gateway.c b/core/gateway.c similarity index 88% rename from gateway.c rename to core/gateway.c index 45f63af5a..d19f6e05f 100644 --- a/gateway.c +++ b/core/gateway.c @@ -1,32 +1,33 @@ /* -This file is distributed as part of the SkySQL Gateway. It is free -software: you can redistribute it and/or modify it under the terms of the -GNU General Public License as published by the Free Software Foundation, -version 2. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 51 -Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Copyright SkySQL Ab - -*/ - + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + * + */ /* -23-05-2013 -epoll loop test -Massimiliano Pinto -*/ + * Revision History + * + * Date Who Description + * 23-05-2013 Massimiliano Pinto epoll loop test + * + */ -#include "gw.h" -#include "dcb.h" -#include "session.h" +#include +#include +#include // epoll fd, global! static int epollfd; diff --git a/gateway_mysql_protocol.c b/core/gateway_mysql_protocol.c similarity index 95% rename from gateway_mysql_protocol.c rename to core/gateway_mysql_protocol.c index 0fe8faee4..37ae065c7 100644 --- a/gateway_mysql_protocol.c +++ b/core/gateway_mysql_protocol.c @@ -1,37 +1,37 @@ /* -This file is distributed as part of the SkySQL Gateway. It is free -software: you can redistribute it and/or modify it under the terms of the -GNU General Public License as published by the Free Software Foundation, -version 2. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 51 -Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Copyright SkySQL Ab - -*/ - + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + * + */ /* -23-05-2013 -Empty mysql_protocol_handling -1)send handshake in accept + * Revision History + * + * Date Who Description + * 23-05-2013 Massimiliano Pinto Empty mysql_protocol_handling + * 1)send handshake in accept + * 2) read data + * 3) alway send OK + * + */ -2) read data -3) alway send OK -Massimiliano Pinto -*/ - -#include "gw.h" -#include "dcb.h" -#include "session.h" +#include +#include +#include #define MYSQL_CONN_DEBUG //#undef MYSQL_CONN_DEBUG diff --git a/gw_utils.c b/core/gw_utils.c similarity index 80% rename from gw_utils.c rename to core/gw_utils.c index e854881b7..40415dba0 100644 --- a/gw_utils.c +++ b/core/gw_utils.c @@ -1,30 +1,32 @@ /* -This file is distributed as part of the SkySQL Gateway. It is free -software: you can redistribute it and/or modify it under the terms of the -GNU General Public License as published by the Free Software Foundation, -version 2. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 51 -Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Copyright SkySQL Ab - -*/ + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + * + */ /* -03-06-2013 -gateway utils -Massimiliano Pinto -*/ + * Revision History + * + * Date Who Description + * 03-06-2013 Massimiliano Pinto gateway utils + * + */ -#include "gw.h" -#include "dcb.h" +#include +#include /// // set ip address in sockect struct diff --git a/core/spinlock.c b/core/spinlock.c new file mode 100644 index 000000000..dcb73844c --- /dev/null +++ b/core/spinlock.c @@ -0,0 +1,98 @@ +/* + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + */ + +/* + * spinlock.c - Spinlock operations for the SkySQL Gateway + * + * Revision History + * + * Date Who Description + * 10/06/13 Mark Riddoch Initial implementation + * + */ + +#include +#include + +/* + * Initialise a spinlock. + * + * @param lock The spinlock to initialise. + */ +void +spinlock_init(SPINLOCK *lock) +{ + lock->lock = 0; +#ifdef DEBUG + lock->spins = 0; + lock->acquired = 0; +#endif +} + +/* + * Acquire a spinlock. + * + * @param lock The spinlock to acquire + */ +void +spinlock_acquire(SPINLOCK *lock) +{ + while (atomic_add(&(lock->lock), 1) != 0) + { + atomic_add(&(lock->lock), -1); +#ifdef DEBUG + atomic_add(&(lock->spins), 1); +#endif + } +#ifdef DEBUG + lock->acquired++; + lock->owner = THREAD_SHELF(); +#endif +} + +/* + * Acquire a spinlock if it is not already locked. + * + * @param lock The spinlock to acquire + * @return True ifthe spinlock was acquired, otherwise false + */ +int +spinlock_acquire_nowait(SPINLOCK *lock) +{ + if (atomic_add(&(lock->lock), 1) != 0) + { + atomic_add(&(lock->lock), -1); + return FALSE; + } +#ifdef DEBUG + lock->acquired++; + lock->owner = THREAD_SHELF(); +#endif + return TRUE; +} + +/* + * Release a spinlock. + * + * @param lock The spinlock to release + */ +void +spinlock_release(SPINLOCK *lock) +{ + atomic_add(&(lock->lock), -1); +} diff --git a/utils.c b/core/utils.c similarity index 96% rename from utils.c rename to core/utils.c index 0f4c68e57..1ae63e9fe 100644 --- a/utils.c +++ b/core/utils.c @@ -1,26 +1,35 @@ /* -This file is distributed as part of the SkySQL Gateway. It is free -software: you can redistribute it and/or modify it under the terms of the -GNU General Public License as published by the Free Software Foundation, -version 2. + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + * + */ -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -details. +/* + * Revision History + * + * Date Who Description + * 10/06/13 Massimiliano Pinto Initial implementation + * + */ -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 51 -Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -Copyright SkySQL Ab - -*/ - -#include "gw.h" -#include "dcb.h" -#include "session.h" -#include "mysql_protocol.h" +#include +#include +#include +#include #include // used in the hex2bin function diff --git a/include/atomic.h b/include/atomic.h new file mode 100644 index 000000000..7df155a11 --- /dev/null +++ b/include/atomic.h @@ -0,0 +1,32 @@ +#ifndef _ATOMIC_H +#define _ATOMIC_H +/* + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + */ + +/* + * The atomic operations used within the gateway + * + * Revision History + * + * Date Who Description + * 10/06/13 Mark Riddoch Initial implementation + * + */ + +extern int atomic_add(int *variable, int value); +#endif diff --git a/include/buffer.h b/include/buffer.h new file mode 100644 index 000000000..5819bb86e --- /dev/null +++ b/include/buffer.h @@ -0,0 +1,64 @@ +#ifndef _BUFFER_H +#define _BUFFER_H +/* + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + */ + +/* + * Definitions relating the gateway buffer manipulation facilities. + * These are used to store all data coming in form or going out to the client and the + * backend structures. + * + * The buffers are designed to be used in linked lists and such that they may be passed + * from one side of the gateway to another without the need to copy data. It may be the case + * that not all of the data in the buffer is valid, to this end a start and end pointer are + * included that point to the first valid byte in the buffer and the first byte after the + * last valid byte. This allows data to be consumed from either end of the buffer whilst + * still allowing for the copy free semantics of the buffering system. + * + * Revision History + * + * Date Who Description + * 10/06/13 Mark Riddoch Initial implementation + * + */ +typedef struct gwbuf { + struct gwbuf *next; // Next buffer in a linked chain of buffers + void *start; // Start of the valid data + void *end; // First byte after the valid data + unsigned char *data; // Physical memory that was allocated +} GWBUF; + +/* + * Macros to access the data in the buffers + */ +#define GWBUF_DATA(b) ((b)->start) +#define GWBUF_LENGTH(b) ((b)->end - (b)->start) +#define GWBUF_EMPTY(b) ((b)->start == (b)->end) +#define GWBUF_CONSUME(b, bytes) (b)->start += bytes + +/* + * Function prototypes for the API to maniplate the buffers + */ +extern GWBUF *gwbuf_alloc(unsigned int size); +extern void gwbuf_free(GWBUF *buf); +extern GWBUF *gwbuf_append(GWBUF *head, GWBUF *tail); +extern GWBUF *gwbuf_consume(GWBUF *head, unsigned int length); +extern unsigned int gwbuf_length(GWBUF *head); + + +#endif diff --git a/dcb.h b/include/dcb.h similarity index 92% rename from dcb.h rename to include/dcb.h index 59d3090ad..a37ccb738 100644 --- a/dcb.h +++ b/include/dcb.h @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab + * Copyright SkySQL Ab 2013 */ struct session; @@ -23,6 +23,13 @@ struct session; /* * The function pointer table used by descriptors to call relevant functions * within the protocol specific code. + * + * Revision History + * + * Date Who Description + * 1/06/13 Mark Riddoch Initial implementation + * + */ */ struct dcb; @@ -33,9 +40,10 @@ typedef struct gw_protocol { */ int (*read)(struct dcb *, int); int (*write)(struct dcb *, int); + int (*write_ready)(struct dcb *); int (*error)(struct dcb *, int); int (*accept)(struct dcb *, int); - //int (*close)(struct dcb *); + int (*close)(struct dcb *); } GWPROTOCOL; /* diff --git a/gateway_mysql.h b/include/gateway_mysql.h similarity index 83% rename from gateway_mysql.h rename to include/gateway_mysql.h index be4db5609..7aaeba34b 100644 --- a/gateway_mysql.h +++ b/include/gateway_mysql.h @@ -1,26 +1,30 @@ /* -This file is distributed as part of the SkySQL Gateway. It is free -software: you can redistribute it and/or modify it under the terms of the -GNU General Public License as published by the Free Software Foundation, -version 2. + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + * + */ -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 51 -Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Copyright SkySQL Ab - -*/ - -//////////////////////////////////////// -// MYSQL mysql protocol header file -// By Massimiliano Pinto 2012/2013 -//////////////////////////////////////// +/* + * MYSQL mysql protocol header file + * Revision History + * + * Date Who Description + * 10/06/13 Massimiliano Pinto Initial implementation + * + */ /* Protocol packing macros. */ #define gw_mysql_set_byte2(__buffer, __int) do { \ diff --git a/gw.h b/include/gw.h similarity index 100% rename from gw.h rename to include/gw.h diff --git a/mysql_protocol.h b/include/mysql_protocol.h similarity index 98% rename from mysql_protocol.h rename to include/mysql_protocol.h index 000fe3c0b..4eca2c0ba 100644 --- a/mysql_protocol.h +++ b/include/mysql_protocol.h @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab + * Copyright SkySQL Ab 2013 */ #ifndef MYSQL_SCRAMBLE_LEN diff --git a/session.h b/include/session.h similarity index 97% rename from session.h rename to include/session.h index 70ac34fac..bf711b2d1 100644 --- a/session.h +++ b/include/session.h @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab + * Copyright SkySQL Ab 2013 */ struct dcb; diff --git a/include/spinlock.h b/include/spinlock.h new file mode 100644 index 000000000..e2567cc3e --- /dev/null +++ b/include/spinlock.h @@ -0,0 +1,51 @@ +#ifndef _SPINLOCK_H +#define _SPINLOCK_H +/* + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + */ + +/* + * Spinlock implementation for ther gateway. + * + * Spinlocks are cheap locks that can be used to protect short code blocks, they are + * generally wasteful as any blocked threads will spin, consuming CPU cycles, waiting + * for the lock to be released. However they are useful in that they do not involve + * system calls and are light weight when the expected wait time for a lock is low. + */ +#include + +typedef struct spinlock { + int lock; +#if DEBUG + int spins; + int acquired; + THREAD owner; +#endif +} SPINLOCK; + +#ifndef TRUE +#define TRUE (1 == 1) +#endif +#ifndef FALSE +#define FALSE (1 == 0) +#endif + +extern void spinlock_init(SPINLOCK *lock); +extern void spinlock_acquire(SPINLOCK *lock); +extern int spinlock_acquire_nowait(SPINLOCK *lock); +extern void spinlock_release(SPINLOCK *lock); +#endif diff --git a/include/thread.h b/include/thread.h new file mode 100644 index 000000000..0ba83ce9b --- /dev/null +++ b/include/thread.h @@ -0,0 +1,25 @@ +#ifndef _THREAD_H +#define _THREAD_H +/* + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + */ +#include + +#define THREAD pthread_t +#define THREAD_SHELF pthread_self + +#endif