예제 #1
0
void sys_mbox_free(sys_mbox_t mbox)
{
    acquire(&mbox->lock);
    sem_destroy(mbox->free);
    sem_destroy(mbox->queued);
    if (mbox->count != 0)
        cprintf("sys_mbox_free: Warning: mbox not free\n");
    release(&mbox->lock);
    kmfree((char*)mbox, sizeof(struct mbox));
}
예제 #2
0
파일: thread.c 프로젝트: nielh/dragon
void thread_exit()
{
    spin_lock(&thread_current->lock);

    process_t* proc = thread_current->process;
	if(proc)
	{
		__sync_sub_and_fetch(&proc->thread_cnt, 1);
		if(proc->thread_cnt == 0)
		{
			ProcessFree(proc);
		}
	}

    kmfree(thread_current->kstack_start);
    kmfree(thread_current);
    thread_current = NULL;

    thread_schedule();
//    spin_unlock(&thread_current->lock);
}
예제 #3
0
파일: dir.c 프로젝트: nielh/dragon
static s64 dir_delete(void* obj, char* path)
{
	assert(obj != 0);
	assert(path != 0);

    char filename[24];
    char* end = strchr(path, '/');
    strncpy(filename, path, end -path);

    if(*end == '/') // skip '/'
        end ++;

	dir_item_t* item = ((dir_t*)obj)->list;
	dir_item_t* prev = 0;

	while(item != 0)
	{
		if(strcmp(filename, item->name) == 0)
        {
            if(*end == NULL) // last filename
            {
                if(prev == 0) // head
                    ((dir_t*)obj)->list = item->next;
                else
                    prev->next = item->next;

                kmfree(item);
                return 0;
            }
            else
                return delete(item->obj, end);
        }

        prev = item;
		item = item->next;
	}

	return -1;

}
예제 #4
0
파일: fat.c 프로젝트: nielh/dragon
static void* file_open(void* obj, char* path, s64 flag, s64 mode)
{
	assert(IS_PTR(obj));

    fatfile_t* file = (fatfile_t*)obj;

    down(&file->sem);

    if(*path == NULL) // last name in path
    {
        file->ref ++;
        if((!file->attr.directory) && (flag & O_TRUNC))
            file_trunc(file);

		up_one(&file->sem);
        return file;
    }

    if(!file->attr.directory) // 路径中的名称必须是目录
    {
    	up_one(&file->sem);
    	return (void*)-1;
    }

    char filename[32];
    char* end = strchr(path, '/');
    strncpy(filename, path, end -path);
    UpperStr(filename);

    if(*end == '/') // skip '/'
        end ++;

    // find in child list
    fatfile_t* child = findChild(file, filename);
    if(child == NULL)
    {
        child = (fatfile_t*)kmalloc(sizeof(fatfile_t));
        memset(child, 0, sizeof(fatfile_t));
        child->ops = &file_ops;
        sem_init(&child->sem, 1, "file sem");
        child->fatfs = file->fatfs;
        child->name = strdup(filename);

        struct FAT_ENTRY entry;
        int index = findEntryByName(file, filename, &entry);
        if(index >= 0)
        {
            child->index = index;
            child->cluster = (entry.start_clusterHI << 16) | entry.start_clusterLO;
            child->size = entry.file_size;
            child->attr = entry.attribute;

            getEntryCreateDate(child, &entry);
            getEntryWriteDate(child, &entry);
        }
        else
        {
            if((flag &O_CREAT) && (*end == NULL))
            {
                rtcdate rtc;
                cmostime(&rtc);
                child->cdatetime = rtc;
                child->wdatetime = rtc;

                child->dirty = TRUE; // update entry
            }
            else
            {
                kmfree(child->name);
                kmfree(child);

                up_one(&file->sem);
                return (void*)-2;
            }
        }

        insertChild(file, child);
    }

    up_one(&file->sem);
    return file_open(child, end, flag, mode);
}
예제 #5
0
void sys_sem_free(sys_sem_t sem)
{
    sem_destroy(sem);
    kmfree((char*)sem, sem_size());
}