Ejemplo n.º 1
0
        public void AddEventSchQueue(ScriptData ID, string FunctionName, DetectParams[] qParams, EventPriority priority,
                                     params object[] param)
        {
            QueueItemStruct QIS = new QueueItemStruct
            {
                EventsProcData = new ScriptEventsProcData(),
                ID             = ID,
                functionName   = FunctionName,
                llDetectParams = qParams,
                param          = param,
                VersionID      = Interlocked.Read(ref ID.VersionID),
                State          = ID.State,
                CurrentlyAt    = null
            };

            if (ID == null || ID.Script == null || ID.IgnoreNew)
            {
                return;
            }

            if (!ID.SetEventParams(QIS)) // check events delay rules
            {
                return;
            }

            ScriptEvents.Enqueue(QIS);

            long threadCount = Interlocked.Read(ref scriptThreadpool.nthreads);

            if (threadCount == 0 || threadCount < (ScriptEvents.Count + (SleepingScriptEventCount / 2)) * EventPerformance)
            {
                scriptThreadpool.QueueEvent(eventLoop, 2);
            }
        }
Ejemplo n.º 2
0
        public void AddEventSchQueue(ScriptData ID, string FunctionName, DetectParams[] qParams, int VersionID, EventPriority priority, params object[] param)
        {
            QueueItemStruct QIS;

            if (ID == null || ID.EventsProcData.IgnoreNew)
            {
                return;
            }

            if (!ID.SetEventParams(FunctionName, qParams)) // check events delay rules
            {
                return;
            }

            QIS                = new QueueItemStruct();
            QIS.ID             = ID;
            QIS.functionName   = FunctionName;
            QIS.llDetectParams = qParams;
            QIS.param          = param;
            QIS.VersionID      = VersionID;
            QIS.State          = ID.State;
            QIS.CurrentlyAt    = null;

            Interlocked.Exchange(ref ID.EventsProcDataLocked, 1);
            lock (ID.EventsProcData)
            {
                if (ID.EventsProcData.EventsQueue.Count > 100)
                {
                    Interlocked.Exchange(ref ID.EventsProcDataLocked, 0);
                    return;
                }

                ID.EventsProcData.EventsQueue.Enqueue(QIS);

                lock (ScriptIDs)
                {
                    if (!ID.InEventsProcData)
                    {
                        ID.EventsProcData.State  = (int)ScriptEventsState.Idle;
                        ID.EventsProcData.thread = null;
                        ScriptIDs.AddLast(ID);
                        ID.InEventsProcData = true;
                        Interlocked.Increment(ref nScriptIDs);
                        Interlocked.Increment(ref nEventScripts);
                    }
                }
                Interlocked.Exchange(ref ID.EventsProcDataLocked, 0);
            }

            lock (WorkersLock)
            {
                if (WorkersLock.nWorkers < MaxScriptThreads && WorkersLock.nWorkers < nScriptIDs)
                {
                    Scriptthreadpool.QueueEvent(loop, 2);
                }
            }
        }
Ejemplo n.º 3
0
        public void AddEventSchQueue(ScriptData ID, string FunctionName, DetectParams[] qParams, EventPriority priority,
                                     params object[] param)
        {
            QueueItemStruct QIS;

            if (ID == null || ID.Script == null || ID.IgnoreNew)
                return;

            if (!ID.SetEventParams(FunctionName, qParams)) // check events delay rules
                return;

            QIS = new QueueItemStruct
                      {
                          EventsProcData = new ScriptEventsProcData(),
                          ID = ID,
                          functionName = FunctionName,
                          llDetectParams = qParams,
                          param = param,
                          VersionID = Interlocked.Read(ref ID.VersionID),
                          State = ID.State,
                          CurrentlyAt = null
                      };

            ScriptEvents.Enqueue(QIS);

            long threadCount = Interlocked.Read(ref scriptThreadpool.nthreads);
            if (threadCount == 0 || threadCount < (ScriptEvents.Count + (SleepingScriptEventCount/2))*EventPerformance)
            {
                scriptThreadpool.QueueEvent(eventLoop, 2);
            }
        }
        public void AddEventSchQueue(ScriptData ID, string FunctionName, DetectParams[] qParams, EventPriority priority, params object[] param)
        {
            QueueItemStruct QIS;

            if (ID == null || ID.Script == null || ID.IgnoreNew)
                return;

            if (!ID.SetEventParams(FunctionName, qParams)) // check events delay rules
                return;

            QIS = new QueueItemStruct();
            QIS.EventsProcData = new ScriptEventsProcData ();
            QIS.ID = ID;
            QIS.functionName = FunctionName;
            QIS.llDetectParams = qParams;
            QIS.param = param;
            QIS.VersionID = Interlocked.Read(ref ID.VersionID);
            QIS.State = ID.State;
            QIS.CurrentlyAt = null;

            lock (ScriptEvents)
            {
                ScriptEvents.Enqueue (QIS);
                ScriptEventCount++;
#if Debug
                m_log.Warn (ScriptEventCount + ", " + QIS.functionName);
#endif
            }

            long threadCount = Interlocked.Read (ref scriptThreadpool.nthreads);
            if (threadCount == 0 || threadCount < (ScriptEventCount + (SleepingScriptEventCount / 2)) * EventPerformance)
            {
                scriptThreadpool.QueueEvent (eventLoop, 2);
            }
        }
Ejemplo n.º 5
0
        public void AddEventSchQueue(ScriptData ID, string FunctionName, DetectParams[] qParams, int VersionID, EventPriority priority, params object[] param)
        {
            QueueItemStruct QIS;

            if (ID == null || ID.EventsProcData.IgnoreNew)
                return;

            if (!ID.SetEventParams(FunctionName, qParams)) // check events delay rules
                return;

            QIS = new QueueItemStruct();
            QIS.ID = ID;
            QIS.functionName = FunctionName;
            QIS.llDetectParams = qParams;
            QIS.param = param;
            QIS.VersionID = VersionID;
            QIS.State = ID.State;
            QIS.CurrentlyAt = null;

            lock (ID.EventsProcData)
            {
                ID.EventsProcDataLocked = true;

                if (ID.EventsProcData.EventsQueue.Count > 100)
                {
                    ID.EventsProcDataLocked = false;
                    return;
                }

                ID.EventsProcData.EventsQueue.Enqueue(QIS);
                lock (ScriptIDs)
                {
                    if (!ScriptIDs.Contains(ID))
                    {
                        ID.EventsProcData.State = (int)ScriptEventsState.Idle;
                        ID.EventsProcData.thread = null;
                        ScriptIDs.AddLast(ID);
                        NScriptIDs++;
                        ID.InEventsProcData = true;
                    }
                }
            }
            ID.EventsProcDataLocked = false;

            lock (WorkersLock)
            {
                if (WorkersLock.nWorkers < MaxScriptThreads)
                {
                    Scriptthreadpool.QueueEvent(loop, 2);
                }
            }
        }