<commit_before>/**
* Server is a .net executable written in js, compiled to .net using jsc
*/
import System;
import System.Threading;
import System.Net;
import System.IO;

import Http;
import Net;

var manualResetEvent : ManualResetEvent = new ManualResetEvent( false );
var lock : Object = new Object();
var workItems = [];

// thread safe enqueue method
function queueWorkItem( item ) {
		print( 'queueWorkItem(): queuing item: ' + item );
		print( 'queueWorkItem(): acquiring lock: ' + lock );
	Monitor.Enter( lock );
	try {
		workItems.push( item );
		print( 'queueWorkItem(): item queued' );
		manualResetEvent.Set();
	}
	finally {
		Monitor.Exit( lock );
		print( 'queueWorkItem: released lock' );
	}
}

// takes a .js file on the commandline, eval it 
var args : String[] = Environment.GetCommandLineArgs();
var sr : StreamReader = new StreamReader( args[1] );
var script = sr.ReadToEnd();
eval( script, 'unsafe' );
sr.Close();

// main event loop
while( true ) {
	print( 'event loop running' );
	var callback;
	
	// TODO: can we improve locking method?
	Monitor.Enter( lock );
	try {
		print( 'event loop: acquired lock' );
		callback = workItems.shift();
		if( callback == null ) {
			manualResetEvent.Reset();
		}
	}
	finally {
		Monitor.Exit( lock );
		print( 'event loop: released lock' );
	}
	
	if( callback != null ) {
		print( 'event loop: dispatching callback' );
		// TODO: figure out what 'this' should be passed, currently passing server
		// which is almost certainly the wrong thing.
		callback.callback.apply( this, callback.args );
	}
	print( 'event loop waiting' );
	manualResetEvent.WaitOne();
} // while<commit_msg>changed lock object to be the work queue, gettign rid of separate lock object.<commit_after>/**
* Server is a .net executable written in js, compiled to .net using jsc
*/
import System;
import System.Threading;
import System.Net;
import System.IO;

import Http;
import Net;

var manualResetEvent : ManualResetEvent = new ManualResetEvent( false );
var lock : Object = new Object();
var workItems = [];

// thread safe enqueue method
function queueWorkItem( item ) {
		print( 'queueWorkItem(): queuing item: ' + item );
		print( 'queueWorkItem(): acquiring lock: ' + workItems );
	Monitor.Enter( workItems );
	try {
		workItems.push( item );
		print( 'queueWorkItem(): item queued' );
		manualResetEvent.Set();
	}
	finally {
		Monitor.Exit( workItems );
		print( 'queueWorkItem: released lock' );
	}
}

// takes a .js file on the commandline, eval it 
var args : String[] = Environment.GetCommandLineArgs();
var sr : StreamReader = new StreamReader( args[1] );
var script = sr.ReadToEnd();
eval( script, 'unsafe' );
sr.Close();

// main event loop
while( true ) {
	print( 'event loop running' );
	var callback;
	
	// TODO: can we improve locking method?
	Monitor.Enter( workItems );
	try {
		print( 'event loop: acquired lock' );
		callback = workItems.shift();
		if( callback == null ) {
			manualResetEvent.Reset();
		}
	}
	finally {
		Monitor.Exit( workItems );
		print( 'event loop: released lock' );
	}
	
	if( callback != null ) {
		print( 'event loop: dispatching callback' );
		// TODO: figure out what 'this' should be passed, currently passing server
		// which is almost certainly the wrong thing.
		callback.callback.apply( this, callback.args );
	}
	print( 'event loop waiting' );
	manualResetEvent.WaitOne();
} // while
{'fraction_non_alphanumeric': 0.132858837485172, 'fraction_numerical': 0.0005931198102016608, 'mean_word_length': 3.867243867243867, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7262228', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1031, 'n_words': 358}