Skip to content

Commit

Permalink
Fix the assmebly mutex macros to handle saving/restoring interrupt state
Browse files Browse the repository at this point in the history
properly.  Fix the recursive mutex macros to actually compile.  At the
moment we only use MTX_EXIT anyways.
  • Loading branch information
bsdjhb committed Sep 24, 2000
1 parent 511e9e7 commit 65e893c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
28 changes: 21 additions & 7 deletions sys/amd64/include/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -744,45 +744,59 @@ _mtx_exit(struct mtx *mtxp, int type, const char *file, int line)
#if defined(I386_CPU)

#define MTX_EXIT(lck, reg) \
movl $ MTX_UNOWNED,lck+MTX_LOCK;
pushl lck+MTX_SAVEFL; \
movl $ MTX_UNOWNED,lck+MTX_LOCK; \
popf

#else /* I386_CPU */

#define MTX_ENTER(reg, lck) \
pushf \
cli \
9: movl $ MTX_UNOWNED,%eax; \
MPLOCKED \
cmpxchgl reg,lck+MTX_LOCK; \
jnz 9b
jnz 9b; \
popl lck+MTX_SAVEFL;

/* Must use locked bus op (cmpxchg) when setting to unowned (barrier) */
#define MTX_EXIT(lck,reg) \
pushl lck+MTX_SAVEFL; \
movl lck+MTX_LOCK,%eax; \
movl $ MTX_UNOWNED,reg; \
MPLOCKED \
cmpxchgl reg,lck+MTX_LOCK; \
popf

#define MTX_ENTER_WITH_RECURSION(reg, lck) \
pushf \
cli \
movl lck+MTX_LOCK,%eax; \
cmpl PCPU_CURPROC,%eax; \
cmpl _curproc,%eax; \
jne 9f; \
incw lck+MTX_RECURSECNT; \
incw lck+MTX_RECURS; \
jmp 8f; \
9: movl $ MTX_UNOWNED,%eax; \
MPLOCKED \
cmpxchgl reg,lck+MTX_LOCK; \
jnz 9b; \
8:
popl lck+MTX_SAVEFL; \
jmp 10f; \
8: add $4,%esp; \
10:

#define MTX_EXIT_WITH_RECURSION(lck,reg) \
movl lck+MTX_RECURSECNT,%eax; \
movl lck+MTX_RECURSE,%eax; \
decl %eax; \
js 9f; \
movl %eax,lck+MTX_RECURSECNT; \
movl %eax,lck+MTX_RECURSE; \
jmp 8f; \
pushl lck+MTX_SAVEFL; \
9: movl lck+MTX_LOCK,%eax; \
movl $ MTX_UNOWNED,reg; \
MPLOCKED \
cmpxchgl reg,lck+MTX_LOCK; \
popf \
8:

#endif /* I386_CPU */
Expand Down
28 changes: 21 additions & 7 deletions sys/i386/include/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -744,45 +744,59 @@ _mtx_exit(struct mtx *mtxp, int type, const char *file, int line)
#if defined(I386_CPU)

#define MTX_EXIT(lck, reg) \
movl $ MTX_UNOWNED,lck+MTX_LOCK;
pushl lck+MTX_SAVEFL; \
movl $ MTX_UNOWNED,lck+MTX_LOCK; \
popf

#else /* I386_CPU */

#define MTX_ENTER(reg, lck) \
pushf \
cli \
9: movl $ MTX_UNOWNED,%eax; \
MPLOCKED \
cmpxchgl reg,lck+MTX_LOCK; \
jnz 9b
jnz 9b; \
popl lck+MTX_SAVEFL;

/* Must use locked bus op (cmpxchg) when setting to unowned (barrier) */
#define MTX_EXIT(lck,reg) \
pushl lck+MTX_SAVEFL; \
movl lck+MTX_LOCK,%eax; \
movl $ MTX_UNOWNED,reg; \
MPLOCKED \
cmpxchgl reg,lck+MTX_LOCK; \
popf

#define MTX_ENTER_WITH_RECURSION(reg, lck) \
pushf \
cli \
movl lck+MTX_LOCK,%eax; \
cmpl PCPU_CURPROC,%eax; \
cmpl _curproc,%eax; \
jne 9f; \
incw lck+MTX_RECURSECNT; \
incw lck+MTX_RECURS; \
jmp 8f; \
9: movl $ MTX_UNOWNED,%eax; \
MPLOCKED \
cmpxchgl reg,lck+MTX_LOCK; \
jnz 9b; \
8:
popl lck+MTX_SAVEFL; \
jmp 10f; \
8: add $4,%esp; \
10:

#define MTX_EXIT_WITH_RECURSION(lck,reg) \
movl lck+MTX_RECURSECNT,%eax; \
movl lck+MTX_RECURSE,%eax; \
decl %eax; \
js 9f; \
movl %eax,lck+MTX_RECURSECNT; \
movl %eax,lck+MTX_RECURSE; \
jmp 8f; \
pushl lck+MTX_SAVEFL; \
9: movl lck+MTX_LOCK,%eax; \
movl $ MTX_UNOWNED,reg; \
MPLOCKED \
cmpxchgl reg,lck+MTX_LOCK; \
popf \
8:

#endif /* I386_CPU */
Expand Down

0 comments on commit 65e893c

Please sign in to comment.