Fixed the libkernelland_emu.so build that Ingo broke so deliberately.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25377 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-05-08 15:09:57 +00:00
parent 23a60f423e
commit 3bdd7f38f1
+33 -33
View File
@@ -26,7 +26,7 @@
#include <string> #include <string>
#ifdef TRACE #ifdef TRACE
#undef TRACE # undef TRACE
#endif #endif
#define TRACE(x) #define TRACE(x)
//#define TRACE(x) printf x //#define TRACE(x) printf x
@@ -1081,22 +1081,35 @@ recursive_lock_unlock(recursive_lock *lock)
// #pragma mark - // #pragma mark -
status_t void
mutex_init(mutex *m, const char *name) mutex_init(mutex *m, const char *name)
{ {
if (m == NULL) if (m == NULL)
return EINVAL; return;
if (name == NULL) if (name == NULL)
name = "mutex_sem"; name = "mutex_sem";
m->holder = -1; // We need to store the semaphore in "waiters", as it is no sem anymore
// Also, kernel mutex creation cannot fail anymore, but we could...
m->waiters = (struct mutex_waiter *)create_sem(1, name);
if ((sem_id)m->waiters < B_OK)
debugger("semaphore creation failed");
}
m->sem = create_sem(1, name);
if (m->sem >= B_OK)
return B_OK;
return m->sem; void
mutex_init_etc(mutex *m, const char *name, uint32 flags)
{
if (m == NULL)
return;
if (name == NULL)
name = "mutex_sem";
m->waiters = (struct mutex_waiter *)create_sem(1, name);
if ((sem_id)m->waiters < B_OK)
debugger("semaphore creation failed");
} }
@@ -1106,44 +1119,31 @@ mutex_destroy(mutex *mutex)
if (mutex == NULL) if (mutex == NULL)
return; return;
if (mutex->sem >= 0) { if ((sem_id)mutex->waiters >= 0) {
delete_sem(mutex->sem); delete_sem((sem_id)mutex->waiters);
mutex->sem = -1; mutex->waiters = (struct mutex_waiter *)-1;
} }
mutex->holder = -1;
} }
status_t status_t
mutex_lock(mutex *mutex) _mutex_trylock(mutex *mutex)
{ {
thread_id me = find_thread(NULL); return acquire_sem_etc((sem_id)mutex->waiters, 1, B_RELATIVE_TIMEOUT, 0);
}
// ToDo: if acquire_sem() fails, we shouldn't panic - but we should definitely
// change the mutex API to actually return the status code
status_t status = acquire_sem(mutex->sem);
if (status < B_OK)
return status;
if (me == mutex->holder) status_t
panic("mutex_lock failure: mutex %p (sem = 0x%lx) acquired twice by thread 0x%lx\n", mutex, mutex->sem, me); _mutex_lock(mutex *mutex, bool threadsLocked)
{
mutex->holder = me; return acquire_sem((sem_id)mutex->waiters);
return B_OK;
} }
void void
mutex_unlock(mutex *mutex) _mutex_unlock(mutex *mutex)
{ {
thread_id me = find_thread(NULL); release_sem((sem_id)mutex->waiters);
if (me != mutex->holder)
panic("mutex_unlock failure: thread 0x%lx is trying to release mutex %p (current holder 0x%lx)\n",
me, mutex, mutex->holder);
mutex->holder = -1;
release_sem(mutex->sem);
} }