Skip to content

Commit

Permalink
Merge branch 'master' into over_locking
Browse files Browse the repository at this point in the history
Conflicts:
	ext/zookeeper_lib.c
  • Loading branch information
jmhodges committed Jan 31, 2011
2 parents e3fed3d + 3d5fdbd commit de8b628
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
22 changes: 13 additions & 9 deletions ext/zookeeper_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ static void free_zkrb_instance_data(struct zkrb_instance_data* ptr) {
}

static void print_zkrb_instance_data(struct zkrb_instance_data* ptr) {
fprintf(stderr, "zkrb_instance_data (%x) {\n", ptr);
fprintf(stderr, " zh = %x\n", ptr->zh);
fprintf(stderr, "zkrb_instance_data (%p) {\n", ptr);
fprintf(stderr, " zh = %p\n", ptr->zh);
fprintf(stderr, " { state = %d }\n", zoo_state(ptr->zh));
fprintf(stderr, " id = %llx\n", ptr->myid.client_id);
fprintf(stderr, " q = %x\n", ptr->queue);
fprintf(stderr, " q = %p\n", ptr->queue);
fprintf(stderr, "}\n");
}

Expand Down Expand Up @@ -237,18 +237,21 @@ static VALUE method_create(VALUE self, VALUE reqid, VALUE path, VALUE data, VALU
switch (call_type) {
case SYNC:
rc = zoo_create(zk->zh, RSTRING_PTR(path), data_ptr, data_len, aclptr, FIX2INT(flags), realpath, sizeof(realpath));
if (aclptr != NULL) deallocate_ACL_vector(aclptr);
break;
case ASYNC:
rc = zoo_acreate(zk->zh, RSTRING_PTR(path), data_ptr, data_len, aclptr, FIX2INT(flags), zkrb_string_callback, data_ctx);
if (aclptr != NULL) deallocate_ACL_vector(aclptr);
break;
default:
/* TODO(wickman) raise proper argument error */
return Qnil;
break;
}

if (aclptr) {
deallocate_ACL_vector(aclptr);
free(aclptr);
}

VALUE output = rb_ary_new();
rb_ary_push(output, INT2FIX(rc));
if (IS_SYNC(call_type) && rc == ZOK) {
Expand Down Expand Up @@ -364,18 +367,19 @@ static VALUE method_set_acl(VALUE self, VALUE reqid, VALUE path, VALUE acls, VAL
switch (call_type) {
case SYNC:
rc = zoo_set_acl(zk->zh, RSTRING_PTR(path), FIX2INT(version), aclptr);
deallocate_ACL_vector(aclptr);
break;
case ASYNC:
rc = zoo_aset_acl(zk->zh, RSTRING_PTR(path), FIX2INT(version), aclptr, zkrb_void_callback, data_ctx);
deallocate_ACL_vector(aclptr);
break;
default:
/* TODO(wickman) raise proper argument error */
return Qnil;
break;
}

deallocate_ACL_vector(aclptr);
free(aclptr);

return INT2FIX(rc);
}

Expand All @@ -400,12 +404,12 @@ static VALUE method_get_acl(VALUE self, VALUE reqid, VALUE path, VALUE async) {
break;
}

// do we need to deallocate the strings in the acl vector????
VALUE output = rb_ary_new();
rb_ary_push(output, INT2FIX(rc));
if (IS_SYNC(call_type) && rc == ZOK) {
rb_ary_push(output, zkrb_acl_vector_to_ruby(&acls));
rb_ary_push(output, zkrb_stat_to_rarray(&stat));
deallocate_ACL_vector(&acls);
}
return output;
}
Expand All @@ -422,7 +426,7 @@ static VALUE method_get_next_event(VALUE self) {
}

static VALUE method_has_events(VALUE self) {
VALUE rb_event = NULL;
VALUE rb_event;
FETCH_DATA_PTR(self, zk);

rb_event = zkrb_peek(zk->queue) != NULL ? Qtrue : Qfalse;
Expand Down
25 changes: 16 additions & 9 deletions ext/zookeeper_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ int ZKRBDebugging;
pthread_mutex_t zkrb_q_mutex = PTHREAD_MUTEX_INITIALIZER;

/* push/pop is a misnomer, this is a queue */
#warning [wickman] TODO enqueue, peek, dequeue => pthread_mutex_lock
void zkrb_enqueue(zkrb_queue_t *q, zkrb_event_t *elt) {
pthread_mutex_lock(&zkrb_q_mutex);
if (q == NULL || q->tail == NULL || q->dead) {
Expand Down Expand Up @@ -90,12 +89,13 @@ void zkrb_queue_free(zkrb_queue_t *queue) {
}

pthread_mutex_lock(&zkrb_q_mutex);
free(queue->head);
free(queue);
pthread_mutex_unlock(&zkrb_q_mutex);
}

zkrb_event_t *zkrb_event_alloc(void) {
zkrb_event_t *rv = (zkrb_event_t *) malloc(sizeof(zkrb_event_t));
zkrb_event_t *rv = (zkrb_event_t *) malloc(sizeof(zkrb_event_t));
return rv;
}

Expand All @@ -105,23 +105,27 @@ void zkrb_event_free(zkrb_event_t *event) {
struct zkrb_data_completion *data_ctx = event->completion.data_completion;
free(data_ctx->data);
free(data_ctx->stat);
free(data_ctx);
break;
}
case ZKRB_STAT: {
struct zkrb_stat_completion *stat_ctx = event->completion.stat_completion;
free(stat_ctx->stat);
free(stat_ctx);
break;
}
case ZKRB_STRING: {
struct zkrb_string_completion *string_ctx = event->completion.string_completion;
free(string_ctx->value);
free(string_ctx);
break;
}
case ZKRB_STRINGS: {
struct zkrb_strings_completion *strings_ctx = event->completion.strings_completion;
int k;
for (k = 0; k < strings_ctx->values->count; ++k) free(strings_ctx->values->data[k]);
free(strings_ctx->values);
free(strings_ctx);
break;
}
case ZKRB_STRINGS_STAT: {
Expand All @@ -130,6 +134,7 @@ void zkrb_event_free(zkrb_event_t *event) {
for (k = 0; k < strings_stat_ctx->values->count; ++k) free(strings_stat_ctx->values->data[k]);
free(strings_stat_ctx->values);
free(strings_stat_ctx->stat);
free(strings_stat_ctx);
break;
}
case ZKRB_ACL: {
Expand All @@ -139,11 +144,13 @@ void zkrb_event_free(zkrb_event_t *event) {
free(acl_ctx->acl);
}
free(acl_ctx->stat);
free(acl_ctx);
break;
}
case ZKRB_WATCHER: {
struct zkrb_watcher_completion *watcher_ctx = event->completion.watcher_completion;
free(watcher_ctx->path);
free(watcher_ctx);
break;
}
case ZKRB_VOID: {
Expand Down Expand Up @@ -260,10 +267,10 @@ void zkrb_print_calling_context(zkrb_calling_context *ctx) {

#define ZKH_SETUP_EVENT(qptr, eptr) \
zkrb_calling_context *ctx = (zkrb_calling_context *) calling_ctx; \
zkrb_event_t *eptr = zkrb_event_alloc(); \
zkrb_event_t *eptr = zkrb_event_alloc(); \
eptr->req_id = ctx->req_id; \
zkrb_queue_t *qptr = ctx->queue; \
if (eptr->req_id != ZKRB_GLOBAL_REQ) free(ctx);
if (eptr->req_id != ZKRB_GLOBAL_REQ) free(ctx)

void zkrb_state_callback(
zhandle_t *zh, int type, int state, const char *path, void *calling_ctx) {
Expand Down Expand Up @@ -495,7 +502,7 @@ struct Id zkrb_ruby_to_id(VALUE rubyid) {
}

if (ident != Qnil) {
id.id = malloc(RSTRING_LEN(ident) + 1);
id.id = malloc(RSTRING_LEN(ident) + 1);
strncpy(id.id, RSTRING_PTR(ident), RSTRING_LEN(ident));
id.id[RSTRING_LEN(ident)] = '\0';
} else {
Expand All @@ -506,17 +513,17 @@ struct Id zkrb_ruby_to_id(VALUE rubyid) {
}

VALUE zkrb_acl_vector_to_ruby(struct ACL_vector *acl_vector) {
int i = 0;
VALUE ary = rb_ary_new();
int i;
VALUE ary = rb_ary_new2(acl_vector->count);
for(i = 0; i < acl_vector->count; i++) {
rb_ary_push(ary, zkrb_acl_to_ruby(acl_vector->data+i));
}
return ary;
}

VALUE zkrb_string_vector_to_ruby(struct String_vector *string_vector) {
int i = 0;
VALUE ary = rb_ary_new();
int i;
VALUE ary = rb_ary_new2(string_vector->count);
for(i = 0; i < string_vector->count; i++) {
rb_ary_push(ary, rb_str_new2(string_vector->data[i]));
}
Expand Down

0 comments on commit de8b628

Please sign in to comment.