Feature #3176 » setpriority_wont_work.diff
| eval.c | ||
|---|---|---|
| 
     void rb_clear_trace_func(void); 
   | 
||
| 
     void rb_thread_stop_timer_thread(void); 
   | 
||
| 
     extern void rb_threadptr_interrupt(rb_thread_t *th); 
   | 
||
| 
     void rb_call_inits(void); 
   | 
||
| 
     void Init_heap(void); 
   | 
||
| thread.c | ||
|---|---|---|
| 
     static inline void blocking_region_end(rb_thread_t *th, struct rb_blocking_region_buffer *region); 
   | 
||
| 
     #if !USE_NATIVE_THREAD_PRIORITY 
   | 
||
| 
     static void rb_pqueue_enqueue(pqueue_t *pqueue, rb_thread_t *th, unsigned priority); 
   | 
||
| 
     static rb_thread_t *rb_pqueue_dequeue(pqueue_t *pqueue); 
   | 
||
| 
     static rb_thread_t *rb_pqueue_dequeue_starting_at(pqueue_t *pqueue, unsigned start_from, unsigned *found_at); 
   | 
||
| 
     #endif 
   | 
||
| 
     #define RB_GC_SAVE_MACHINE_CONTEXT(th) \ 
   | 
||
| 
       do { \ 
   | 
||
| ... | ... | |
| 
         SET_MACHINE_STACK_END(&(th)->machine_stack_end); \ 
   | 
||
| 
       } while (0) 
   | 
||
| 
     #if USE_NATIVE_THREAD_PRIORITY 
   | 
||
| 
     #define GVL_TAKE(th) (native_mutex_lock(&(th)->vm->global_vm_lock)) 
   | 
||
| 
     #define GVL_GIVE(th) (native_mutex_unlock(&(th)->vm->global_vm_lock)) 
   | 
||
| 
     #else 
   | 
||
| 
     #define GVL_TAKE(th) \ 
   | 
||
| 
       while (0!=native_mutex_trylock(&(th)->vm->global_vm_lock)) { \ 
   | 
||
| 
         thread_debug("waiting for gvl\n"); \ 
   | 
||
| ... | ... | |
| 
          if (th2) rb_undoze(th2); \ 
   | 
||
| 
        } while(0) 
   | 
||
| 
     #endif 
   | 
||
| 
     #define GVL_UNLOCK_BEGIN() do { \ 
   | 
||
| 
       rb_thread_t *_th_stored = GET_THREAD(); \ 
   | 
||
| 
       RB_GC_SAVE_MACHINE_CONTEXT(_th_stored); \ 
   | 
||
| ... | ... | |
| 
         native_mutex_destroy(lock); 
   | 
||
| 
     } 
   | 
||
| 
     #if !USE_NATIVE_THREAD_PRIORITY 
   | 
||
| 
     static void 
   | 
||
| 
     rb_pqueue_flush(pqueue_t *pqueue) 
   | 
||
| 
     { 
   | 
||
| ... | ... | |
| 
         } 
   | 
||
| 
         if (++pqueue->next_promote_index>=RUBY_NUM_PRIORITIES) pqueue->next_promote_index=0; 
   | 
||
| 
     } 
   | 
||
| 
     #endif /*USE_NATIVE_THREAD_PRIORITY*/ 
   | 
||
| 
     static void 
   | 
||
| 
     set_unblock_function(rb_thread_t *th, rb_unblock_function_t *func, void *arg, 
   | 
||
| ... | ... | |
| 
         rb_thread_wait_for(rb_time_timeval(INT2FIX(sec))); 
   | 
||
| 
     } 
   | 
||
| 
     #if USE_NATIVE_THREAD_PRIORITY 
   | 
||
| 
     #define rb_there_are_equal_or_higher_priority_threads(th) 0 
   | 
||
| 
     #else 
   | 
||
| 
     static int 
   | 
||
| 
     rb_there_are_equal_or_higher_priority_threads(rb_thread_t *th) 
   | 
||
| 
     { 
   | 
||
| ... | ... | |
| 
         return(highest_waiting>=th->priority); 
   | 
||
| 
     } 
   | 
||
| 
     #endif 
   | 
||
| 
     static void rb_threadptr_execute_interrupts_rec(rb_thread_t *, int); 
   | 
||
| ... | ... | |
| 
     	    thread_debug("rb_thread_schedule/switch done\n"); 
   | 
||
| 
     	} 
   | 
||
| 
     #if !USE_NATIVE_THREAD_PRIORITY 
   | 
||
| 
     	if (sched_depth){ 
   | 
||
| 
     	    if (ticks_til_rotate) { 
   | 
||
| 
     		--ticks_til_rotate; 
   | 
||
| ... | ... | |
| 
     		rb_pqueue_rotate(&th->vm->ready_to_run_list); 
   | 
||
| 
     	    } 
   | 
||
| 
     	} 
   | 
||
| 
     #endif 
   | 
||
| 
     	if (!sched_depth && UNLIKELY(GET_THREAD()->interrupt_flag)) { 
   | 
||
| 
     	    rb_threadptr_execute_interrupts_rec(GET_THREAD(), sched_depth+1); 
   | 
||
| ... | ... | |
| 
         rb_secure(4); 
   | 
||
| 
     #if USE_NATIVE_THREAD_PRIORITY 
   | 
||
| 
         th->priority = NUM2INT(prio); 
   | 
||
| 
         native_thread_apply_priority(th); 
   | 
||
| 
     #else 
   | 
||
| 
         priority = NUM2INT(prio); 
   | 
||
| 
         if (priority > RUBY_THREAD_PRIORITY_MAX) { 
   | 
||
| 
     	priority = RUBY_THREAD_PRIORITY_MAX; 
   | 
||
| ... | ... | |
| 
     	priority = RUBY_THREAD_PRIORITY_MIN; 
   | 
||
| 
         } 
   | 
||
| 
         th->priority = priority; 
   | 
||
| 
     #if USE_NATIVE_THREAD_PRIORITY 
   | 
||
| 
         native_thread_apply_priority(th); 
   | 
||
| 
     #endif 
   | 
||
| 
         return INT2NUM(th->priority); 
   | 
||
| 
     } 
   | 
||
| ... | ... | |
| 
         vm->main_thread = th; 
   | 
||
| 
         native_mutex_reinitialize_atfork(&th->vm->global_vm_lock); 
   | 
||
| 
     #if !USE_NATIVE_THREAD_PRIORITY 
   | 
||
| 
         rb_pqueue_flush(&vm->ready_to_run_list); 
   | 
||
| 
     #endif 
   | 
||
| 
         st_foreach(vm->living_threads, atfork, (st_data_t)th); 
   | 
||
| 
         st_clear(vm->living_threads); 
   | 
||
| 
         st_insert(vm->living_threads, thval, (st_data_t)th->thread_id); 
   | 
||
| ... | ... | |
| 
     	    rb_thread_lock_t *lp = &GET_THREAD()->vm->global_vm_lock; 
   | 
||
| 
     	    native_mutex_initialize(lp); 
   | 
||
| 
     	    native_mutex_lock(lp); 
   | 
||
| 
     #if !USE_NATIVE_THREAD_PRIORITY 
   | 
||
| 
     	    rb_pqueue_initialize(&GET_THREAD()->vm->ready_to_run_list); 
   | 
||
| 
     #endif 
   | 
||
| 
     	    native_mutex_initialize(&GET_THREAD()->interrupt_lock); 
   | 
||
| 
     	} 
   | 
||
| 
         } 
   | 
||
| thread_pthread.c | ||
|---|---|---|
| 
     static void 
   | 
||
| 
     native_thread_apply_priority(rb_thread_t *th) 
   | 
||
| 
     { 
   | 
||
| 
     #if defined(_POSIX_PRIORITY_SCHEDULING) && (_POSIX_PRIORITY_SCHEDULING > 0) 
   | 
||
| 
     #ifdef linux 
   | 
||
| 
         setpriority(PRIO_PROCESS,th->thread_id,-th->priority); 
   | 
||
| 
     #else 
   | 
||
| 
         struct sched_param sp; 
   | 
||
| 
         int policy; 
   | 
||
| 
         int priority = 0 - th->priority; 
   | 
||
| ... | ... | |
| 
         sp.sched_priority = priority; 
   | 
||
| 
         pthread_setschedparam(th->thread_id, policy, &sp); 
   | 
||
| 
     #else 
   | 
||
| 
         /* not touched */ 
   | 
||
| 
     #endif 
   | 
||
| 
     } 
   | 
||
| vm.c | ||
|---|---|---|
| 
     void vm_analysis_register(int reg, int isset); 
   | 
||
| 
     void vm_analysis_insn(int insn); 
   | 
||
| 
     #if !USE_NATIVE_THREAD_PRIORITY 
   | 
||
| 
     extern void rb_pqueue_destroy(pqueue_t *pqueue); 
   | 
||
| 
     #endif 
   | 
||
| 
     void 
   | 
||
| 
     rb_vm_change_state(void) 
   | 
||
| ... | ... | |
| 
     	} 
   | 
||
| 
     	rb_thread_lock_unlock(&vm->global_vm_lock); 
   | 
||
| 
     	rb_thread_lock_destroy(&vm->global_vm_lock); 
   | 
||
| 
     #if !USE_NATIVE_THREAD_PRIORITY 
   | 
||
| 
     	rb_pqueue_destroy(&vm->ready_to_run_list); 
   | 
||
| 
     #endif 
   | 
||
| 
     	ruby_xfree(vm); 
   | 
||
| 
     	ruby_current_vm = 0; 
   | 
||
| 
     #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE 
   | 
||
| vm_core.h | ||
|---|---|---|
| 
     #include <setjmp.h> 
   | 
||
| 
     #include <signal.h> 
   | 
||
| 
     #ifdef linux 
   | 
||
| 
     #define USE_NATIVE_THREAD_PRIORITY 1 
   | 
||
| 
     #define RUBY_THREAD_PRIORITY_MAX 20 
   | 
||
| 
     #define RUBY_THREAD_PRIORITY_MIN -19 
   | 
||
| 
     #endif 
   | 
||
| 
     #ifndef USE_NATIVE_THREAD_PRIORITY 
   | 
||
| 
     #define USE_NATIVE_THREAD_PRIORITY 0 
   | 
||
| 
     #define RUBY_THREAD_PRIORITY_MAX 15 
   | 
||
| 
     #define RUBY_THREAD_PRIORITY_MIN -16 
   | 
||
| 
     #define RUBY_NUM_PRIORITIES (1+RUBY_THREAD_PRIORITY_MAX-RUBY_THREAD_PRIORITY_MIN) 
   | 
||
| 
     #endif 
   | 
||
| 
     #define RUBY_NUM_PRIORITIES (1+RUBY_THREAD_PRIORITY_MAX-RUBY_THREAD_PRIORITY_MIN) 
   | 
||
| 
     #ifndef NSIG 
   | 
||
| 
     # define NSIG (_SIGMAX + 1)      /* For QNX */ 
   | 
||
| 
     #endif 
   | 
||
| ... | ... | |
| 
     void rb_objspace_free(struct rb_objspace *); 
   | 
||
| 
     #endif 
   | 
||
| 
     #if !USE_NATIVE_THREAD_PRIORITY 
   | 
||
| 
     struct rb_thread_struct; 
   | 
||
| 
     typedef struct priority_queue {  
   | 
||
| 
         /*elements in queues are circularly linked lists of rb_thread_t, 
   | 
||
| ... | ... | |
| 
         unsigned next_promote_index;  /*makes this into a fair priority queue*/ 
   | 
||
| 
         rb_thread_lock_t lock; 
   | 
||
| 
     } pqueue_t; 
   | 
||
| 
     #endif 
   | 
||
| 
     typedef struct rb_vm_struct { 
   | 
||
| 
         VALUE self; 
   | 
||
| 
         rb_thread_lock_t global_vm_lock; 
   | 
||
| 
     #if !USE_NATIVE_THREAD_PRIORITY 
   | 
||
| 
         pqueue_t ready_to_run_list; 
   | 
||
| 
     #endif 
   | 
||
| 
         struct rb_thread_struct *main_thread; 
   | 
||
| 
         struct rb_thread_struct *running_thread; 
   | 
||
| ... | ... | |
| 
         int method_missing_reason; 
   | 
||
| 
         int abort_on_exception; 
   | 
||
| 
     #if !USE_NATIVE_THREAD_PRIORITY 
   | 
||
| 
         struct rb_thread_struct *next; 
   | 
||
| 
     #endif 
   | 
||
| 
     #ifdef USE_SIGALTSTACK 
   | 
||
| 
         void *altstack; 
   | 
||
- « Previous
 - 1
 - …
 - 3
 - 4
 - 5
 - Next »