Add rw lock to ensure metadata aren't updated while running STMT_PREPARE_RESPONSE

bsd_install_update
René Cannaò 8 years ago
parent 3b9e4a6150
commit a8e8859b79

@ -42,6 +42,7 @@ class MySQL_STMT_Global_info {
private:
void compute_hash();
public:
pthread_rwlock_t rwlock_;
uint64_t digest;
MYSQL_COM_QUERY_command MyComQueryCmd;
char * digest_text;

@ -136,6 +136,7 @@ MySQL_STMT_Global_info::MySQL_STMT_Global_info(uint64_t id, unsigned int h,
char *u, char *s, char *q,
unsigned int ql,
MYSQL_STMT *stmt, uint64_t _h) {
pthread_rwlock_init(&rwlock_, NULL);
statement_id = id;
hostgroup_id = h;
ref_count_client = 0;
@ -221,6 +222,7 @@ MySQL_STMT_Global_info::MySQL_STMT_Global_info(uint64_t id, unsigned int h,
void MySQL_STMT_Global_info::update_metadata(MYSQL_STMT *stmt) {
int i;
bool need_refresh = false;
pthread_rwlock_wrlock(&rwlock_);
if (
(num_params != stmt->param_count)
||
@ -400,6 +402,7 @@ void MySQL_STMT_Global_info::update_metadata(MYSQL_STMT *stmt) {
}
// till here is copied from constructor
}
pthread_rwlock_unlock(&rwlock_);
}
MySQL_STMT_Global_info::~MySQL_STMT_Global_info() {

@ -777,6 +777,7 @@ bool MySQL_Protocol::generate_STMT_PREPARE_RESPONSE(uint8_t sequence_id, MySQL_S
okpack[4]=0;
okpack[13]=0;
okpack[15]=0;
pthread_rwlock_rdlock(&stmt_info->rwlock_);
if (_stmt_id) {
memcpy(okpack+5,&_stmt_id,sizeof(uint32_t));
} else {
@ -817,6 +818,7 @@ bool MySQL_Protocol::generate_STMT_PREPARE_RESPONSE(uint8_t sequence_id, MySQL_S
generate_pkt_EOF(true,NULL,NULL,sid,0,setStatus);
sid++;
}
pthread_rwlock_unlock(&stmt_info->rwlock_);
return true;
}

Loading…
Cancel
Save