void worker( cyg_addrword_t id ) { for(;;) { thread_count[id]++; thread_pri[id] = cyg_thread_get_priority( cyg_thread_self() ); switch( worker_state ) { case WORKER_STATE_BREAK: if( 0 == (id % 4) ) breakme(); case WORKER_STATE_WAIT: cyg_mutex_lock( &worker_mutex ); workers_asleep++; cyg_cond_wait( &worker_cv ); workers_asleep--; cyg_mutex_unlock( &worker_mutex ); break; case WORKER_STATE_EXIT: cyg_thread_exit(); } } }
static int e_cond_wait(lua_State *L) { cyg_cond_t *cond; cond = (cyg_cond_t *) check_user_data(L, 1, E_COND); lua_pushboolean(L, cyg_cond_wait(cond)); return 1; }
static void finish( cyg_ucount8 t ) { cyg_mutex_lock( &m1 ); { m1d |= 1<<t; if( 0x7 == m1d ) CYG_TEST_PASS_FINISH("Kernel C API Mutex 1 OK"); cyg_cond_wait( &cvar2 ); } /* cyg_mutex_unlock( &m1 ); */ CYG_TEST_FAIL_FINISH("Not reached"); }
res_t resAllocate(void) { res_t res; cyg_mutex_lock(&res_lock); while(res_count == 0) cyg_cond_wait(&res_wait); res_count--; res = res_pool[res_count]; cyg_mutex_unlock(&res_lock); return res; }
static void entry0( cyg_addrword_t data ) { cyg_mutex_lock( &m0 ); { CHECK( ! cyg_mutex_trylock( &m0 ) ); cyg_mutex_lock( &m1 ); { CHECK( ! cyg_mutex_trylock( &m0 ) ); } cyg_mutex_unlock( &m1 ); } cyg_mutex_unlock( &m0 ); cyg_mutex_lock( &m0 ); { while ( 0 == m0d ) cyg_cond_wait( &cvar0 ); CHECK( 1 == m0d++ ); cyg_cond_signal( &cvar0 ); while ( 4 != m0d ) cyg_cond_wait( &cvar1 ); CHECK( 4 == m0d ); } cyg_mutex_unlock( &m0 ); finish( (cyg_ucount8)data ); }
static void entry2( cyg_addrword_t data ) { cyg_mutex_lock( &m0 ); { while( 3 != m0d ) { cyg_cond_wait( &cvar0 ); } CHECK( 3 == m0d++ ); cyg_cond_broadcast( &cvar1 ); } cyg_mutex_unlock( &m0 ); finish( (cyg_ucount8)data ); }
static void entry1( cyg_addrword_t data ) { cyg_mutex_lock( &m0 ); { CHECK( cyg_mutex_trylock( &m1 ) ); { } cyg_mutex_unlock( &m1 ); } cyg_mutex_unlock( &m0 ); cyg_mutex_lock( &m0 ); { CHECK( 0 == m0d++ ); cyg_cond_broadcast( &cvar0 ); } cyg_mutex_unlock( &m0 ); cyg_mutex_lock( &m0 ); { while( 1 == m0d ) cyg_cond_wait( &cvar0 ); CHECK( 2 == m0d++ ); cyg_cond_signal( &cvar0 ); while( 3 == m0d ) cyg_cond_wait( &cvar1 ); } cyg_mutex_unlock( &m0 ); finish( (cyg_ucount8)data ); }
res_t res_allocate() { res_t res; cyg_mutex_lock(&res_lock); while (res_count == 0) cyg_cond_wait(&res_wait, &res_lock); res_count--; res = res_pool[res_count]; printf("TID %lu using %d, free resources: %d\n", cyg_thread_self(), res, res_count); cyg_cond_signal(&res_wait); cyg_mutex_unlock(&res_lock); return res; }