Exemplo n.º 1
0
        private bool EventWaitHandleThread()
        {
            message_wait.WaitOne();
            //read what's in the shared memory
            SMemIPCData data = IPCCodec.Deserialize(phile_stream);

            //pass to program for processing
            switch (data.messageType)
            {
            case 2:     //compute function
                SMemIPCData results = new SMemIPCData();
                results.messageType = 3;

                //call VBA handler
                List <ResultStruct> res_temp = vba_core.ComputeOperator(data.messageValue, data.parameters, data.N, data.num_parameters);

                //place results in shared memory
                results.Results = res_temp;
                IPCCodec.Serialize(phile_stream, results);

                //store the result prefix length
                phile_prefix_stream.Write(0, phile_stream.Position);
                break;

            case 4:     //store in GPU
                break;

            case 5:     //retrieve from GPU
                break;

            case 6:
                string[] parameters = data.messageValue.Split('|');
                Program.HandleFile(parameters[0], parameters[1]);
                break;

            default:
                break;
            }

            message_handled.Set();
            return(false);
        }
Exemplo n.º 2
0
        public SMemIPCData SendMessage(SMemIPCData data_in)
        {
            try
            {
                sharedmem_mutex.WaitOne(); //take the mutex

                //save message in shared memory
                IPCCodec.Serialize(phile_stream, data_in);
                //prepare the message prefix
                phile_prefix.Write(0, phile_stream.Position);
                message_wait.Set();        //signal message ready

                message_handled.WaitOne(); //wait for reply ready signal
                //copy results from shared memory
                long result_size = phile_prefix.ReadInt64(0);
                if (result_size > phile_stream.Capacity)
                {
                    //enlarge the view stream if the result is too big
                    try
                    {
                        phile_stream.Close();
                        phile_stream = phile.CreateViewStream(sizeof(long), result_size);
                    }
                    catch
                    {
                        throw new SystemException("ijiCore: Result set too large.");
                    }
                }
                return(IPCCodec.Deserialize(phile_stream));
            }
            catch (Exception e)
            {
                return(null);
            }
            finally
            {
                sharedmem_mutex.ReleaseMutex();
            }
        }