// remove (dead) thread from process. errno_t uu_proc_rm_thread( int pid, int tid ) { assert( tid >= 0 ); hal_mutex_lock(&proc_lock); uuprocess_t * p = proc_by_pid(pid); if( !p ) { hal_mutex_unlock(&proc_lock); return ESRCH; } assert(p->ntids > 0); int done = 0; int i; for( i = 0; i < MAX_UU_TID; i++ ) { if( p->tids[i] != tid ) continue; p->tids[i] = -1; p->ntids--; done = 1; break; } if(!done) panic("not proc's thread"); if( p->ntids <= 0 ) uu_proc_death(p); hal_mutex_unlock(&proc_lock); return 0; }
void paint_q_add( rect_t *r ) { hal_mutex_lock( &rect_list_lock ); pqel_t *new_el = mkel( r ); // Don't die, just let some garbage onscreen? if(0 == new_el) return; hal_sem_release( &painter_sem ); if(paint_q_empty()) { queue_enter(&rect_list, new_el, pqel_t *, chain); goto finish; } pqel_t *pqel; again: queue_iterate( &rect_list, pqel, pqel_t *, chain ) { // r includes qe - delete qe if( rect_includes( r, &pqel->r ) ) { queue_remove( &rect_list, pqel, pqel_t *, chain ); goto again; } // qe includes r - skip addition if( rect_includes( &pqel->r, r ) ) { free( new_el ); goto finish; } }
void init_main_event_q() { queue_init(&ev_unused_events); queue_init(&ev_main_event_q); hal_mutex_init( &ev_main_q_mutex, "Main EvQ" ); hal_mutex_init( &ev_unused_q_mutex, "Free EvQ" ); hal_cond_init( &ev_have_event, "UIEvent" ); hal_mutex_lock( &ev_unused_q_mutex ); int i = MIN_EVENT_POOL; while(i--) ev_allocate_event(); hal_mutex_unlock( &ev_unused_q_mutex ); #if EVENTS_ENABLED hal_start_kernel_thread( ev_push_thread ); ev_engine_active = 1; #if KEY_EVENTS phantom_set_console_getchar( phantom_window_getc ); hal_start_kernel_thread( ev_keyboard_read_thread ); #endif #endif #if DELIVER2THREAD hal_start_kernel_thread( w_event_deliver_thread ); #endif #if VIDEO_NEW_BG_WIN w_bg_win_init(); #endif }
static void thread1(void *a) { char *name = a; while(!thread_stop_request) { thread_activity_counter++; if(TEST_CHATTY) printf("--- thread %s runs ---\n", name); pressEnter(""); if(TEST_CHATTY) printf("Will lock mutex\n"); hal_mutex_lock(&m); if(TEST_CHATTY) printf("locked mutex\n"); checkEnterMutex(); YIELD(); if(TEST_CHATTY) printf("Will unlock mutex\n"); checkLeaveMutex(); hal_mutex_unlock(&m); if(TEST_CHATTY) printf("unlocked mutex\n"); if( random() & 1 ) hal_sem_acquire( &s ); counter++; if(counter >7) { counter = 0; if(TEST_CHATTY) printf("Will signal cond\n"); hal_cond_signal(&c); if(TEST_CHATTY) printf("Signalled cond\n"); } YIELD(); } FINISH(); }
errno_t uu_proc_set_exec( int pid, struct exe_module *em) { assert(em); // Caller must increment assert( em->refcount > 0 ); errno_t r = 0; hal_mutex_lock(&proc_lock); uuprocess_t * p = proc_by_pid(pid); if( p ) { if( p->em ) { // todo unlink em SHOW_ERROR( 0, "Process %d already has em", pid ); } p->em = em; p->mem_start = em->mem_start; p->mem_end = em->mem_end; const char *name = "?"; if( p->argv[0] ) name = p->argv[0]; strlcpy( em->name, name, MAX_UU_CMD ); } else r = ESRCH; hal_mutex_unlock(&proc_lock); return r; }
//! Find a cache entry and get data from it, or return ENOENT static errno_t cache_do_read( cache_t *c, long blk, void *data ) { assert(!queue_empty(&c->lru)); errno_t ret = 0; hal_mutex_lock( &c->lock ); cache_el_t * el = cache_do_find( c, blk ); if( el == 0 ) { SHOW_FLOW( 10, "Cache r miss blk %ld", blk ); ret = ENOENT; goto done; } #if 0 { ret = ENOENT; goto done; } #endif // remove queue_remove( &c->lru, el, cache_el_t *, lru ); // insert at start queue_enter_first( &c->lru, el, cache_el_t *, lru ); memcpy( data, el->data, c->page_size ); //hexdump( data, c->page_size, 0, 0 ); SHOW_FLOW( 9, "Cache r _HIT_ blk %ld blksize %d", blk, c->page_size ); done: hal_mutex_unlock( &c->lock ); return ret; }
void removeRequest(trfs_queue_t *r) { hal_mutex_lock(&lock); queue_remove(&requests, r, trfs_queue_t *, chain); hal_mutex_unlock(&lock); }
void addRequest(trfs_queue_t *r) { hal_mutex_lock(&lock); queue_enter(&requests, r, trfs_queue_t *, chain); hal_mutex_unlock(&lock); }
static void put_buf( char c ) { hal_mutex_lock( &buf_mutex ); cbuf[cbufpos++] = c; hal_mutex_unlock( &buf_mutex ); }