Ejemplo n.º 1
0
/*
 * Initialize an abstract vnode.
 * Invoked by VOP_INIT.
 */
int
vnode_init(struct vnode *vn, const struct vnode_ops *ops,
	   struct fs *fs, void *fsdata)
{
	KASSERT(vn!=NULL);
	KASSERT(ops!=NULL);

	vn->vn_ops = ops;
	vn->vn_refcount = 1;
	vn->vn_opencount = 0;
	vn->vn_fs = fs;
	vn->vn_data = fsdata;

	vn->vn_rwlock = lock_create("vnode-rwlock");
	if (vn->vn_rwlock == NULL) {
		return ENOMEM;
	}
	vn->vn_createlock = lock_create("vnode-createlock");
	if (vn->vn_createlock == NULL) {
		return ENOMEM;
	}
	vn->vn_countlock = lock_create("vnode-countlock");
	if (vn->vn_countlock == NULL) {
		return ENOMEM;
	}

	return 0;
	DEBUG(DB_VFS, "DEBUG VFS: ref-%d\topen-%d\n", vn->vn_refcount, vn->vn_opencount);
}
Ejemplo n.º 2
0
struct rwlock * rwlock_create(const char *name){

	struct rwlock *myrwlock;

	myrwlock=kmalloc(sizeof(struct rwlock));

	if(myrwlock==NULL){
		return NULL;
	}

	myrwlock->rwlock_name = kstrdup(name);

	if(myrwlock->rwlock_name==NULL){
		kfree(myrwlock);
		return NULL;
	}

	myrwlock->lk_read=lock_create("read");
	myrwlock->lk_write=lock_create("write");
	myrwlock->max_readers=30;
	myrwlock->sem_resource=sem_create("resource",myrwlock->max_readers);


	if(myrwlock->sem_resource==NULL){
		kfree(myrwlock);
		return NULL;
	}

	return myrwlock;
}
Ejemplo n.º 3
0
/*
 * pid_bootstrap: initialize.
 */
void
pid_bootstrap(void)
{
	int i;

	pidlock = lock_create("pidlock");
	if (pidlock == NULL) {
		panic("Out of memory creating pid lock\n");
	}

	exitlock = lock_create("exitlock");
	if (exitlock == NULL) {
		panic("Out of memory creating exit lock\n");
	}


	/* not really necessary - should start zeroed */
	for (i=0; i<PROCS_MAX; i++) {
		pidinfo[i] = NULL;
	}

	pidinfo[BOOTUP_PID] = pidinfo_create(BOOTUP_PID, INVALID_PID);
	if (pidinfo[BOOTUP_PID]==NULL) {
		panic("Out of memory creating bootup pid data\n");
	}

	nextpid = PID_MIN;
	nprocs = 1;
}
Ejemplo n.º 4
0
Archivo: vm.c Proyecto: jessZhAnG/OS
void
vm_bootstrap(void)
{
    /*
     initialize locks
     these locks are supposed to be resident in RAM for ever
    */
    coremap_lock = lock_create("coremap");
    page_lock = lock_create("page");
    swap_lock = lock_create("swap");

    /*
     check
    */
    assert(coremap_lock != NULL);
    assert(page_lock != NULL);
    assert(swap_lock != NULL);

    // initialize coremap
    coremap_bootstrap();
    vmstats_init();

    // coremap done
    // take charge of memory management
    coremap_ready = 1;
  
}
Ejemplo n.º 5
0
static void
stdio_init(){
	char *consoleR = NULL;
	char *consoleW = NULL;
	char *consoleE = NULL;
	consoleR = kstrdup("con:");
	consoleW = kstrdup("con:");
	consoleE = kstrdup("con:");

	if (consoleR == NULL || consoleW == NULL || consoleE == NULL)
		panic("thread_bootstrap: could not connect to console\n");

	struct vnode *out;
	struct vnode *in;
	struct vnode *err;
	int r0 = vfs_open(consoleR,O_RDONLY,0664,&in);
	int r1 = vfs_open(consoleW,O_WRONLY,0664,&out);
	int r2 = vfs_open(consoleE,O_WRONLY,0664,&err);
	if (r0 | r1 | r2)
	 	panic("thread_bootstrap: could not connect to console\n");

	struct file_table *stdin = kmalloc(sizeof(struct file_table));
	struct file_table *stdout = kmalloc(sizeof(struct file_table));
	struct file_table *stderr = kmalloc(sizeof(struct file_table));
	if (stdin == NULL || stdout == NULL || stderr == NULL)
		panic("thread_bootstrap: out of memory\n");

	stdin->status = O_RDONLY;
	stdin->refcnt = 1;
	stdin->offset = 0;
	stdin->file = in;
	stdin->update_pos = 0;
	stdin->mutex = lock_create("stdin");

	stdout->status = O_WRONLY;
	stdout->refcnt = 1;
	stdout->offset = 0;
	stdout->file = out;
	stdout->update_pos = 0;
	stdout->mutex = lock_create("stdout");

	stderr->status = O_WRONLY;
	stderr->refcnt = 1;
	stderr->offset = 0;
	stderr->file = err;
	stderr->update_pos = 0;
	stderr->mutex = lock_create("stderr");

	if (stdin->mutex == NULL || stdout->mutex == NULL || stderr->mutex == NULL)
		panic("thread_bootstrap: stdin, stdout, or stderr lock couldn't be initialized\n");

	curthread->fd[STDIN_FILENO] = stdin;
	curthread->fd[STDOUT_FILENO] = stdout;
	curthread->fd[STDERR_FILENO] = stderr;

	kfree(consoleR);
	kfree(consoleW);
	kfree(consoleE);
}
Ejemplo n.º 6
0
void stoplight_init() {
    locks[0] = lock_create("q0 lock");
    locks[1] = lock_create("q1 lock");
    locks[2] = lock_create("q2 lock");
    locks[3] = lock_create("q3 lock");

    inter_sem = sem_create("inter sem",3); 
}
Ejemplo n.º 7
0
void whalemating_init() {
	male_lock = lock_create("male");
	female_lock = lock_create("female");
	match_maker_lock = lock_create("match_maker");
	thread_count_lock = lock_create("counter");
	thread_count_cv = cv_create("count_cv");
	return;
}
Ejemplo n.º 8
0
void stoplight_init() {
  zero = lock_create("zero");
  one = lock_create("one");
  two = lock_create("two");
  three = lock_create("three");
  big_lock = lock_create("big");
  return;
}
Ejemplo n.º 9
0
int
config_con(struct con_softc *cs, int unit)
{
	struct semaphore *rsem, *wsem;
	struct lock *rlk, *wlk;

	/*
	 * Only allow one system console.
	 * Further devices that could be the system console are ignored.
	 *
	 * Do not hardwire the console to be "con1" instead of "con0",
	 * or these asserts will go off.
	 */
	if (unit>0) {
		KASSERT(the_console!=NULL);
		return ENODEV;
	}
	KASSERT(the_console==NULL);

	rsem = sem_create("console read", 0);
	if (rsem == NULL) {
		return ENOMEM;
	}
	wsem = sem_create("console write", 1);
	if (wsem == NULL) {
		sem_destroy(rsem);
		return ENOMEM;
	}
	rlk = lock_create("console-lock-read");
	if (rlk == NULL) {
		sem_destroy(rsem);
		sem_destroy(wsem);
		return ENOMEM;
	}
	wlk = lock_create("console-lock-write");
	if (wlk == NULL) {
		lock_destroy(rlk);
		sem_destroy(rsem);
		sem_destroy(wsem);
		return ENOMEM;
	}

	cs->cs_rsem = rsem;
	cs->cs_wsem = wsem;
	cs->cs_gotchars_head = 0;
	cs->cs_gotchars_tail = 0;

	the_console = cs;
	con_userlock_read = rlk;
	con_userlock_write = wlk;

	flush_delay_buf();

	return attach_console_to_vfs(cs);
}
Ejemplo n.º 10
0
int createcars(int nargs, char ** args)
{
        int index, error;
		count=NCARS;
        lock0 = lock_create("lock0");
		lock1=lock_create("lock1");
		lock2=lock_create("lock2");
		lock3=lock_create("lock3");
		
		
        /*
         * Avoid unused variable warnings.
         */

       (void) nargs;
        (void) args;

        /*
         * Start NCARS approachintersection() threads.
         */

        for (index = 0; index < NCARS; index++) {
				
                error = thread_fork("approachintersection thread",
                                    NULL,
                                    index,
                                    approachintersection,
                                    NULL
                                    );

                /*
                 * panic() on error.
                 */

                if (error) {
                        
                        panic("approachintersection: thread_fork failed: %s\n",strerror(error));
                }
				
        }
		while(1)
		{
		if(count==0)
		{
		lock_destroy(lock0);
		lock_destroy(lock1);
		lock_destroy(lock2);
		lock_destroy(lock3);
		kprintf("All locks destroyed. \n");
		break;
		}
		}
        return 0;
}
Ejemplo n.º 11
0
/**
 * fellowship - Fellowship synch problem driver routine.
 *
 * You may modify this function to initialize any synchronization primitives
 * you need; however, any other data structures you need to solve the problem
 * must be handled entirely by the forked threads (except for some freeing at
 * the end).  Feel free to change the thread forking loops if you wish to use
 * the same entrypoint routine to implement multiple Middle-Earth races.
 *
 * Make sure you don't leak any kernel memory!  Also, try to return the test to
 * its original state so it can be run again.
 */
int
fellowship(int nargs, char **args)
{
  int i, n;

  (void)nargs;
  (void)args;
  
  print_lock = lock_create("print");
  done_sem = sem_create("done", 0);
  
  fotr.warlock = lock_create("wizard");
  init_members(fotr.men, 2, "men");
  init_members(&fotr.elf, 1, "elf");
  init_members(&fotr.dwarf, 1, "dwarf");
  init_members(fotr.hobbits, 4, "hobbits");
  fotr.generation = 0;

  for (i = 0; i < NFOTRS; ++i) {
    thread_fork_or_panic("wizard", wizard, NULL, i, NULL);
  }
  for (i = 0; i < NFOTRS; ++i) {
    thread_fork_or_panic("elf", elf, NULL, i, NULL);
  }
  for (i = 0; i < NFOTRS; ++i) {
    thread_fork_or_panic("dwarf", dwarf, NULL, i, NULL);
  }
  for (i = 0, n = NFOTRS * MEN_PER_FOTR; i < n; ++i) {
    thread_fork_or_panic("man", man, NULL, i, NULL);
  }
  for (i = 0, n = NFOTRS * HOBBITS_PER_FOTR; i < n; ++i) {
    thread_fork_or_panic("hobbit", hobbit, NULL, i, NULL);
  }
  
  for (i = 0, n = NFOTRS * FOTR_SIZE; i < n; i++)
  {
    P(done_sem);
  }
  
  lock_destroy(fotr.warlock);
  destroy_members(fotr.men);
  destroy_members(&fotr.elf);
  destroy_members(&fotr.dwarf);
  destroy_members(fotr.hobbits);
  
  lock_destroy(print_lock);
  sem_destroy(done_sem);

  return 0;
}
Ejemplo n.º 12
0
void stoplight_init() {
  	
	sp_intr_zero = lock_create("zero");
	KASSERT(sp_intr_zero != NULL);	
	
	sp_intr_one = lock_create("one");
	KASSERT(sp_intr_one != NULL);	
	
	sp_intr_two = lock_create("two");
	KASSERT(sp_intr_two != NULL);	
	
	sp_intr_three = lock_create("three");
	KASSERT(sp_intr_three != NULL);	
	return;
}
Ejemplo n.º 13
0
static
void
inititems(void)
{
	if (testsem==NULL) {
		testsem = sem_create("testsem", 2);
		if (testsem == NULL) {
			panic("synchtest: sem_create failed\n");
		}
	}
	if (testlock==NULL) {
		testlock = lock_create("testlock");
		if (testlock == NULL) {
			panic("synchtest: lock_create failed\n");
		}
	}
	if (testcv==NULL) {
		testcv = cv_create("testlock");
		if (testcv == NULL) {
			panic("synchtest: cv_create failed\n");
		}
	}
	if (donesem==NULL) {
		donesem = sem_create("donesem", 0);
		if (donesem == NULL) {
			panic("synchtest: sem_create failed\n");
		}
	}
}
/*!
 * @brief Initialize the OpenSSL subsystem for use in a multi threaded enviroment.
 * @param transport Pointer to the transport instance.
 * @return Indication of success or failure.
 */
static BOOL server_initialize_ssl(Transport* transport) {
	int i;

	lock_acquire(transport->lock);

	// Begin to bring up the OpenSSL subsystem...
	CRYPTO_malloc_init();
	SSL_load_error_strings();
	SSL_library_init();

	// Setup the required OpenSSL multi-threaded enviroment...
	ssl_locks = malloc(CRYPTO_num_locks() * sizeof(LOCK *));
	if (ssl_locks == NULL) {
			dprintf("[SSL INIT] failed to allocate locks (%d locks)", CRYPTO_num_locks());
		lock_release(transport->lock);
		return FALSE;
	}

	for (i = 0; i < CRYPTO_num_locks(); i++) {
		ssl_locks[i] = lock_create();
	}

	CRYPTO_set_id_callback(server_threadid_callback);
	CRYPTO_set_locking_callback(server_locking_callback);
	CRYPTO_set_dynlock_create_callback(server_dynamiclock_create);
	CRYPTO_set_dynlock_lock_callback(server_dynamiclock_lock);
	CRYPTO_set_dynlock_destroy_callback(server_dynamiclock_destroy);
	lock_release(transport->lock);

	return TRUE;
}
Ejemplo n.º 15
0
/* 
 * The CatMouse simulation will call this function once before any cat or
 * mouse tries to each.
 *
 * You can use it to initialize synchronization and other variables.
 * 
 * parameters: the number of bowls
 */
void
catmouse_sync_init(int bowls)
{
  /* replace this default implementation with your own implementation of catmouse_sync_init */
  /* This is the default implementation
  (void)bowls; // keep the compiler from complaining about unused parameters
  globalCatMouseSem = sem_create("globalCatMouseSem",1);
  if (globalCatMouseSem == NULL) {
    panic("could not create global CatMouse synchronization semaphore");
  }
  return;
  */
  myLock = lock_create("myLock");
  KASSERT(myLock != NULL);
  lock_acquire(myLock);
  ava_bowl = kmalloc(bowls * sizeof(bool));
  KASSERT(ava_bowl != NULL);
  for(int i = 0; i < bowls; i++) {
     ava_bowl[i] = true;
  }
  num_cat_eating = 0;
  num_mouse_eating = 0;
//  wchan_cat = cv_create("cat");
//  wchan_mouse = cv_create("mouse");
  wchan_all = cv_create("all");
  lock_release(myLock);
  return;
}
Ejemplo n.º 16
0
void
test_cv_broadcast()
{

	long i;
        int result;

	unintr_printf("starting cv broadcast test\n");
	unintr_printf("threads should print out in reverse order\n");

	testcv_broadcast = cv_create();
	testlock = lock_create();
	done = 0;
	testval1 = NTHREADS - 1;
	for (i = 0; i < NTHREADS; i++) {
		result = thread_create((void (*)(void *))
				       test_cv_broadcast_thread, (void *)i);
		assert(thread_ret_ok(result));
	}

	while (__sync_fetch_and_add(&done, 0) < NTHREADS) {
		/* this requires thread_yield to be working correctly */
		thread_yield(THREAD_ANY);
	}

	assert(interrupts_enabled());
	cv_destroy(testcv_broadcast);
	assert(interrupts_enabled());	
	unintr_printf("cv broadcast test done\n");
}
Ejemplo n.º 17
0
void
test_lock()
{
	long i;
	Tid result;

	unintr_printf("starting lock test\n");

	testlock = lock_create();
	done = 0;
	for (i = 0; i < NTHREADS; i++) {
		result = thread_create((void (*)(void *))test_lock_thread,
				       (void *)i);
		assert(thread_ret_ok(result));
	}

	while (__sync_fetch_and_add(&done, 0) < NTHREADS) {
		/* this requires thread_yield to be working correctly */
		thread_yield(THREAD_ANY);
	}

	assert(interrupts_enabled());
	lock_destroy(testlock);
	assert(interrupts_enabled());
	unintr_printf("lock test done\n");
}
Ejemplo n.º 18
0
CJobPool::CJobPool()
{
	// empty the pool
	m_Lock = lock_create();
	m_pFirstJob = 0;
	m_pLastJob = 0;
}
/*!
 * @brief Creates a new named pipe transport instance.
 * @param config The Named Pipe configuration block.
 * @param size Pointer to the size of the parsed config block.
 * @return Pointer to the newly configured/created Named Pipe transport instance.
 */
Transport* transport_create_named_pipe(MetsrvTransportNamedPipe* config, LPDWORD size)
{
	Transport* transport = (Transport*)calloc(1, sizeof(Transport));
	NamedPipeTransportContext* ctx = (NamedPipeTransportContext*)calloc(1, sizeof(NamedPipeTransportContext));

	if (size)
	{
		*size = sizeof(MetsrvTransportNamedPipe);
	}

	// Lock used to synchronise writes
	ctx->write_lock = lock_create();

	dprintf("[TRANS NP] Creating pipe transport for url %S", config->common.url);

	transport->type = METERPRETER_TRANSPORT_PIPE;
	transport->timeouts.comms = config->common.comms_timeout;
	transport->timeouts.retry_total = config->common.retry_total;
	transport->timeouts.retry_wait = config->common.retry_wait;
	transport->url = _wcsdup(config->common.url);
	transport->packet_transmit = packet_transmit_named_pipe;
	transport->transport_init = configure_named_pipe_connection;
	transport->transport_destroy = transport_destroy_named_pipe;
	transport->transport_reset = transport_reset_named_pipe;
	transport->server_dispatch = server_dispatch_named_pipe;
	transport->get_handle = transport_get_handle_named_pipe;
	transport->set_handle = transport_set_handle_named_pipe;
	transport->ctx = ctx;
	transport->comms_last_packet = current_unix_timestamp();
	transport->get_migrate_context = get_migrate_context_named_pipe;
	transport->get_config_size = transport_get_config_size_named_pipe;

	return transport;
}
Ejemplo n.º 20
0
void add_animation(Window* window, ca_animation* anim) {
	if (!mutex) mutex = lock_create();
	lock(mutex);
	array_m_insert(window->animations, anim);
	anim->end_date = tick_count() + (anim->duration * 1000);
	unlock(mutex);
}
Ejemplo n.º 21
0
void
daemon_init(void)
{
	int err;
	char *daemon_name;

	if (!USE_DAEMON) {
		return;
	}

	daemon_name = kstrdup("writeback daemon:");
	if (daemon_name == NULL) {
		panic("daemon_init: could not launch thread");
	}

	daemon.d_cv = cv_create("daemon cv");
	if (daemon.d_cv == NULL) {
		panic("daemon_init: could not launch thread");
	}

	daemon.d_lock = lock_create("daemon lock");
	if (daemon.d_lock == NULL) {
		panic("daemon_init: could not launch thread");
	}

	daemon.d_awake = true;

	err = thread_fork(daemon_name, NULL, daemon_thread, NULL, 0);
	if (err) {
		panic("daemon_init: could not launch thread");
	}
}
Ejemplo n.º 22
0
void whalemating_init() {
  wm_lock = lock_create("whales");

  wm_mcv = cv_create("males");
  wm_fcv = cv_create("females");
  wm_mmcv = cv_create("matchmakers");
}
Ejemplo n.º 23
0
void
initialize_pid(struct thread *thr,pid_t processid)
{
	if(curthread!=NULL)
		lock_acquire(pid_lock);
	struct process_control *p_array;

	p_array=kmalloc(sizeof(struct process_control));

	thr->t_pid=processid;

	p_array->parent_id=-1;
	p_array->childlist=NULL;
	p_array->exit_code=-1;
	p_array->exit_status=false;
	p_array->mythread=thr;
	p_array->waitstatus=false;
	p_array->process_sem = sem_create(thr->t_name,0);

	//Create the lock and CV
	p_array->process_lock=lock_create(thr->t_name);
	p_array->process_cv = cv_create(thr->t_name);

	//Copy back into the thread
	process_array[processid]=p_array;

	if(curthread!=NULL)
		lock_release(pid_lock);

}
Ejemplo n.º 24
0
/*
 * Instantiate a remote context from a file descriptor
 */
Remote *remote_allocate(SOCKET fd)
{
	Remote *remote = NULL;

	// Allocate the remote context
	if ((remote = (Remote *)malloc(sizeof(Remote))))
	{
		memset(remote, 0, sizeof(Remote));

		// Set the file descriptor
		remote->fd = fd;

		remote->lock = lock_create();


		// If we failed to create the lock we must fail to create the remote
		// as we wont be able to synchronize communication correctly.
		if( remote->lock == NULL )
		{
			remote_deallocate( remote );
			return NULL;
		}
	}

	return remote;
}
Ejemplo n.º 25
0
//==============================================================================
void xivss_initialize_vessel(vessel* v, char* acfpath, char* acfname)
{
	FILE* f;
	char filename[MAX_FILENAME] = { 0 };
	char buf[ARBITRARY_MAX] = { 0 };

	if (xivss_debug_lock == BAD_ID) xivss_debug_lock = lock_create();

	//Get filename
	snprintf(filename,MAX_FILENAME-1,"%s/%s.ivss",acfpath,acfname);
	f = fopen(filename,"r");
	if (!f) {
		/*snprintf(filename,MAX_FILENAME-1,"%s/systems.ivss",acfpath);
		f = fopen(filename,"r");
		if (!f) {
			return;
		}*/
		return;
	}
	fclose(f);

	//Generate prefix for the system
	snprintf(buf,ARBITRARY_MAX-1,"%s/",acfpath);

	//Load the system
	IVSS_Simulator_XGDC_TranslatePrefix = buf;
	xivss_load(v,filename);
	IVSS_Simulator_XGDC_TranslatePrefix = 0;
}
Ejemplo n.º 26
0
CFileScore::CFileScore(CGameContext *pGameServer) : m_pGameServer(pGameServer), m_pServer(pGameServer->Server())
{
	if(gs_ScoreLock == 0)
		gs_ScoreLock = lock_create();

	Init();
}
Ejemplo n.º 27
0
/*
 * Initialize the OpenSSL subsystem for use in a multi threaded enviroment.
 */
static BOOL server_initialize_ssl( Remote * remote )
{
	int i = 0;

	lock_acquire( remote->lock );

	// Begin to bring up the OpenSSL subsystem...
	CRYPTO_malloc_init();
	SSL_load_error_strings();
	SSL_library_init();

	// Setup the required OpenSSL multi-threaded enviroment...
	ssl_locks = (LOCK**)malloc( CRYPTO_num_locks() * sizeof(LOCK *) );
	if( ssl_locks == NULL )
	{
		lock_release( remote->lock );
		return FALSE;
	}

	for( i=0 ; i<CRYPTO_num_locks() ; i++ )
		ssl_locks[i] = lock_create();

	CRYPTO_set_id_callback( server_threadid_callback );
	CRYPTO_set_locking_callback( server_locking_callback );
	CRYPTO_set_dynlock_create_callback( server_dynamiclock_create );
	CRYPTO_set_dynlock_lock_callback( server_dynamiclock_lock );
	CRYPTO_set_dynlock_destroy_callback( server_dynamiclock_destroy  ); 

	lock_release( remote->lock );

	return TRUE;
}
Ejemplo n.º 28
0
static
void
initiateMating()
{
	if (mateLock==NULL) {
		mateLock = lock_create("mateLock");
		if (mateLock == NULL) {
			panic("mateLock: lock_create failed\n");
		}
	}
	if (male_go==NULL) {
		male_go = cv_create("male_go");
		if (male_go == NULL) {
			panic("male_go: cv_create failed\n");
		}
	}
	if (female_go==NULL) {
		female_go = cv_create("female_go");
		if (female_go == NULL) {
			panic("female_go: cv_create failed\n");
		}
	}
	if (matchmaker_go==NULL) {
		matchmaker_go = cv_create("matchmaker_go");
		if (matchmaker_go == NULL) {
			panic("matchmaker_go: cv_create failed\n");
		}
	}
	if (doneSem==NULL) {
		doneSem = sem_create("doneSem", 0);
		if (doneSem == NULL) {
			panic("doneSem: sem_create failed\n");
		}
	}
}
void swap_init() {
	int ret = vfs_open((char*) SWAP_DISK_NAME, O_RDWR, 0, &swap_vnode);
	if (ret) {
		kprintf("WARN swap disk not found Ret = %d\n", ret);
		swap_state = SWAP_STATE_NOSWAP;
		return;
	}
	struct stat statbuf;
	ret = VOP_STAT(swap_vnode, &statbuf);
	if (ret) {
		kprintf("ERR Stat on swap disk failed\n");
		swap_state = SWAP_STATE_NOSWAP;
		return;
	}

	swap_page_count = (statbuf.st_size / PAGE_SIZE) - 1;
	swap_map = (struct swap_entry*) kmalloc(
			sizeof(struct swap_entry) * swap_page_count);

	int i;
	for (i = 0; i < swap_page_count; i++) {
		swap_map[i].se_used = SWAP_PAGE_FREE;
		swap_map[i].se_paddr = i;
	}

	swap_lock = lock_create("swap_lock");

	swap_state = SWAP_STATE_READY;
	kprintf("Swap init done. Total available pages = %d\n", swap_page_count);

}
Ejemplo n.º 30
0
/* 
 * The simulation driver will call this function once before starting
 * the simulation
 *
 * You can use it to initialize synchronization and other variables.
 * 
 */
void
intersection_sync_init(void)
{
  /* replace this default implementation with your own implementation */
	
	inservice=0;
	wait_total=0;
  intersectionSem = sem_create("intersectionSem",1);
  if (intersectionSem == NULL) {
    panic("could not create intersection semaphore");
  }
  mutex=lock_create("intersection lock");
  if(mutex==NULL)
  {
  	panic("could not create intersection lock");
  }
  int i;
  for(i=0;i<4;i++)
  {
  	CV[i]=cv_create("condition varaible");
  	if(CV[i]==NULL)
  	{
  		panic("could not create condition variable");
  	}
  }
  return;
}