Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eb9fd685 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

add a ctor to Mutex to specify the type, which can be shared. This is used by...

add a ctor to Mutex to specify the type, which can be shared. This is used by sf and af an soon will allow some optimization in the kernel for non shared mutexes
parent b8eccd86
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -98,6 +98,8 @@ struct layer_cblk_t // (128 bytes)

struct per_client_cblk_t   // 4KB max
{
    per_client_cblk_t() : lock(Mutex::SHARED) { }

                Mutex           lock;
                Condition       cv;
                layer_cblk_t    layers[NUM_LAYERS_MAX] __attribute__((aligned(32)));
+17 −0
Original line number Diff line number Diff line
@@ -190,8 +190,14 @@ inline thread_id_t getThreadId() {
 */
class Mutex {
public:
    enum {
        NORMAL = 0,
        SHARED = 1
    };
    
                Mutex();
                Mutex(const char* name);
                Mutex(int type, const char* name = NULL);
                ~Mutex();

    // lock or unlock the mutex
@@ -235,6 +241,17 @@ inline Mutex::Mutex() {
inline Mutex::Mutex(const char* name) {
    pthread_mutex_init(&mMutex, NULL);
}
inline Mutex::Mutex(int type, const char* name) {
    if (type == SHARED) {
        pthread_mutexattr_t attr;
        pthread_mutexattr_init(&attr);
        pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
        pthread_mutex_init(&mMutex, &attr);
        pthread_mutexattr_destroy(&attr);
    } else {
        pthread_mutex_init(&mMutex, NULL);
    }
}
inline Mutex::~Mutex() {
    pthread_mutex_destroy(&mMutex);
}