Example #1
0
/**
 * @Description: This function builds the mapping between userspace 'mutexes' and internal 'locks'. When a mutex is
 * provided, the function returns a corresponding lock which is global shared.
 * @Bugfix: The read of map (e.g., m = lockMap[mutex]) will also allocate space if mutex is not in lockMap!
 * Hence, the flag "kernal_malloc" should be set before the read and write of lockMap.
 */
InternalLock* InternalLockMap::FindOrCreateLock(void* mutex){
	ASSERT(mutex != NULL, "mutex = NULL");
	//printf("FindOrCreateLock: enter critical section\n");
	map <void*, InternalLock*> :: const_iterator iter;
	//kernal_malloc = true;
	GetHBRuntime()->getThreadPrivate()->SetKernalMalloc(true);
	//SPINLOCK_LOCK(&lock);
	InternalLock* m = lockMap[mutex];
	//InternalLock* m = lockMap.at(mutex);
	//InternalLock* m = NULL;
	//iter = lockMap.find(mutex);
	if(m == NULL) {
		WARNING_MSG("Warning: using lock(%p) without initializing it.\n", mutex);
		//exit(0);
		SPINLOCK_LOCK(&lock);
		m = lockMap[mutex];
		//iter = lockMap.find(mutex);
		if(m == NULL){
			void* ptr = metadata->meta_alloc(sizeof(InternalLock));
			m = new (ptr) InternalLock(mutex);
			//m->magic = 1;
			//lockMap.insert(pair<void*, InternalLock*>(mutex, m));
			lockMap[mutex] = m;
		}
		SPINLOCK_UNLOCK(&lock);
	}
	//kernal_malloc = false;
	GetHBRuntime()->getThreadPrivate()->SetKernalMalloc(false);
	//SPINLOCK_UNLOCK(&lock);
	return m;
}
Example #2
0
void _update_cursor(t_console_desc *console_desc)
{
	SPINLOCK_LOCK(console_desc->spinlock);
	unsigned int cursor_position=(console_desc->video_buf_index/2)+1;
	out(0x0F,0x3D4);
    	out((unsigned char)(cursor_position&0xFF),0x3D5);
   	out(0x0E,0x3D4);
    	out((unsigned char )((cursor_position>>8)&0xFF),0x3D5);
	SPINLOCK_UNLOCK(console_desc->spinlock);
}
Example #3
0
void _delete_char(t_console_desc *console_desc)
{
	SPINLOCK_LOCK(console_desc->spinlock);
	if (console_desc->out_buf_index/SCREEN_WIDTH==(console_desc->out_buf_index+1)/SCREEN_WIDTH)
	{
		console_desc->out_buf[--console_desc->out_buf_index]='\0';
		console_desc->video_buf[--console_desc->video_buf_index]=CHAR_NULL;
		console_desc->video_buf[--console_desc->video_buf_index]=SCREEN_FOREGROUND_COLOR;
	}
	SPINLOCK_UNLOCK(console_desc->spinlock);
}
Example #4
0
void _write_char(t_console_desc *console_desc,char data)
{
	unsigned int to_end_line;
	unsigned int i;

	SPINLOCK_LOCK(console_desc->spinlock);
	if (data=='\n')
	{
		to_end_line=SCREEN_WIDTH -1 - (console_desc->out_buf_index %  SCREEN_WIDTH);
		for (i=0;i<to_end_line;i++) write_out_buf(console_desc,'\0');
	}
	else write_out_buf(console_desc,data);
	SPINLOCK_UNLOCK(console_desc->spinlock);
}
Example #5
0
AdhocSync* AdhocSyncMap::findOrCreateAdhoc(void* sync){
	SPINLOCK_LOCK(&lock);

	GetHBRuntime()->getThreadPrivate()->SetKernalMalloc(true);
	AdhocSync* isync = adhocMap[sync];
	if(isync == NULL) {
		void* ptr = metadata->meta_alloc(sizeof(AdhocSync));
		isync = new (ptr) AdhocSync();
		adhocMap[sync] = isync;
	}
	SPINLOCK_UNLOCK(&lock);

	GetHBRuntime()->getThreadPrivate()->SetKernalMalloc(false);
	return isync;
}
Example #6
0
InternalCond* InternalCondsMap::findOrCreateCond(void* cond){
	ASSERT(cond != NULL, "cond = NULL");
	//SPINLOCK_LOCK(&lock);
	
	GetHBRuntime()->getThreadPrivate()->SetKernalMalloc(true);
	InternalCond* c = condsMap[cond];
	if(c == NULL) {
		WARNING_MSG("Using conditional variable(%p) without initialize it\n", cond);
		//exit(0);
		SPINLOCK_LOCK(&lock);
		c = condsMap[cond];
		if(c == NULL){
			void* ptr = metadata->meta_alloc(sizeof(InternalCond));
			c = new (ptr) InternalCond(cond);
			condsMap[cond] = c;
		}
		SPINLOCK_UNLOCK(&lock);
	}
	//SPINLOCK_UNLOCK(&lock);
	
	GetHBRuntime()->getThreadPrivate()->SetKernalMalloc(false);
	return c;
}
Example #7
0
/*
 *  Initialize the system and let everyone wait until we have done so
 *  properly
 */
void
Init_iODBC (void)
{
#if !defined (PTHREAD_MUTEX_INITIALIZER) || defined (WINDOWS)
  SPINLOCK_INIT (iodbcdm_global_lock);
#endif

  SPINLOCK_LOCK (iodbcdm_global_lock);
  if (!_iodbcdm_initialized)
    {
      /*
       *  OK, now flag we are not callable anymore
       */
      _iodbcdm_initialized = 1;

      /*
       *  Other one time initializations can be performed here
       */
    }
  SPINLOCK_UNLOCK (iodbcdm_global_lock);

  return;
}
Example #8
0
File: ata.c Project: giumaug/g-os
static unsigned int _p_read_write_28_ata(t_io_request* io_request)
{
    int i;
    t_device_desc* device_desc;
    t_io_request* pending_request;
    t_llist_node* node;
    t_spinlock_desc spinlock;
    int k=0;

    SPINLOCK_INIT(spinlock);
    device_desc=io_request->device_desc;

    //Entrypoint mutual exclusion region
    SPINLOCK_LOCK(spinlock);

    device_desc->status=DEVICE_BUSY || POOLING_MODE;
    system.device_desc->serving_request=io_request;

    out(0x2,0x3F6);
    out(0xE0 | (io_request->lba >> 24),0x1F6);
    out((unsigned char)io_request->sector_count,0x1F2);
    out((unsigned char)io_request->lba,0x1F3);
    out((unsigned char)(io_request->lba >> 8),0x1F4);
    out((unsigned char)(io_request->lba >> 16),0x1F5);
    out(io_request->command,0x1F7);
    for (k=0; k<1000; k++);

    //to fix
    if (io_request->command==WRITE_28)
    {
        for (i=0; i<256; i++)
        {
            //out(*(char*)io_request->io_buffer++,0x1F0);
            outw((unsigned short)57,0x1F0);
        }
    }
    while (in(0x1F7)&0x80);

    if ((in(0x1F7)&0x21))
    {
        device_desc->status=DEVICE_IDLE;
        panic();
        return -1;
    }

    device_desc->status=DEVICE_IDLE;

    if (io_request->command==READ_28)
    {
        for (i=0; i<(512*io_request->sector_count); i+=2)
        {
            unsigned short val=inw(0x1F0);
            ((char*)io_request->io_buffer)[i]=(val&0xff);
            ((char*)io_request->io_buffer)[i+1]=(val>>0x8);
        }
    }
    out(0x0,0x3F6);
    //Exitpoint mutual exclusion region
    SPINLOCK_UNLOCK(spinlock);
    return 0;
}