Skip to content

Commit

Permalink
added lock/unlock to rack plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto@debian32 committed Nov 12, 2011
1 parent 90fda2b commit 6800d2a
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions plugins/rack/rack_api.c
Expand Up @@ -27,6 +27,44 @@ VALUE rack_uwsgi_mem(VALUE *class) {

}

VALUE rack_uwsgi_lock(int argc, VALUE *argv, VALUE *class) {

int lock_num = 0;

if (argc > 0) {
Check_Type(argv[0], T_FIXNUM);
lock_num = NUM2INT(argv[0]);
}

if (lock_num < 0 || lock_num > uwsgi.locks) {
rb_raise(rb_eRuntimeError, "Invalid lock number");
return Qnil;
}

uwsgi_lock(uwsgi.user_lock[lock_num]);
return Qnil;
}

VALUE rack_uwsgi_unlock(int argc, VALUE *argv, VALUE *class) {

int lock_num = 0;

if (argc > 0) {
Check_Type(argv[0], T_FIXNUM);
lock_num = NUM2INT(argv[0]);
}

if (lock_num < 0 || lock_num > uwsgi.locks) {
rb_raise(rb_eRuntimeError, "Invalid lock number");
return Qnil;
}


uwsgi_unlock(uwsgi.user_lock[lock_num]);
return Qnil;
}




VALUE rack_uwsgi_cache_set(VALUE *class, VALUE rbkey, VALUE rbvalue) {
Expand Down Expand Up @@ -470,6 +508,10 @@ void uwsgi_rack_init_api() {
rb_define_module_function(rb_uwsgi_embedded, "setprocname", rack_uwsgi_setprocname, 1);
rb_define_module_function(rb_uwsgi_embedded, "mem", rack_uwsgi_mem, 0);

rb_define_module_function(rb_uwsgi_embedded, "lock", rack_uwsgi_lock, -1);
rb_define_module_function(rb_uwsgi_embedded, "unlock", rack_uwsgi_unlock, -1);


if (uwsgi.cache_max_items > 0) {
rb_define_module_function(rb_uwsgi_embedded, "cache_get", rack_uwsgi_cache_get, 1);
rb_define_module_function(rb_uwsgi_embedded, "cache_get!", rack_uwsgi_cache_get_exc, 1);
Expand Down

0 comments on commit 6800d2a

Please sign in to comment.