Пример #1
0
struct cv *
cv_create(const char *name)
{
	struct cv *cv;

	cv = kmalloc(sizeof(struct cv));
	if (cv == NULL) {
		return NULL;
	}

	// cv->name = kstrdup(name);
	// if (cv->name==NULL) {
		// kfree(cv);
		// return NULL;
	// }
	
    // cv->waitqueue = q_create(5);
    // if (cv->waitqueue == NULL) {
        // kfree(cv->name);
        // kfree(cv);
        // return NULL;
    // }
	
    TQInit(&cv->tq);
	return cv;
}
Пример #2
0
void ungetToken(tToken* token) {
	if (token == NULL) {
		return;
	}
	if (!TQueue) {
		TQInit();
	}
	tToken newTok = (tToken)malloc(sizeof(struct stToken));
	tTokenQueueElem elm = (tTokenQueueElem)malloc(sizeof(struct tTQelem));
	if (!newTok || !elm) {
		FatalError(99, ERR_MESSAGES[ERR_ALLOC]);
	}
	newTok->typ = (*token)->typ;
	if ((*token)->typ == TYPE_IDENTIFICATOR || (*token)->typ == TYPE_STRING) {
		strInit(&newTok->value.stringVal);
		strCopyString(&newTok->value.stringVal, &(*token)->value.stringVal);
	}
	else {
		newTok->value = (*token)->value;
	}
	freeTokenMem(token);
	elm->token = newTok;
	elm->rptr = elm->lptr= NULL;
	if (!TQueue->First) {//ve fronte nikdo neni
		TQueue->First = TQueue->Last = elm;
	}
	else {//nekdo ceka
		TQueue->Last->rptr = elm;
		elm->lptr = TQueue->Last;
		TQueue->Last = elm;
	}


}
Пример #3
0
struct lock *
lock_create(const char *name)
{
	struct lock *lock;

	lock = kmalloc(sizeof(struct lock));
	if (lock == NULL) {
		return NULL;
	}

    (void)name;
	// lock->name = kstrdup(name);
	// if (lock->name == NULL) {
		// kfree(lock);
		// return NULL;
	// }
	
    lock->holdingThread = NULL;
    // lock->waitqueue = q_create(5);
    // if (lock->waitqueue == NULL) {
        // kfree(lock->name);
        // kfree(lock);
        // return NULL;
    // }
    
    TQInit(&lock->tq);
	// add stuff here as needed
	
	return lock;
}
Пример #4
0
/*
 * Setup function
 */
void
scheduler_bootstrap(void)
{
	// runqueue = q_create(32);
	// if (runqueue == NULL) {
		// panic("scheduler: Could not create run queue\n");
	// }
    TQInit(&tq);
}
Пример #5
0
/*
 * Suspend execution for n seconds.
 */
void
clocksleep(int num_secs)
{
	int s;

    if(first) {lbolt = q_create(1); TQInit(&lboltq);}
    first = 0;
	s = splhigh();
	while (num_secs > 0) {
		thread_sleep(&lboltq);
		num_secs--;
	}
	splx(s);
}
Пример #6
0
void
hardclock(void)
{
	/*
	 * Collect statistics here as desired.
	 */


    if(first) {lbolt = q_create(1); TQInit(&lboltq);}
    first = 0;
	lbolt_counter++;
	if (lbolt_counter >= HZ) {
		lbolt_counter = 0;
		thread_wakeup(&lboltq);
	}

	thread_yield();
}
Пример #7
0
struct semaphore *
sem_create(const char *namearg, int initial_count)
{
	struct semaphore *sem;

	assert(initial_count >= 0);

	sem = kmalloc(sizeof(struct semaphore));
	if (sem == NULL) {
		return NULL;
	}

    (void)namearg;
	// sem->name = kstrdup(namearg);
	// if (sem->name == NULL) {
		// kfree(sem);
		// return NULL;
	// }

    // sem->waitqueue = q_create(1);
	sem->count = initial_count;
    TQInit(&sem->tq);
	return sem;
}
Пример #8
0
void sem_init(struct semaphore* sem, int initial_count)
{
    sem->count = initial_count;
    TQInit(&sem->tq);
}
Пример #9
0
void cv_init(struct cv* cv)
{
    TQInit(&cv->tq);
}
Пример #10
0
void lock_init(struct lock* lock)
{
    TQInit(&lock->tq);
    lock->holdingThread = NULL;
}