With dynamic creation, you can use:
bthread_mutex_t mutex;
- pthread_mutex_init(&mutex); // you can also use bthread_mutex_init()
+ pthread_mutex_init(&mutex);
bthread_mutex_set_priority(&mutex, 10);
pthread_mutex_destroy(&mutex);
/*
* Replacement for pthread_mutex_init()
*/
-int bthread_mutex_init(bthread_mutex_t *m, const pthread_mutexattr_t *attr)
+int pthread_mutex_init(bthread_mutex_t *m, const pthread_mutexattr_t *attr)
{
m->priority = 0;
return pthread_mutex_init(&m->mutex, attr);
/*
* Replacement for pthread_mutex_destroy()
*/
-int bthread_mutex_destroy(bthread_mutex_t *m)
+int pthread_mutex_destroy(bthread_mutex_t *m)
{
return pthread_mutex_destroy(&m->mutex);
}
-/*
- * Replacement for pthread_mutex_init() for pthread_mutex_t
- */
-int bthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *attr)
-{
- return pthread_mutex_init(m, attr);
-}
-
-/*
- * Replacement for pthread_mutex_destroy() for pthread_mutex_t
- */
-int bthread_mutex_destroy(pthread_mutex_t *m)
-{
- return pthread_mutex_destroy(m);
-}
-
-
/*
* Replacement for pthread_mutex_lock()
* Returns always ok
void *ret=NULL;
lmgr_thread_t *self;
pthread_t id1, id2, id3, tab[200];
+ bthread_mutex_t bmutex1;
+ pthread_mutex_t pmutex2;
my_prog = argv[0];
use_undertaker = false;
lmgr_init_thread();
+ self = lmgr_get_thread_info();
if (argc == 2) { /* do priority check */
P(mutex_p2); /* not permited */
return 0;
}
+ pthread_mutex_init(&bmutex1, NULL);
+ bthread_mutex_set_priority(&bmutex1, 10);
+
+ pthread_mutex_init(&pmutex2, NULL);
+ P(bmutex1);
+ ok(self->max_priority == 10, "Check self max_priority");
+ P(pmutex2);
+ ok(bmutex1.priority == 10, "Check bmutex_set_priority()");
+ V(pmutex2);
+ V(bmutex1);
+ ok(self->max_priority == 0, "Check self max_priority");
+
pthread_create(&id1, NULL, self_lock, NULL);
sleep(2);
ok(lmgr_detect_deadlock(), "Check self deadlock");
pthread_join(id3, &ret);
ok(ret != 0, "Check for priority segfault");
- self = lmgr_get_thread_info();
P(mutex_p1);
ok(self->max_priority == 1, "Check max_priority 1/4");
P(mutex_p2);
/* Call just before releasing the lock */
void lmgr_do_unlock(void *m);
-int bthread_mutex_init(bthread_mutex_t *m, const pthread_mutexattr_t *attr);
-int bthread_mutex_destroy(bthread_mutex_t *m);
-void bthread_mutex_set_priority(bthread_mutex_t *m, int prio);
+/* We use C++ mangling to make integration eaysier */
+int pthread_mutex_init(bthread_mutex_t *m, const pthread_mutexattr_t *attr);
+int pthread_mutex_destroy(bthread_mutex_t *m);
-/* init/destroy for real pthread_mutex_t object */
-int bthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *attr);
-int bthread_mutex_destroy(pthread_mutex_t *m);
+void bthread_mutex_set_priority(bthread_mutex_t *m, int prio);
/*
* Each thread have to call this function to put a lmgr_thread_t object
# define pthread_mutex_unlock(x) bthread_mutex_unlock(x)
# define pthread_cond_wait(x,y) bthread_cond_wait(x,y)
# define pthread_cond_timedwait(x,y,z) bthread_cond_timedwait(x,y,z)
-# define pthread_mutex_init(x,y) bthread_mutex_init(x,y)
-# define pthread_mutex_destroy(x) bthread_mutex_destroy(x)
#endif
#else /* _USE_LOCKMGR */
# define lmgr_do_unlock(m)
# define lmgr_cleanup_main()
# define bthread_mutex_set_priority(a)
-# define bthread_mutex_init(a,b) pthread_mutex_init(a,b)
-# define bthread_mutex_destroy(a) pthread_mutex_destroy(a)
# define bthread_mutex_lock(a) pthread_mutex_lock(a)
# define bthread_mutex_unlock(a) pthread_mutex_unlock(a)
# define lmgr_cond_wait(a,b) pthread_cond_wait(a,b)