Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2b43ad5a09c4
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d7e914981ffa
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Nov 22, 2014

  1. Copy the full SHA
    e986ba5 View commit details
  2. Copy the full SHA
    d7e9149 View commit details
Showing with 61 additions and 11 deletions.
  1. +1 −1 gems_list.txt
  2. +15 −3 vm/builtin/fsevent.cpp
  3. +29 −7 vm/console.cpp
  4. +4 −0 vm/console.hpp
  5. +12 −0 vm/util/atomic.hpp
2 changes: 1 addition & 1 deletion gems_list.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bundler-1.7.4.gem
bundler-1.7.7.gem
ffi2-generators-0.1.1.gem
json-1.8.1.gem
minitest-4.7.5.gem
18 changes: 15 additions & 3 deletions vm/builtin/fsevent.cpp
Original file line number Diff line number Diff line change
@@ -87,11 +87,21 @@ namespace rubinius {
return fsevent;
}

#define RBX_FSEVENT_MASK (IN_MODIFY \
| IN_CLOSE_WRITE \
| IN_CLOSE_NOWRITE \
| IN_DELETE \
| IN_ONESHOT)

static int fsevent_add_watch(int fd, const char* path) {
return inotify_add_watch(fd, path, RBX_FSEVENT_MASK);
}

Object* FSEvent::watch_file(STATE, Fixnum* fd, String* path) {
this->fileno(state, fd);
this->path(state, path);

inotify_add_watch(in_, path->c_str(state), IN_MODIFY | IN_ONESHOT);
fsevent_add_watch(in_, path->c_str(state));
watch_set_ = true;

return cNil;
@@ -114,14 +124,16 @@ namespace rubinius {
int status;

if(!watch_set_) {
inotify_add_watch(in_, path_->c_str(state), IN_MODIFY | IN_ONESHOT);
fsevent_add_watch(in_, path_->c_str(state));
} else {
watch_set_ = false;
}

status = read(in_, buf, RBX_FSEVENT_BUF_LEN);

if(status <= 0) return cNil;
if(status <= 0 || !(((struct inotify_event*)buf)->mask & IN_MODIFY)) {
return cNil;
}

return cTrue;
}
36 changes: 29 additions & 7 deletions vm/console.cpp
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@

#include "dtrace/dtrace.h"

#include "util/atomic.hpp"
#include "util/file.hpp"
#include "util/logger.hpp"

@@ -156,6 +157,11 @@ namespace rubinius {
fsevent_.set(fsevent);
}

void Console::reset(STATE) {
close_files(false);
setup_files(state);
}

void Console::start(STATE) {
initialize(state);
setup_files(state);
@@ -205,9 +211,11 @@ namespace rubinius {
if(request_vm_) {
wakeup();

void* return_value;
pthread_t os = request_vm_->os_thread();
pthread_join(os, &return_value);
if(atomic::poll(request_running_, false)) {
void* return_value;
pthread_t os = request_vm_->os_thread();
pthread_join(os, &return_value);
}

request_vm_ = NULL;
}
@@ -218,9 +226,11 @@ namespace rubinius {

response_cond_.signal();

void* return_value;
pthread_t os = response_vm_->os_thread();
pthread_join(os, &return_value);
if(atomic::poll(response_running_, false)) {
void* return_value;
pthread_t os = response_vm_->os_thread();
pthread_join(os, &return_value);
}

response_vm_ = NULL;
}
@@ -291,14 +301,20 @@ namespace rubinius {
RUBINIUS_THREAD_START(const_cast<RBX_DTRACE_CONST char*>(thread_name),
state->vm()->thread_id(), 1);

request_running_ = true;

state->vm()->thread->hard_unlock(state, gct, 0);
state->gc_independent(gct, 0);

while(!request_exit_) {
Object* status = fsevent_.get()->wait_for_event(state);

if(request_exit_) break;
if(status->nil_p()) continue;

if(status->nil_p()) {
reset(state);
continue;
}

char* request = read_request(state);

@@ -310,6 +326,8 @@ namespace rubinius {
}
}

request_running_ = false;

state->gc_dependent(gct, 0);

RUBINIUS_THREAD_STOP(const_cast<RBX_DTRACE_CONST char*>(thread_name),
@@ -349,6 +367,8 @@ namespace rubinius {
RUBINIUS_THREAD_START(const_cast<RBX_DTRACE_CONST char*>(thread_name),
state->vm()->thread_id(), 1);

response_running_ = true;

state->vm()->thread->hard_unlock(state, gct, 0);
state->gc_dependent(gct, 0);

@@ -392,6 +412,8 @@ namespace rubinius {
}
}

response_running_ = false;

RUBINIUS_THREAD_STOP(const_cast<RBX_DTRACE_CONST char*>(thread_name),
state->vm()->thread_id(), 1);
}
4 changes: 4 additions & 0 deletions vm/console.hpp
Original file line number Diff line number Diff line change
@@ -39,6 +39,9 @@ namespace rubinius {
bool request_exit_;
bool response_exit_;

bool request_running_;
bool response_running_;

RequestList* request_list_;

utilities::thread::Mutex list_lock_;
@@ -56,6 +59,7 @@ namespace rubinius {
void start(STATE);
void initialize(STATE);
void setup_files(STATE);
void reset(STATE);
void run(STATE);

void start_threads(STATE);
12 changes: 12 additions & 0 deletions vm/util/atomic.hpp
Original file line number Diff line number Diff line change
@@ -80,6 +80,18 @@ namespace atomic {
#endif
}

inline bool poll(bool& flag, bool expected) {
struct timespec ts = {0, 1000};

for(int limit = 0; limit < 100; limit++) {
memory_barrier();
if(flag == expected) return true;
nanosleep(&ts, NULL);
}

return false;
}

inline bool compare_and_swap(uint32_t* ptr, uint32_t old_val, uint32_t new_val) {
#if defined(GCC_SYNC)
return __sync_bool_compare_and_swap(ptr, old_val, new_val);