Exemplo n.º 1
0
		/// <summary>
		/// Grows the size of the request allocation tables by 33%.
		///
		/// This *MUST* be called with the reqlock held!
		/// </summary>
		/// <returns>ID to use for a new request.</returns>
		/// <param name="curlen">Current length of the allocation tables.</param>
		int GrowRequests (ref int curlen)
		{
			int newsize = curlen + curlen/3;
			var new_request_ids = new int [newsize];
			var new_requests = new Worker [newsize];
			var new_buffers = new byte [newsize][];

			request_ids.CopyTo (new_request_ids, 0);
			Array.Clear (request_ids, 0, request_ids.Length);
			request_ids = new_request_ids;
			
			requests.CopyTo (new_requests, 0);
			Array.Clear (requests, 0, requests.Length);
			requests = new_requests;
			
			buffers.CopyTo (new_buffers, 0);
			Array.Clear (buffers, 0, buffers.Length);
			buffers = new_buffers;

			curlen = newsize;
			return curlen + 1;
		}
Exemplo n.º 2
0
        // Grows the size of the request allocation tables by 33%.
        //
        // Parameters:
        //   curlen - current length of the allocation tables.
        //   newid - ID to use for a new request.
        //
        // This *MUST* be called with the reqlock held!
        //
        void GrowRequests(ref int curlen, ref int newid)
        {
            int newsize = curlen + curlen/3;
            int[] new_request_ids = new int [newsize];
            Worker[] new_requests = new Worker [newsize];
            byte[][] new_buffers = new byte [newsize][];

            request_ids.CopyTo (new_request_ids, 0);
            Array.Clear (request_ids, 0, request_ids.Length);
            request_ids = new_request_ids;

            requests.CopyTo (new_requests, 0);
            Array.Clear (requests, 0, requests.Length);
            requests = new_requests;

            buffers.CopyTo (new_buffers, 0);
            Array.Clear (buffers, 0, buffers.Length);
            buffers = new_buffers;

            newid = curlen + 1;
            curlen = newsize;
        }
Exemplo n.º 3
0
		public int RegisterRequest (Worker worker)
		{
			int result;
			
			lock (reqlock) {
				result = IdToIndex (GetNextRequestId ());
				requests [result] = worker;
				
				// Don't create a new array if one already exists.
				byte[] a = buffers [result];
				if (a == null)
					buffers [result] = new byte [BUFFER_SIZE];
			}

			return request_ids [result];
		}
Exemplo n.º 4
0
        /// <summary>
        ///    Registers a request with the current instance.
        /// </summary>
        /// <param name="worker">
        ///    A <see cref="Worker" /> object containing the request to
        ///    register.
        /// </param>
        /// <returns>
        ///    A <see cref="int" /> containing the ID of the request.
        /// </returns>
        public int RegisterRequest(Worker worker)
        {
            int result = -1;

            lock (reqlock) {
                result = IdToIndex (GetNextRequestId ());
                requests [result] = worker;

                // Don't create a new array if one already
                // exists.
                byte[] a = buffers [result];
                if (a == null || a.Length != 16384)
                    buffers [result] = new byte [16384];
            }

            return request_ids [result];
        }