[lkml]   [2005]   [Dec]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH 1/19] MUTEX: Introduce simple mutex implementation
Alan Cox writes:
> On Iau, 2005-12-15 at 16:41 +0300, Nikita Danilov wrote:
> > But this change is about fixing bugs: mutex assumes that
> >
> > - only owner can unlock, and
> >
> > - owner cannot lock (immediate self-deadlock).
> So add mutex_up/mutex_down that use the same semaphores but do extra
> checks if lock debugging is enabled. All you need is an owner field for
> debugging.

And to convert almost all calls to down/up to mutex_{down,up}. At which
point, it no longer makes sense to share the same data-type for
semaphore and mutex.

Also, (as was already mentioned several times) having separate data-type
for mutex makes code easier to understand, as it specifies intended

To avoid duplicating code, mutex can be implemented on top of semaphore,

struct mutex {
struct semaphore sema;
void *owner;

or something similar.

> Now generate a trace dump on up when up and to check for sleeping on a
> lock you already hold (for both sem and mutex).

Sleeping on a semaphore "held" by the current thread is perfectly
reasonable usage of a generic counting semaphore, as it can be upped by
another thread.

> Alan

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-12-15 16:55    [W:0.307 / U:0.800 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site