Esempio n. 1
0
static void activate(GtkWidget *widget, gpointer data)
{
	// Let the main thread update...
	gtk_main_iteration();

	gboolean make_my_life_easier=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mmle_check));

	if (make_my_life_easier)
	{
		// Activate!
		activate_thread(1);
	}
	else {
		if (confirm("Are you sure you don't want you life to be easier should you have to reactivate?", "Are you sure?")!=1)
		{
			gtk_main_iteration();

			// Activate!
			activate_thread(1);
		}
		else {
			gtk_main_iteration();

			// Activate!
			activate_thread(0);
		}
	}

	// Fill in the info again (to get new device name)
	//fill_in_info();
}
Esempio n. 2
0
  bool VM::find_and_activate_thread() {
    Tuple* scheduled = globals.scheduled_threads.get();

    for(std::size_t i = scheduled->num_fields() - 1; i > 0; i--) {
      List* list = as<List>(scheduled->at(this, i));

      Thread* thread = try_as<Thread>(list->shift(this));

      while(thread) {
        thread->queued(this, Qfalse);

        /** @todo   Should probably try to prevent dead threads here.. */
        if(thread->alive() == Qfalse) {
          thread = try_as<Thread>(list->shift(this));
          continue;
        }

        if(thread->sleep() == Qtrue) {
          thread = try_as<Thread>(list->shift(this));
          continue;
        }

        activate_thread(thread);
        return true;
      }
    }

    return false;
  }
Esempio n. 3
0
void * main_thread(void * data)
{
	int flag=1,choice,n;
	int temp;
	TCPsocket client_socket,server_socket;
	if(!intialize_thread())
	{
		printf("\n Therer is some error while initializing thread");
		return 0;
	 }
	printf("\n Value of active ports is:%d",get_active_threads());

	// first server receive request from client to connect and open master server socket. To be created only once.-permanent 
	if(common_connect_server(&host_ipaddress,&server_socket,global_port,(const char *)NULL)==0)
		return (void *)1;
	while(quit) 
	{
		// Open client socket on server side for sending dynamic port address-temprary
		if((client_socket=SDLNet_TCP_Accept(server_socket)))
		{
 			// send port address to client
			pthread_mutex_lock(&mutex_variable);
			printf("\n Value of active ports:%d",get_active_threads());
			if(get_active_threads()==0)
			{
				int temp=0;
				SDLNet_TCP_Send(client_socket,&(temp),2);
				SDLNet_TCP_Close(client_socket);
				pthread_mutex_unlock(&mutex_variable);
			}
			else
				if(SDLNet_TCP_Send(client_socket,&(thread_header->client.port),2)==2)
				{
					printf("\nNew Port is send to client"); 
					// close temprary client socket 
					SDLNet_TCP_Close(client_socket);
					// opening port so that server can accept content from client in different thread;
					pthread_mutex_unlock(&mutex_variable);
					printf("\n Activating thread");
					activate_thread();
				}
		}
	}
		printf("\nEverything is OK now exiting");	
		SDLNet_TCP_Close(server_socket);
		cleanup_thread();
		return NULL;
}
Esempio n. 4
0
asmlinkage int pthread_detach_sys (pthread_t thread) {
  int flags;

  if (!thread || thread -> magic_number != PTHREAD_MAGIC_NUMBER) {
    SET_ERRNO (ESRCH);
    return -1;
  }

  if (GET_THREAD_DETACH_STATE(thread)) {
    SET_ERRNO (EINVAL);
    return -1;
  }

  hw_save_flags_and_cli (flags);
  SET_THREAD_DETACH_STATE(thread, 1);
  
  activate_thread (current_thread -> joining_thread);
  current_thread -> joining_thread = 0;
  hw_restore_flags (flags);
  scheduling ();

  return 0;
}
Esempio n. 5
0
asmlinkage int pthread_create_sys (pthread_t *thread, 
				   const pthread_attr_t *attr,
                                   void *(*startup)(void *),
				   void *(*start_routine)(void *), 
				   void *args) {
  int flags;

  hw_save_flags_and_cli (flags);


  // Check policy & prio
  if (attr) {
    if (attr->policy != SCHED_FIFO) {
      SET_ERRNO(EINVAL);
      return -1;
    } else {

      if (attr -> sched_param.sched_priority > MIN_SCHED_PRIORITY ||
	  attr -> sched_param.sched_priority < MAX_SCHED_PRIORITY) {
	SET_ERRNO(EINVAL);
	return -1;
      }
    }
  }

  // Creating the pthread structure
  if (!(*thread = create_pthread_struct ())) {
    SET_ERRNO (EAGAIN);
    hw_restore_flags (flags);
    return -1;
  }
  
  /* 
   * Configuring the new thread either with attr (if not NULL)
   * or with the default values
   */
  if (attr) {
    (*thread) -> sched_param = attr -> sched_param;    
    (*thread) -> stack_info.stack_size = attr -> stack_size;
    (*thread) -> stack_info.stack_bottom = attr -> stack_addr;
    SET_THREAD_DETACH_STATE((*thread), attr -> detachstate);
    SET_THREAD_POLICY ((*thread), attr -> policy);
  } else {
    (*thread) -> sched_param.sched_priority = MIN_SCHED_PRIORITY;
    (*thread) -> stack_info.stack_size = STACK_SIZE;
    (*thread) -> stack_info.stack_bottom = 0;
    SET_THREAD_DETACH_STATE((*thread), 0);
    SET_THREAD_POLICY ((*thread), SCHED_FIFO);
  }

  if (!((*thread) -> stack_info.stack_bottom)) {
    // Creating the thread stack
    if (alloc_stack (&(*thread) -> stack_info) < 0) {
      SET_ERRNO (EAGAIN);
      hw_restore_flags (flags);
      return -1;
    }
  }

  // This is arhictecture dependent
  (*thread) -> stack = setup_stack ((*thread)->stack_info.stack_bottom +
				    (*thread)->stack_info.stack_size 
				    / sizeof (int),
                                    startup,
                                    start_routine, args);

  activate_thread (*thread);
  pthread_t tmp = *thread;
  printf("pthred_create_sys thread 0x%x state:%d\n", (unsigned long)tmp, GET_THREAD_STATE(tmp));

  // no error at all
  hw_restore_flags (flags);

  // Calling the scheduler
  scheduling ();
  return 0;
}