Remove spinlocks from GWBUF

The spinlock does not protect from or prevent misuse as buffers must not
be used concurrently by multiple threads.
This commit is contained in:
Markus Mäkelä
2018-07-01 15:51:34 +03:00
parent 709c394064
commit 295d59881e
2 changed files with 12 additions and 35 deletions

View File

@ -123,16 +123,15 @@ typedef struct
*/ */
typedef struct gwbuf typedef struct gwbuf
{ {
SPINLOCK gwbuf_lock;
struct gwbuf *next; /*< Next buffer in a linked chain of buffers */ struct gwbuf *next; /*< Next buffer in a linked chain of buffers */
struct gwbuf *tail; /*< Last buffer in a linked chain of buffers */ struct gwbuf *tail; /*< Last buffer in a linked chain of buffers */
void *start; /*< Start of the valid data */ void *start; /*< Start of the valid data */
void *end; /*< First byte after the valid data */ void *end; /*< First byte after the valid data */
SHARED_BUF *sbuf; /*< The shared buffer with the real data */ SHARED_BUF *sbuf; /*< The shared buffer with the real data */
uint32_t gwbuf_type; /*< buffer's data type information */
HINT *hint; /*< Hint data for this buffer */ HINT *hint; /*< Hint data for this buffer */
BUF_PROPERTY *properties; /*< Buffer properties */ BUF_PROPERTY *properties; /*< Buffer properties */
struct server *server; /*< The target server where the buffer is executed */ struct server *server; /*< The target server where the buffer is executed */
uint32_t gwbuf_type; /*< buffer's data type information */
} GWBUF; } GWBUF;
/*< /*<

View File

@ -79,7 +79,6 @@ gwbuf_alloc(unsigned int size)
sbuf->info = GWBUF_INFO_NONE; sbuf->info = GWBUF_INFO_NONE;
sbuf->bufobj = NULL; sbuf->bufobj = NULL;
spinlock_init(&rval->gwbuf_lock);
rval->start = &sbuf->data; rval->start = &sbuf->data;
rval->end = (void *)((char *)rval->start + size); rval->end = (void *)((char *)rval->start + size);
rval->sbuf = sbuf; rval->sbuf = sbuf;
@ -675,20 +674,16 @@ void gwbuf_add_buffer_object(GWBUF* buf,
void* data, void* data,
void (*donefun_fp)(void *)) void (*donefun_fp)(void *))
{ {
buffer_object_t** p_b;
buffer_object_t* newb;
CHK_GWBUF(buf); CHK_GWBUF(buf);
newb = (buffer_object_t *)MXS_MALLOC(sizeof(buffer_object_t)); buffer_object_t* newb = (buffer_object_t *)MXS_MALLOC(sizeof(buffer_object_t));
MXS_ABORT_IF_NULL(newb); MXS_ABORT_IF_NULL(newb);
newb->bo_id = id; newb->bo_id = id;
newb->bo_data = data; newb->bo_data = data;
newb->bo_donefun_fp = donefun_fp; newb->bo_donefun_fp = donefun_fp;
newb->bo_next = NULL; newb->bo_next = NULL;
/** Lock */
spinlock_acquire(&buf->gwbuf_lock); buffer_object_t** p_b = &buf->sbuf->bufobj;
p_b = &buf->sbuf->bufobj;
/** Search the end of the list and add there */ /** Search the end of the list and add there */
while (*p_b != NULL) while (*p_b != NULL)
{ {
@ -697,30 +692,20 @@ void gwbuf_add_buffer_object(GWBUF* buf,
*p_b = newb; *p_b = newb;
/** Set flag */ /** Set flag */
buf->sbuf->info |= GWBUF_INFO_PARSED; buf->sbuf->info |= GWBUF_INFO_PARSED;
/** Unlock */
spinlock_release(&buf->gwbuf_lock);
} }
void* gwbuf_get_buffer_object_data(GWBUF* buf, bufobj_id_t id) void* gwbuf_get_buffer_object_data(GWBUF* buf, bufobj_id_t id)
{ {
buffer_object_t* bo;
CHK_GWBUF(buf); CHK_GWBUF(buf);
/** Lock */
spinlock_acquire(&buf->gwbuf_lock); buffer_object_t* bo = buf->sbuf->bufobj;
bo = buf->sbuf->bufobj;
while (bo != NULL && bo->bo_id != id) while (bo != NULL && bo->bo_id != id)
{ {
bo = bo->bo_next; bo = bo->bo_next;
} }
/** Unlock */
spinlock_release(&buf->gwbuf_lock); return bo ? bo->bo_data : NULL;
if (bo)
{
return bo->bo_data;
}
return NULL;
} }
/** /**
@ -754,30 +739,23 @@ gwbuf_add_property(GWBUF *buf, const char *name, const char *value)
prop->name = my_name; prop->name = my_name;
prop->value = my_value; prop->value = my_value;
spinlock_acquire(&buf->gwbuf_lock);
prop->next = buf->properties; prop->next = buf->properties;
buf->properties = prop; buf->properties = prop;
spinlock_release(&buf->gwbuf_lock);
return true; return true;
} }
char * char *
gwbuf_get_property(GWBUF *buf, const char *name) gwbuf_get_property(GWBUF *buf, const char *name)
{ {
BUF_PROPERTY *prop; BUF_PROPERTY* prop = buf->properties;
spinlock_acquire(&buf->gwbuf_lock);
prop = buf->properties;
while (prop && strcmp(prop->name, name) != 0) while (prop && strcmp(prop->name, name) != 0)
{ {
prop = prop->next; prop = prop->next;
} }
spinlock_release(&buf->gwbuf_lock);
if (prop) return prop ? prop->value : NULL;
{
return prop->value;
}
return NULL;
} }
GWBUF * GWBUF *