Skip to content

Instantly share code, notes, and snippets.

View trevnorris's full-sized avatar

Trevor Norris trevnorris

View GitHub Profile
@trevnorris
trevnorris / uv-loop-notes.txt
Last active October 10, 2022 15:45
rough notes on the linux side of the libuv event loop
uv_run
- uv__update_time(): Update time with millisecond precision.
- uv__run_timers(): Loop through "heap" and run timers whose timeout > time.
- uv__run_pending(): Run all callbacks on the pending_queue. Remove each item
from the queue when run.
@trevnorris
trevnorris / irhydra-fix.diff
Created October 1, 2014 20:58
Patch to fix IRHydra support by back porting the patch to 3.28
diff --git a/deps/v8/src/codegen.cc b/deps/v8/src/codegen.cc
index 6b12d64..a24220d 100644
--- a/deps/v8/src/codegen.cc
+++ b/deps/v8/src/codegen.cc
@@ -190,7 +190,7 @@ void CodeGenerator::PrintCode(Handle<Code> code, CompilationInfo* info) {
function->end_position() - function->start_position() + 1;
for (int i = 0; i < source_len; i++) {
if (stream.HasMore()) {
- os << AsUC16(stream.GetNext());
+ os << AsReversiblyEscapedUC16(stream.GetNext());
@trevnorris
trevnorris / falling-body.js
Last active August 29, 2015 14:08
Crazy physics done in integer space, to prevent floating point calculations.
// Distance is in 100nm segments. Will be rounding values in order to keep them
// in integer space. Hopefully no values exceed +/-2^53.
var D = 1e7;
var G = 9.80665 * D;
// Amount of time to calculate for.
var T = 10;
// Number of segments to divide time (60 fps).
var S = 60 * T;
// Initial velocity in m/sec
diff --git a/lib/domain.js b/lib/domain.js
index afaa922..39e90f4 100644
--- a/lib/domain.js
+++ b/lib/domain.js
@@ -33,7 +33,11 @@ var endMethods = ['end', 'abort', 'destroy', 'destroySoon'];
events.usingDomains = true;
// let the process know we're using domains
-process._usingDomains();
+// The return value let's us know whether --abort-on-uncaught-exception was
var dgram = require('dgram');
var fork = require('child_process').fork;
var PORT = 7845;
var ITER = 1e4;
var MS = 100;
var SHUTDOWN = 1000 * 60;
var cntr = 0;
if (process.argv[2] === 'child') {
var async_wrap = process.binding('async_wrap');
var b = {};
function initHook() {
this._asyncQueue = {};
}
function preHook() {
throw new Error('preHook');
}
diff --git a/src/haywire/http_server.c b/src/haywire/http_server.c
index 6f18b9b..3591aca 100644
--- a/src/haywire/http_server.c
+++ b/src/haywire/http_server.c
@@ -78,6 +78,7 @@ void free_http_connection(http_connection* connection)
free_http_request(connection->request);
}
+ free(connection->thread);
free(connection);
@trevnorris
trevnorris / sem-bounce.c
Last active August 29, 2015 14:10
bounce back and forth between threads using semaphores
/* Compiled with
* clang -pthread -fno-omit-frame-pointer -Wall -g -fstrict-aliasing -O3 \
* -o sem-bounce sem-bounce.c libuv.a -Iuv/include
*/
#include "uv.h"
#define ITER 1e6
static uv_thread_t thread;
var smalloc = require('smalloc');
var uid = 0;
function MemStruct() {
this._id = 0; // 4 bytes (uint32)
this._address = 1; // 4 bytes (uint32)
this._data = 2; // 8 bytes (uint64)
var size = 4;
smalloc.alloc(size, this, smalloc.Types.Uint32);
function reblaze(vals, fn) {
if (typeof fn !== 'function')
throw new TypeError('fn should be a function');
// V8 will automatically throw if vals is not an object.
var keys = Object.keys(vals);
var regexp;
var fn_name = fn.name;