1
0
Fork 0
mirror of https://github.com/endofunky/sidetiq.git synced 2022-11-09 13:53:30 -05:00

Remove C extension (addresses #4 and #5).

This commit is contained in:
Tobias Svensson 2013-06-24 09:54:33 +01:00
parent fc9cd12f20
commit 1ec6ac3bdf
8 changed files with 1 additions and 136 deletions

View file

@ -2,7 +2,6 @@ source 'https://rubygems.org'
group :development do
gem 'rake'
gem 'rake-compiler'
gem 'sinatra', require: false
gem 'slim', require: false
end

View file

@ -1,8 +1,5 @@
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'rake/extensiontask'
Rake::ExtensionTask.new('sidetiq_ext')
Rake::TestTask.new do |t|
t.pattern = 'test/**/test_*.rb'

View file

@ -1,4 +0,0 @@
require 'rbconfig'
require 'mkmf'
create_makefile('sidetiq_ext')

View file

@ -1,97 +0,0 @@
#include <ruby.h>
#include <assert.h>
#include "sidetiq_ext.h"
#ifdef __APPLE__
#include <sys/time.h>
#include <sys/resource.h>
#include <mach/mach.h>
#include <mach/clock.h>
#include <mach/mach_time.h>
#include <errno.h>
#include <unistd.h>
#include <sched.h>
#else
#include <time.h>
#endif
VALUE msidetiq;
VALUE esidetiq_error;
VALUE csidetiq_clock;
#ifdef __APPLE__
static mach_timebase_info_data_t clock_gettime_inf;
typedef enum {
CLOCK_REALTIME,
CLOCK_MONOTONIC,
CLOCK_PROCESS_CPUTIME_ID,
CLOCK_THREAD_CPUTIME_ID
} clockid_t;
int clock_gettime(clockid_t clk_id, struct timespec *tp)
{
kern_return_t ret;
clock_serv_t clk;
clock_id_t clk_serv_id;
mach_timespec_t tm;
uint64_t start, end, delta, nano;
int retval = -1;
switch (clk_id) {
case CLOCK_REALTIME:
case CLOCK_MONOTONIC:
clk_serv_id = clk_id == CLOCK_REALTIME ? CALENDAR_CLOCK : SYSTEM_CLOCK;
if (KERN_SUCCESS == (ret = host_get_clock_service(mach_host_self(), clk_serv_id, &clk))) {
if (KERN_SUCCESS == (ret = clock_get_time(clk, &tm))) {
tp->tv_sec = tm.tv_sec;
tp->tv_nsec = tm.tv_nsec;
retval = 0;
}
}
if (KERN_SUCCESS != ret) {
errno = EINVAL;
retval = -1;
}
break;
case CLOCK_PROCESS_CPUTIME_ID:
case CLOCK_THREAD_CPUTIME_ID:
start = mach_absolute_time();
if (clk_id == CLOCK_PROCESS_CPUTIME_ID) {
getpid();
} else {
sched_yield();
}
end = mach_absolute_time();
delta = end - start;
if (0 == clock_gettime_inf.denom) {
mach_timebase_info(&clock_gettime_inf);
}
nano = delta * clock_gettime_inf.numer / clock_gettime_inf.denom;
tp->tv_sec = nano * 1e-9;
tp->tv_nsec = nano - (tp->tv_sec * 1e9);
retval = 0;
break;
default:
errno = EINVAL;
retval = -1;
}
return retval;
}
#endif
static VALUE sidetiq_gettime(VALUE self)
{
struct timespec time;
assert(clock_gettime(CLOCK_REALTIME, &time) == 0);
return rb_time_nano_new(time.tv_sec, time.tv_nsec);
}
void Init_sidetiq_ext()
{
msidetiq = rb_define_module("Sidetiq");
esidetiq_error = rb_define_class_under(msidetiq, "Error", rb_eStandardError);
csidetiq_clock = rb_define_class_under(msidetiq, "Clock", rb_cObject);
rb_define_private_method(csidetiq_clock, "clock_gettime", sidetiq_gettime, 0);
}

View file

@ -1,17 +0,0 @@
#ifndef __SIDETIQ_EXT_H__
#define __SIDETIQ_EXT_H__
#include <ruby.h>
void Init_sidetiq_ext();
static VALUE sidetiq_gettime(VALUE self);
/* module Sidetiq */
extern VALUE msidetiq;
/* class Sidetiq::Error < StandardError */
extern VALUE esidetiq_error;
/* class Sidetiq::Clock */
extern VALUE csidetiq_clock;
#endif

View file

@ -7,9 +7,6 @@ require 'singleton'
require 'ice_cube'
require 'sidekiq'
# c extensions
require 'sidetiq_ext'
# internal
require 'sidetiq/config'
require 'sidetiq/clock'

View file

@ -67,9 +67,6 @@ module Sidetiq
# Public: Returns the current time used by the clock.
#
# Sidetiq::Clock uses `clock_gettime()` on UNIX systems and
# `mach_absolute_time()` on Mac OS X.
#
# Examples
#
# gettime
@ -77,7 +74,7 @@ module Sidetiq
#
# Returns a Time instance.
def gettime
Sidetiq.config.utc ? clock_gettime.utc : clock_gettime
Sidetiq.config.utc ? Time.now.utc : Time.now
end
# Public: Starts the clock unless it is already running.

View file

@ -1,7 +0,0 @@
require_relative 'helper'
class TestErrors < Sidetiq::TestCase
def test_error_superclass
assert_equal StandardError, Sidetiq::Error.superclass
end
end