Making a cList object thread safe?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> You have to protect all functions of your object which are
> dealing with the list (reading and/or writing) with a cMutex.
>
>   
Thanks! So the following should work (please correct me if I'm wrong):
I add a cMutex object in the cList derived class and 2 functions:

class cThreadSafecList: public cList<...> {
...
private:
    cMutex mutex;
public:
    void Lock(void) { mutex.Lock(); }
    void Unlock(void) { mutex.Unlock(); }
...
}

extern cThreadSafecList MyThreadSafecList;

Every member function with access to the list objects calls Lock and 
Unlock at the beginning and end of the function.
Every direct access to the MyThreadSafecList object (to loop throug or 
manipulate the list objects) must make sure to call 
MyThreadSafecList.Lock and MyThreadSafecList.Unlock. The locking time 
should be short to avoid a sluggish OSD, if one accesses 
MyThreadSafecList in the main thread.

BR,

Christian






[Index of Archives]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Big List of Linux Books]     [Fedora Users]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux