예제 #1
0
asmlinkage long NewExit(int exit_code){
	int group_dead;
	struct task_struct* tsk = current;
	struct Mailbox* self;	
// If the calling process does not have a mailbox, simply call the original exit system call
	if((self = HashFind(current->tgid))==NULL){
		return (*ref_sys_exit)(exit_code);
	}
// If the calling process is a kernel process, remove it's mailbox and then exit
	if(verifyPID(current->pid)==KERNPID){
		spin_lock_irq(&creationLock);
		HashRemove(current->tgid);
		spin_unlock_irq(&creationLock);
		return (*ref_sys_exit)(exit_code);
	}
	group_dead = atomic_read(&tsk->signal->live) - 1;
// If the calling process is the last process/thread in its group, it needs to delete the mailbox 
	if(group_dead == 0){
	// Manage the mailbox to stop it, which removes all waiting processes on send or receive
		ManageMailbox(true, NULL);
		spin_lock_irq(&self->lock);
	// If there are no processes waiting on either waiting queue, then flush the messages in the mailbox
		if (self->waitingFull != 0 || self->waitingEmpty != 0 || atomic_read(&self->references) != 0){
			spin_unlock_irq(&self->lock);
			wait_event(self->canExit, self->waitingFull == 0 && self->waitingEmpty == 0 && atomic_read(&self->references) == 0);
			atomic_set(&self->references, -1);
			spin_lock_irq(&self->lock);
		}
		atomic_set(&self->references, -1);
		printk(KERN_INFO "%d is flushing %d messages. \n", current->tgid, self->numberofMessages);
		while(self->numberofMessages > 0){
			struct Message* messages = self->message;
			//printk(KERN_INFO "Number of messages: %d\n", self->numberofMessages);
			self->message = self->message->next;
			kmem_cache_free(contentCache, messages->msg);
			kmem_cache_free(messageCache, messages);
			self->numberofMessages--;
		}
		//printk(KERN_INFO "Number of messages: %d\n", self->numberofMessages);
	// If there are no processes with a reference to the mailbox, delete the mailbox and hash link using HashRemove()
		spin_unlock_irq(&self->lock);
		spin_lock_irq(&creationLock);
		HashRemove(current->tgid);
		spin_unlock_irq(&creationLock);
		printk(KERN_INFO "Exiting and deleting mailbox for %d \n", current->tgid);
		//printk(KERN_INFO "Last member of thread group, so the mailbox has been deleted\n");
		return (*ref_sys_exit)(exit_code);
	}
	//printk(KERN_INFO "Not the last member of thread group\n");
	return (*ref_sys_exit)(exit_code);
}
예제 #2
0
HashObjectPtr removeThings()
{
	char * input = (char *)malloc(sizeof(char)*MAX_INPUT_LENGTH);
	printf("Please enter the word you wish to remove\n\n");
	fgets(input, MAX_INPUT_LENGTH, stdin);

	int j = 0;
	for (; j < strlen(input); j++)
	{
		if (input[j] == '\n')
		{
			input[j] = '\0';
			break;
		}
	}
	HashObjectPtr hobj = HashRemove(table, input);
	if (hobj == NULL)
	{
		printf("That word was not found, returning to main menu\n\n");
		printOptions();
	}
	else
	{
		printf("That word has been successfully removed\n");
		printf("The word and frequency were %s\n", toString(hobj));
		printf("Please do something else\n\n");
		printOptions();
	}
	free(input);
	return hobj;
}
예제 #3
0
ADTErr OperatorDBRemove(OperatorDB* _odb, const char* _operatorName, Operator** _op)
{
	char errMsg[ERR_MSG_SIZE];
	ADTErr err;
	
	if (NULL == _odb)
	{
		GetError(errMsg, ERR_NOT_INITIALIZED);
		LOG_ERROR_PRINT("%s", errMsg);
		return ERR_NOT_INITIALIZED;
	}
	if (NULL == _operatorName || NULL == _op)
	{
		GetError(errMsg, ERR_ILLEGAL_INPUT);
		LOG_ERROR_PRINT("%s", errMsg);
		return ERR_ILLEGAL_INPUT;
	}
	
	HashRemove(_odb->m_map, (const HashKey)_operatorName, (Data*)_op);
	err = (NULL == *_op) ? ERR_NOT_FOUND : ERR_OK;
	if (ERR_OK != err)
	{
		GetError(errMsg, err);
		LOG_WARN_PRINT("%s", errMsg);
	}
	else
	{
		LOG_DEBUG_PRINT("%s", "Successfully removed from database.");
	}
	return err;
}
예제 #4
0
local void Cunset(const char *cmd, const char *params, Player *p, const Target *target)
{
	if (params && *params)
	{
		PData *pdata = PPDATA(p, pdata_key);
		FormulaVariable *var;

		if (*params == '$')
		{
			// ignore a leading $
			params++;
		}

		var = HashGetOne(pdata->vars, params);

		if (var)
		{
			HashRemove(pdata->vars, params, var);
			afree(var);
			chat->SendMessage(p, "Unset %s", params);
		}
		else
		{
			chat->SendMessage(p, "No such variable '%s'", params);
		}
	}
	else
	{
		chat->SendMessage(p, "Usage: ?unset <var>");
	}
}
예제 #5
0
asmlinkage long NewExitGroup(int exit_code){
	int group_dead;
	struct task_struct* tsk = current;
	struct Mailbox* self;	
	if((self = HashFind(current->tgid))==NULL){
		return (*ref_sys_exit_group)(exit_code);
	}
	if(verifyPID(current->pid)==KERNPID){
		spin_lock_irq(&creationLock);
		HashRemove(current->tgid);
		spin_unlock_irq(&creationLock);
		return (*ref_sys_exit_group)(exit_code);
	}
	group_dead = atomic_read(&tsk->signal->live) - 1;
	if(group_dead == 0){
		ManageMailbox(true, NULL);
		spin_lock_irq(&self->lock);
		if (self->waitingFull != 0 || self->waitingEmpty != 0 ||  atomic_read(&self->references) != 0){
			spin_unlock_irq(&self->lock);
			wait_event(self->canExit, self->waitingFull == 0 && self->waitingEmpty == 0 &&  atomic_read(&self->references) == 0);
			atomic_set(&self->references, -1);
			spin_lock_irq(&self->lock);
		}
		atomic_set(&self->references, -1);
		printk(KERN_INFO "%d is flushing %d messages. \n", current->tgid, self->numberofMessages);
		while(self->numberofMessages > 0){
			struct Message* messages = self->message;
			//printk(KERN_INFO "Number of messages: %d\n", self->numberofMessages);
			self->message = self->message->next;
			kmem_cache_free(contentCache, messages->msg);
			kmem_cache_free(messageCache, messages);
			self->numberofMessages--;
		}
		//printk(KERN_INFO "Number of messages: %d\n", self->numberofMessages);
		spin_unlock_irq(&self->lock);
		spin_lock_irq(&creationLock);
		HashRemove(current->tgid);
		spin_unlock_irq(&creationLock);
		printk(KERN_INFO "Exiting and deleting mailbox for %d \n", current->tgid);
		//printk(KERN_INFO "Last member of thread group, so the mailbox has been deleted\n");
		return (*ref_sys_exit_group)(exit_code);
	}
	//printk(KERN_INFO "Not the last member of thread group\n");
	return (*ref_sys_exit_group)(exit_code);
}
TAction* HashPopXdbKey(Transaction *t,
                       const char *hash_name,
                       const char *db_name,
                       size_t key_result,
                       size_t value_result)
{
  TOperand *key_arg = new TOperandVariable(t, key_result);

  TRANSACTION_MAKE_VAR(key_empty);

  TActionSequence *sequence = new TActionSequence(t);
  sequence->PushAction(HashChooseKey(t, hash_name, key_result));
  sequence->PushAction(StringIsEmpty(t, key_arg, key_empty_var));

  TActionTest *non_empty_test = new TActionTest(t, key_empty, false);
  non_empty_test->PushAction(HashRemove(t, hash_name, key_arg));
  non_empty_test->PushAction(XdbLookup(t, db_name, key_arg, value_result));
  sequence->PushAction(non_empty_test);

  return sequence;
}
예제 #7
0
static Err Menu(ClientManager* _clientManager)
{
	int option;
	char group[MAX_NAME_SIZE],ip[MAX_NAME_SIZE],port[MAX_NAME_SIZE];
	char message[MAX_SIZE_OF_MESSAGE];
	unsigned short length;
	Data data;
	char* ptr = NULL;
	if (! _clientManager)
	{
		return ERROR_NOT_INITIALIZED;
	}
	printf("welcome %s!!!\nplease choose one of the following options:\n1. open group\n2. join group\n3. leave group\n4. get all groups\n5. get members of group\n6. log out\n7. unregister\n8. printf groups im in\n9. quit\n",_clientManager->m_name);
	
	select(FD_SETSIZE, &_clientManager->m_fd, NULL, NULL, NULL);
	if (FD_ISSET(0, &_clientManager->m_fd) == 1)
	{
		scanf("%d",&option);
		getchar();
		switch(option)
	 	{
			case 1:
				DEBUG_PRINT("%s","going to open group");
				printf("please enter the group name you wish to create\n");
				if (ERROR_OK == ExecuteCommands(_clientManager,TAG_OPEN_GROUP,group,message,&length))
				{
					ptr = message;
					strcpy(ip,ptr);
					ptr += MAX_NAME_SIZE;
					strcpy(port,ptr);
					OpenGroup(_clientManager,ip,port,group);
					return ERROR_OK;
				}
				return ERROR_END_MAIN;
		 	case 2:
				DEBUG_PRINT("%s","going to join group");
		 		printf("please enter the group name you wish to join\n");
				if (ERROR_OK == ExecuteCommands(_clientManager,TAG_JOIN_GROUP,group,message,&length))
				{
				
					ptr = message;
					strcpy(ip,ptr);
					ptr += MAX_NAME_SIZE;
					strcpy(port,ptr);
					OpenGroup(_clientManager,ip,port,group);
					return ERROR_OK;
				}
				return ERROR_OK;
			case 3:
				DEBUG_PRINT("%s","going to leave group");
				if (ERROR_OK == ExecuteCommands(_clientManager,TAG_LEAVE_GROUP,group,message,&length))
				{
					HashRemove(_clientManager->m_groups,group,&data);
					return ERROR_OK;
				}
				return ERROR_OK;
			case 4:
				DEBUG_PRINT("%s","going to get all groups");
				if (ERROR_OK == ExecuteCommands(_clientManager,TAG_GET_GROUPS,NULL,message,&length))
				{
					PrintData(length,message);		
					return ERROR_OK;
				}
				return ERROR_OK;
			case 5:
				DEBUG_PRINT("%s","going to get members of group");
				printf("please enter the name of the group you wish to see members from\n");
				if (ERROR_OK == ExecuteCommands(_clientManager,TAG_GET_MEMBERS,group,message,&length))
				{
					PrintData(length,message);		
					return ERROR_OK;
				}
				return ERROR_OK;
			case 6:
				DEBUG_PRINT("%s","going to log out");
				if (ERROR_OK == ExecuteCommands(_clientManager,TAG_LOGOUT,NULL,message,&length))
				{
					LogOut(_clientManager);
					return ERROR_END_MENU;
				}
			case 7:
				if (ERROR_OK == ExecuteCommands(_clientManager,TAG_UNREGISTER,group,message,&length))
				{
					printf("unregistered succsesfully\n");
					return ERROR_END_MENU;
				}
				return ERROR_OK;
			case 8:
				HashPrint(_clientManager->m_groups,PrintGroupsImIn);
				return ERROR_OK;
			case 9:
				return ERROR_END_MAIN;
			default:
				printf("i'm sorry, no such option, please try again\n");
				return ERROR_OK;			
		}
	}
	
	else if (FD_ISSET(_clientManager->m_socket, &_clientManager->m_fd) == 1)
	{}
	return ERROR_OK;	
}