[omniORB] Thread Priorities

Lolke B. Dijkstra omniorb at dijkstra-ict.com
Wed Mar 8 21:00:38 GMT 2006


Duncan Grisby wrote:

>On Thursday 2 March, "Brian Neal" wrote:
>
>[...]
>  
>
>>Currently there doesn't seem to be a way to tell omniORB what priority
>>it should use for its threads. Does it just pick the omniThread
>>PRIORITY_NORMAL? Is there a way to pass an arg to the orb for that?
>>    
>>
>
>No, there's no way to tell omniORB or omnithread to use a different
>priority. There's no priority setting support in omnithread because it's
>too variable between different platforms.
>
>What I suggest you do is to make an omniORB thread interceptor (see
>chapter 10 of the omniORB manual) that sets the priority you want with
>direct pthread calls.
>
>Cheers,
>
>Duncan.
>
>  
>
Ehhh? What about  SEE class task : public omni_thread section


#ifdef OMNI_THREAD
#    include <omnithread.h>

namespace omni {
    /* exception safe mutex wrapper */
    class scoped_lock {
    public:
        scoped_lock( omni_mutex& m ) : m_(m) { m_.lock(); }
        ~scoped_lock() { m_.unlock(); }
    private:
        omni_mutex& m_;
    };
    inline unsigned long sec     (unsigned long millis)    { return 
(millis/1000); }
    inline unsigned long nanosec (unsigned long millis)    { return 
((millis%1000)*1000000); }
}

//---------------------------------------------------------------------------------
//    wrapper class for thread class
//    the 'work' is done in operator() () making it compatible with 
boost::thread
//
//    NOTES:
//    -    the destuctor is private to prevent delete of omni_thread
//    -    the class hides the differences between boost and omni threading
//---------------------------------------------------------------------------------

class task : public omni_thread
{
public:               
    enum priority_t { LOW_PRIORITY, NORMAL_PRIORITY, HIGH_PRIORITY };
    task( priority_t p = NORMAL_PRIORITY )
        : omni_thread( 0, (omni_thread::priority_t)p )
    {};

private:
    void run(void*) { operator() (); }
    ~task() {};        /* UNDELETABLE CONSTRAINT */

    virtual void operator() () = 0;
public:
    static void launch( task *t ) {    t->start();        }
};


#    define SCOPED_LOCK    omni::scoped_lock
#    define MUTEX        omni_mutex
#    define SLEEP(x)        omni_thread::sleep( omni::sec(x), 
omni::nanosec(x) )    /* x in milliseconds */


#else    // BOOST THREAD






More information about the omniORB-list mailing list