/**
 * Register for single event notification.
 * A timer event is queued for a single event after the specified delay.
 * @param delay Seconds to wait before the handler is called.
 */
void Notifier::StartSingle(double delay) {
  std::lock_guard<priority_recursive_mutex> sync(queueMutex);
  m_periodic = false;
  m_period = delay;
  DeleteFromQueue();
  InsertInQueue(false);
}
Exemple #2
0
/**
 * Free the resources for a timer event.
 * All resources will be freed and the timer event will be removed from the
 * queue if necessary.
 */
Notifier::~Notifier()
{
    tRioStatusCode localStatus = NiFpga_Status_Success;
    {
        Synchronized sync(queueSemaphore);
        DeleteFromQueue();

        // Delete the static variables when the last one is going away
        if (!(--refcount))
        {
            talarm->writeEnable(false, &localStatus);
            delete talarm;
            talarm = NULL;
            manager->disable(&localStatus);
            delete manager;
            manager = NULL;
        }
    }
    wpi_setError(localStatus);

    // Acquire the semaphore; this makes certain that the handler is 
    // not being executed by the interrupt manager.
    semTake(m_handlerSemaphore, WAIT_FOREVER);
    // Delete while holding the semaphore so there can be no race.
    semDelete(m_handlerSemaphore);
}
Exemple #3
0
long DestroyQueue(queue_t* const queue_tqueue, void (*del)(void*))
{

     /* ------------------------------------- */

	queueNode_t*  queueNode_tNode = NULL;

     /* ------------------------------------- */


	if ( queue_tqueue == NULL ){
		PRINT_ERROR("Niepoprawny pierwszy parametr. Error = %d\n", BMD_ERR_PARAM1);
		return BMD_ERR_PARAM1;
	}

	for( queueNode_tNode = queue_tqueue->head; \
	     queueNode_tNode; queueNode_tNode = queue_tqueue->head){
		DeleteFromQueue( queue_tqueue, (void**)&queueNode_tNode, del );
	}

	queue_tqueue->head = NULL;
	queue_tqueue->tail = NULL;
	queue_tqueue->ulCount = 0;

   return BMD_OK;
}
/**
 * Register for periodic event notification.
 * A timer event is queued for periodic event notification. Each time the
 * interrupt
 * occurs, the event will be immediately requeued for the same time interval.
 * @param period Period in seconds to call the handler starting one period after
 * the call to this method.
 */
void Notifier::StartPeriodic(double period) {
  std::lock_guard<priority_recursive_mutex> sync(queueMutex);
  m_periodic = true;
  m_period = period;
  DeleteFromQueue();
  InsertInQueue(false);
}
/**
 * Register for single event notification.
 * A timer event is queued for a single event after the specified delay.
 * @param delay Seconds to wait before the handler is called.
 */
void Notifier::StartSingle(double delay)
{
	::std::unique_lock<ReentrantMutex> sync(queueSemaphore);
	m_periodic = false;
	m_period = delay;
	DeleteFromQueue();
	InsertInQueue(false);
}
Exemple #6
0
/**
 * Register for periodic event notification.
 * A timer event is queued for periodic event notification. Each time the interrupt
 * occurs, the event will be immedeatly requeued for the same time interval.
 * @param period Period in seconds to call the handler starting one period after the call to this method.
 */
void Notifier::StartPeriodic(double period)
{
    Synchronized sync(queueSemaphore);
    m_periodic = true;
    m_period = period;
    DeleteFromQueue();
    InsertInQueue(false);
}
/**
 * Register for periodic event notification.
 * A timer event is queued for periodic event notification. Each time the interrupt
 * occurs, the event will be immediately requeued for the same time interval.
 * @param period Period in seconds to call the handler starting one period after the call to this method.
 */
void Notifier::StartPeriodic(double period)
{
	::std::unique_lock<ReentrantMutex> sync(queueSemaphore);
	m_periodic = true;
	m_period = period;
	DeleteFromQueue();
	InsertInQueue(false);
}
Exemple #8
0
/**
 * Register for single event notification.
 * A timer event is queued for a single event after the specified delay.
 * @param delay Seconds to wait before the handler is called.
 */
void Notifier::StartSingle(double delay)
{
    Synchronized sync(queueSemaphore);
    m_periodic = false;
    m_period = delay;
    DeleteFromQueue();
    InsertInQueue(false);
}
/**
 * Stop timer events from occuring.
 * Stop any repeating timer events from occuring. This will also remove any single
 * notification events from the queue.
 * If a timer-based call to the registered handler is in progress, this function will
 * block until the handler call is complete.
 */
void Notifier::Stop()
{
	{
		::std::unique_lock<ReentrantMutex> sync(queueSemaphore);
		DeleteFromQueue();
	}
	// Wait for a currently executing handler to complete before returning from Stop()
	Synchronized sync(m_handlerSemaphore);
}
Exemple #10
0
/**
 * Stop timer events from occuring.
 * Stop any repeating timer events from occuring. This will also remove any single
 * notification events from the queue.
 * If a timer-based call to the registered handler is in progress, this function will
 * block until the handler call is complete.
 */
void Notifier::Stop()
{
    {
        Synchronized sync(queueSemaphore);
        DeleteFromQueue();
    }
    // Wait for a currently executing handler to complete before returning from Stop()
    Synchronized sync(m_handlerSemaphore);
}
Exemple #11
0
/**
 * Stop timer events from occuring.
 * Stop any repeating timer events from occuring. This will also remove any
 * single
 * notification events from the queue.
 * If a timer-based call to the registered handler is in progress, this function
 * will
 * block until the handler call is complete.
 */
void Notifier::Stop() {
  {
    std::lock_guard<priority_recursive_mutex> sync(queueMutex);
    DeleteFromQueue();
  }
  // Wait for a currently executing handler to complete before returning from
  // Stop()
  std::lock_guard<priority_mutex> sync(m_handlerMutex);
}
void MyThreadExit(void) {
	if (debug) printf("***** MyThreadExit *****\n");
	if (debug) printf("***** Running   %i *****\n", running_thread->id);

	Thread * exiting_thread = running_thread;

	exiting_thread->state = 3;

	if (exiting_thread->parent != NULL && exiting_thread->parent->join_all) {
		if (exiting_thread->parent->children->front == exiting_thread && exiting_thread->parent->children->rear == exiting_thread) {
			Thread * unblocked_node = exiting_thread->parent;
			unblocked_node->state = 0;
			DeleteFromQueue(unblocked_node, blockedQ, 1);
			Enqueue(unblocked_node, readyQ, 0);
		}
	} else if (exiting_thread->joined_by_parent) {
		Thread * unblocked_node = exiting_thread->parent;
		unblocked_node->state = 0;
		DeleteFromQueue(unblocked_node, blockedQ, 1);
		Enqueue(unblocked_node, readyQ, 0);
	}
	if (queues) PrintQueue(readyQ, 0);
	if (queues) PrintQueue(blockedQ, 1);
	if (debug) printf("***** Exited   %i   *****\n", exiting_thread->id);

	RelinquishThread(exiting_thread);

	if(!isEmpty(readyQ)) {
		Thread * next_thread = readyQ->front;
		next_thread->state = 1;
		running_thread = next_thread;
		Dequeue(readyQ, 0);
		if (debug) printf("***** Running   %i *****\n", running_thread->id);

		setcontext(running_thread->context);
	} else {
		setcontext(&main_context);
	}
}
Exemple #13
0
void main(int argc, char *argv[]) {	
	char *buffer = (char*)malloc(sizeof(char) * LENGTH);
	int i, numMsg;
	Msg *newMsg;

	// seed rand with time so we don't get the same numbers
	srand( time(NULL) );

	numMsg = NUMMSG;

	// get number of messages from the command line
	if(argc == 2){
		numMsg = atoi(argv[1]);
	}else if(argc > 2)
		printf("\n Usage: txtmessage.exe [Number of Messages] \n");

	// add the messages to the queue
	for(i = 0; i < numMsg; i++){

		// get the message from the file
		GetMessageFromFile(buffer, LENGTH);

		// fill out the message structure
		newMsg = (Msg *)malloc(sizeof(struct message));
		if (newMsg == NULL)
			printf("ERROR COULD NOT MALLOC");
		strcpy(newMsg->txt, buffer);
		newMsg->senderID = 2*i;
		newMsg->receiverID = 2*i+1;
		newMsg->msgNum = i+1;
		newMsg->priority = rand() % PRIORITYRANGE;
		newMsg->next = NULL;

		// add the message to the queue
		AddToQueue(newMsg, newMsg->priority, numMsg);
	}

	// print the messages to the screen
	for(i = 0; i < numMsg; i++){
		Msg *message = DeleteFromQueue();
		printf("\n Message Number: %d Message Priority %d %s\n", message->msgNum, message->priority, message->txt);
	}

	
}
/**
 * Free the resources for a timer event.
 * All resources will be freed and the timer event will be removed from the
 * queue if necessary.
 */
Notifier::~Notifier()
{
	{
		std::lock_guard<priority_recursive_mutex> sync(queueMutex);
		DeleteFromQueue();

		// Delete the static variables when the last one is going away
		if (refcount.fetch_sub(1) == 1)
		{
      m_stopped = true;
			m_task.join();
		}
	}

	// Acquire the semaphore; this makes certain that the handler is
	// not being executed by the interrupt manager.
	std::lock_guard<priority_mutex> lock(m_handlerMutex);
}
void RelinquishThread(Thread * thread) {
	if (thread->parent != NULL) {
		MyQueue * family = thread->parent->children;
		DeleteFromQueue(thread, family, 2);
		thread->parent = NULL;
	}
	Thread * child = thread->children->front;
	while (child != NULL) {
		child->parent = NULL;
		if (child->next_s == NULL) {
			child = NULL;
		} else {
			child = child->next_s;
		}

	}
	thread->children = NULL;
	free(thread->context);
	free(thread);
}
Exemple #16
0
/**
 * Free the resources for a timer event.
 * All resources will be freed and the timer event will be removed from the
 * queue if necessary.
 */
Notifier::~Notifier()
{
	{
		Synchronized sync(queueSemaphore);
		DeleteFromQueue();

		// Delete the static variables when the last one is going away
		if (!(--refcount))
		{
			task->Stop();
			delete task;
		}
	}

	// Acquire the semaphore; this makes certain that the handler is 
	// not being executed by the interrupt manager.
	takeSemaphore(m_handlerSemaphore);
	// Delete while holding the semaphore so there can be no race.
	deleteSemaphore(m_handlerSemaphore);
}
/**
 * Free the resources for a timer event.
 * All resources will be freed and the timer event will be removed from the
 * queue if necessary.
 */
Notifier::~Notifier()
{
	{
		::std::unique_lock<ReentrantMutex> sync(queueSemaphore);
		DeleteFromQueue();

		// Delete the static variables when the last one is going away
		if (!(--refcount))
		{
			int32_t status = 0;
			cleanNotifier(m_notifier, &status);
			wpi_setErrorWithContext(status, getHALErrorMessage(status));
		}
	}

	// Acquire the semaphore; this makes certain that the handler is 
	// not being executed by the interrupt manager.
	takeSemaphore(m_handlerSemaphore);
	// Delete while holding the semaphore so there can be no race.
	deleteSemaphore(m_handlerSemaphore);
}
Exemple #18
0
//---------------------------------------------------------------------------
void __fastcall TSound::Execute()
{
  try
  {
    int SleepPause;
    while( ! Terminated )
    {
      SleepPause = 10; // По умолчанию пауза 10 мсек
      if( QueueSize > 0 )
      {
        if( Queue[0].Count > 0 )
        {
          for(int i=0; i<MAX_SOUND_FILE_COUNT && ! Terminated; i++)
          {
            if( Queue[0].File[i].Length() > 0 )
            {
              MyPlaySound(Queue[0].File[i]);
            }
          }

          SleepPause = MAX(SleepPause, Queue[0].Pause);
          Queue[0].Count--;
        }
        else
        {
          DeleteFromQueue();
        }
      }
      Wait(SleepPause);
    }
  }
  catch(const Exception & E)
  {
    WriteToLogError("ERROR\tTSound::Execute: %s", E.Message.c_str());
  }
  catch(...)
  {
    WriteToLogError("ERROR\tTSound::Execute");
  }
}
Exemple #19
0
/**
 * Free the resources for a timer event.
 * All resources will be freed and the timer event will be removed from the
 * queue if necessary.
 */
Notifier::~Notifier() {
  {
    std::lock_guard<priority_recursive_mutex> sync(queueMutex);
    DeleteFromQueue();
  }

  // Delete the static variables when the last one is going away
  if (refcount.fetch_sub(1) == 1) {
    int32_t status = 0;
    {
      std::lock_guard<priority_mutex> sync(halMutex);
      if (m_notifier) {
        cleanNotifier(m_notifier, &status);
        m_notifier = nullptr;
      }
    }
    wpi_setErrorWithContext(status, getHALErrorMessage(status));
  }

  // Acquire the mutex; this makes certain that the handler is
  // not being executed by the interrupt manager.
  std::lock_guard<priority_mutex> lock(m_handlerMutex);
}