Skip to content

Commit

Permalink
a likely concurrency issue (grumbles...)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardemslie committed Apr 25, 2013
1 parent 4c28648 commit 0ac3fa3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
49 changes: 41 additions & 8 deletions bindings/shapehandle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ void async_open(uv_work_t * job) {
}




void async_open_after(uv_work_t * job, int) {

HandleScope scope;
Expand Down Expand Up @@ -65,7 +67,25 @@ void async_open_after(uv_work_t * job, int) {
// and free() resources
//

}
};

void async_read_object(uv_work_t * job) {
printf("read\n");
sleep(1);

// looks like the async worker runs 4 at a time
// each will be reading data to/fro the same shapeHandl
// that will likely present an issue.

// UM.

// easier to prevent the

};

void async_read_object_after(uv_work_t * job, int) {
printf("done\n");
};

ShapeHandle::ShapeHandle() {};
ShapeHandle::~ShapeHandle() {};
Expand Down Expand Up @@ -162,7 +182,7 @@ void ShapeHandle::Init(Handle<Object> exports) {
Persistent<Function> constructor = Persistent<Function>::New(tpl->GetFunction());
exports->Set(String::NewSymbol("ShapeHandle"), constructor);

}
};

Handle<Value> ShapeHandle::New(const Arguments& args) {

Expand All @@ -172,7 +192,7 @@ Handle<Value> ShapeHandle::New(const Arguments& args) {
obj->Wrap(args.This());
return args.This();

}
};

Handle<Value> ShapeHandle::OpenAsync(const Arguments& args) {

Expand All @@ -182,7 +202,7 @@ Handle<Value> ShapeHandle::OpenAsync(const Arguments& args) {
if (args.Length() != 2) {
return ThrowException(
Exception::Error(String::New(
"Expected ShapeHandle::Open(<filename>,<callback>)"))
"Expected ShapeHandle::OpenAsync(<filename>,<callback>)"))
);
}

Expand All @@ -199,11 +219,24 @@ Handle<Value> ShapeHandle::OpenAsync(const Arguments& args) {

return Undefined();

}
};

Handle<Value> ShapeHandle::ReadObjectAsync(const Arguments& args) {

HandleScope scope;
return Undefined();
HandleScope scope;
uv_work_t * job;

}
if (args.Length() != 2) {
return ThrowException(
Exception::Error(String::New(
"Expected ShapeHandle::ReadObjectAsync(<shapeid>,<callback>)"))
);
}

ShapeHandle* obj = ObjectWrap::Unwrap<ShapeHandle>(args.This());
job = new uv_work_t;
job->data = obj;
uv_queue_work( uv_default_loop(), job, async_read_object, async_read_object_after );
return Undefined();

};
3 changes: 3 additions & 0 deletions bindings/shapehandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@ class ShapeHandle : public ObjectWrap {
void async_open(uv_work_t * job);
void async_open_after(uv_work_t * job, int);

void async_read_object(uv_work_t * job);
void async_read_object_after(uv_work_t * job, int);

#endif

0 comments on commit 0ac3fa3

Please sign in to comment.