Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177741421
D61748.1795175664.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D61748.1795175664.diff
View Options
diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h
--- a/sys/sys/mutex.h
+++ b/sys/sys/mutex.h
@@ -131,6 +131,11 @@
void __mtx_assert(const volatile uintptr_t *c, int what, const char *file,
int line);
#endif
+
+/*
+ * Thread locking.
+ */
+
void thread_lock_flags_(struct thread *, int, const char *, int);
#if LOCK_DEBUG > 0
void _thread_lock(struct thread *td, int opts, const char *file, int line);
@@ -160,6 +165,51 @@
#define thread_unlock(tdp) \
mtx_unlock_spin((tdp)->td_lock)
+/*
+ * Functions around substituting a thread lock's with the blocked lock.
+ */
+
+/* All locks involved must be/are locked. */
+struct mtx *thread_lock_block(struct thread *);
+void thread_lock_unblock(struct thread *, struct mtx *);
+
+/* Wait for the thread to get a real lock (which may or may not be locked). */
+void thread_lock_block_wait(struct thread *);
+
+/* Set a new lock, then unlock the old one. */
+void thread_lock_set(struct thread *, struct mtx *);
+
+#define THREAD_LOCK_ASSERT(td, type) \
+ mtx_assert((td)->td_lock, (type))
+
+#define THREAD_LOCK_BLOCKED_ASSERT(td, type) \
+do { \
+ struct mtx *__m = (td)->td_lock; \
+ if (__m != &blocked_lock) \
+ mtx_assert(__m, (type)); \
+} while (0)
+
+#ifdef INVARIANTS
+#define THREAD_LOCKPTR_ASSERT(td, lock) \
+do { \
+ struct mtx *__m; \
+ __m = (td)->td_lock; \
+ KASSERT(__m == (lock), \
+ ("Thread %p lock %p does not match %p", td, __m, (lock))); \
+} while (0)
+
+#define THREAD_LOCKPTR_BLOCKED_ASSERT(td, lock) \
+do { \
+ struct mtx *__m; \
+ __m = (td)->td_lock; \
+ KASSERT(__m == (lock) || __m == &blocked_lock, \
+ ("Thread %p lock %p does not match %p", td, __m, (lock))); \
+} while (0)
+#else
+#define THREAD_LOCKPTR_ASSERT(td, lock)
+#define THREAD_LOCKPTR_BLOCKED_ASSERT(td, lock)
+#endif
+
/*
* Top-level macros to provide lock cookie once the actual mtx is passed.
* They will also prevent passing a malformed object to the mtx KPI by
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -399,37 +399,10 @@
uint64_t t0st_sched[10];
};
-struct mtx *thread_lock_block(struct thread *);
-void thread_lock_unblock(struct thread *, struct mtx *);
-void thread_lock_block_wait(struct thread *);
-void thread_lock_set(struct thread *, struct mtx *);
-#define THREAD_LOCK_ASSERT(td, type) \
- mtx_assert((td)->td_lock, (type))
-
-#define THREAD_LOCK_BLOCKED_ASSERT(td, type) \
-do { \
- struct mtx *__m = (td)->td_lock; \
- if (__m != &blocked_lock) \
- mtx_assert(__m, (type)); \
-} while (0)
-
+/*
+ * Count of sleep locks held by a thread.
+ */
#ifdef INVARIANTS
-#define THREAD_LOCKPTR_ASSERT(td, lock) \
-do { \
- struct mtx *__m; \
- __m = (td)->td_lock; \
- KASSERT(__m == (lock), \
- ("Thread %p lock %p does not match %p", td, __m, (lock))); \
-} while (0)
-
-#define THREAD_LOCKPTR_BLOCKED_ASSERT(td, lock) \
-do { \
- struct mtx *__m; \
- __m = (td)->td_lock; \
- KASSERT(__m == (lock) || __m == &blocked_lock, \
- ("Thread %p lock %p does not match %p", td, __m, (lock))); \
-} while (0)
-
#define TD_LOCKS_INC(td) ((td)->td_locks++)
#define TD_LOCKS_DEC(td) do { \
KASSERT(SCHEDULER_STOPPED() || (td)->td_locks > 0, \
@@ -437,12 +410,9 @@
(td)->td_locks--; \
} while (0)
#else
-#define THREAD_LOCKPTR_ASSERT(td, lock)
-#define THREAD_LOCKPTR_BLOCKED_ASSERT(td, lock)
-
#define TD_LOCKS_INC(td)
#define TD_LOCKS_DEC(td)
-#endif
+#endif /* INVARIANTS */
/*
* Flags kept in td_flags:
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 20, 11:54 AM (22 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41867011
Default Alt Text
D61748.1795175664.diff (3 KB)
Attached To
Mode
D61748: threads: Move thread-lock-related functions to <sys/mutex.h>
Attached
Detach File
Event Timeline