| 20645 | var define = _dereq_('./define'); |
| 20646 | |
| 20647 | var Fabric = function( N ){ |
| 20648 | if( !(this instanceof Fabric) ){ |
| 20649 | return new Fabric( N ); |
| 20650 | } |
| 20651 | |
| 20652 | this._private = { |
| 20653 | pass: [] |
| 20654 | }; |
| 20655 | |
| 20656 | var defN = 4; |
| 20657 | |
| 20658 | if( is.number(N) ){ |
| 20659 | // then use the specified number of threads |
| 20660 | } if( typeof navigator !== 'undefined' && navigator.hardwareConcurrency != null ){ |
| 20661 | N = navigator.hardwareConcurrency; |
| 20662 | } else { |
| 20663 | try{ |
| 20664 | N = _dereq_('os').cpus().length; |
| 20665 | } catch( err ){ |
| 20666 | N = defN; |
| 20667 | } |
| 20668 | } // TODO could use an estimation here but would the additional expense be worth it? |
| 20669 | |
| 20670 | for( var i = 0; i < N; i++ ){ |
| 20671 | this[i] = new Thread(); |
| 20672 | } |
| 20673 | |
| 20674 | this.length = N; |
| 20675 | }; |
| 20676 | |
| 20677 | var fabfn = Fabric.prototype; // short alias |
| 20678 | |