socsvn commit: r236806 -
soc2012/gmiller/locking-head/lib/libthr/thread
gmiller at FreeBSD.org
gmiller at FreeBSD.org
Thu May 31 11:07:17 UTC 2012
Author: gmiller
Date: Thu May 31 11:07:14 2012
New Revision: 236806
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=236806
Log:
Add the remaining lock profiling call points for mutexes.
Modified:
soc2012/gmiller/locking-head/lib/libthr/thread/thr_mutex.c
soc2012/gmiller/locking-head/lib/libthr/thread/thr_private.h
Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_mutex.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libthr/thread/thr_mutex.c Thu May 31 08:22:02 2012 (r236805)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_mutex.c Thu May 31 11:07:14 2012 (r236806)
@@ -89,9 +89,9 @@
int _pthread_mutex_getyieldloops_np(pthread_mutex_t *mutex, int *count);
int __pthread_mutex_setyieldloops_np(pthread_mutex_t *mutex, int count);
-static int mutex_self_trylock(pthread_mutex_t);
+static int mutex_self_trylock(pthread_mutex_t _PROFILE_PARMS);
static int mutex_self_lock(pthread_mutex_t,
- const struct timespec *abstime);
+ const struct timespec *abstime _PROFILE_PARMS);
static int mutex_unlock_common(struct pthread_mutex *, int);
static int mutex_lock_sleep(struct pthread *, pthread_mutex_t,
const struct timespec * _PROFILE_PARMS);
@@ -327,7 +327,7 @@
ENQUEUE_MUTEX(curthread, m);
MUTEX_OBTAIN_SUCCESS();
} else if (m->m_owner == curthread) {
- ret = mutex_self_trylock(m);
+ ret = mutex_self_trylock(m _PROFILE_PASS);
MUTEX_OBTAIN_FAILED();
} else {
MUTEX_OBTAIN_FAILED();
@@ -358,7 +358,7 @@
int ret;
if (m->m_owner == curthread)
- return mutex_self_lock(m, abstime);
+ return mutex_self_lock(m, abstime _PROFILE_PASS);
MUTEX_OBTAIN_FAILED();
@@ -433,6 +433,8 @@
if (_thr_umutex_trylock2(&m->m_lock, TID(curthread)) == 0) {
ENQUEUE_MUTEX(curthread, m);
ret = 0;
+
+ MUTEX_OBTAIN_SUCCESS();
} else {
ret = mutex_lock_sleep(curthread, m, abstime _PROFILE_PASS);
}
@@ -541,7 +543,7 @@
}
static int
-mutex_self_trylock(struct pthread_mutex *m)
+mutex_self_trylock(struct pthread_mutex *m _PROFILE_PARMS)
{
int ret;
@@ -565,11 +567,18 @@
ret = EINVAL;
}
+ if (ret == 0) {
+ MUTEX_OBTAIN_SUCCESS();
+ } else {
+ MUTEX_OBTAIN_FAILED();
+ }
+
return (ret);
}
static int
-mutex_self_lock(struct pthread_mutex *m, const struct timespec *abstime)
+mutex_self_lock(struct pthread_mutex *m, const struct timespec *abstime
+ _PROFILE_PARMS)
{
struct timespec ts1, ts2;
int ret;
@@ -577,6 +586,8 @@
switch (PMUTEX_TYPE(m->m_flags)) {
case PTHREAD_MUTEX_ERRORCHECK:
case PTHREAD_MUTEX_ADAPTIVE_NP:
+ MUTEX_OBTAIN_FAILED();
+
if (abstime) {
if (abstime->tv_sec < 0 || abstime->tv_nsec < 0 ||
abstime->tv_nsec >= 1000000000) {
@@ -601,6 +612,8 @@
* What SS2 define as a 'normal' mutex. Intentionally
* deadlock on attempts to get a lock you already own.
*/
+ MUTEX_OBTAIN_FAILED();
+
ret = 0;
if (abstime) {
if (abstime->tv_sec < 0 || abstime->tv_nsec < 0 ||
@@ -625,15 +638,21 @@
if (m->m_count + 1 > 0) {
m->m_count++;
ret = 0;
- } else
+ } else {
ret = EAGAIN;
- break;
+ MUTEX_OBTAIN_FAILED();
+ }
+ break;
default:
/* Trap invalid mutex types; */
ret = EINVAL;
}
+ if (ret == 0) {
+ MUTEX_OBTAIN_SUCCESS();
+ }
+
return (ret);
}
@@ -661,7 +680,13 @@
PMUTEX_TYPE(m->m_flags) == PTHREAD_MUTEX_RECURSIVE &&
m->m_count > 0)) {
m->m_count--;
+
+ if (m->m_count == 0) {
+ MUTEX_RELEASE(m);
+ }
} else {
+ MUTEX_RELEASE(m);
+
if ((m->m_flags & PMUTEX_FLAG_DEFERED) != 0) {
defered = 1;
m->m_flags &= ~PMUTEX_FLAG_DEFERED;
Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_private.h
==============================================================================
--- soc2012/gmiller/locking-head/lib/libthr/thread/thr_private.h Thu May 31 08:22:02 2012 (r236805)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_private.h Thu May 31 11:07:14 2012 (r236806)
@@ -747,6 +747,7 @@
__hidden;
void _mutex_obtain_success(struct pthread_mutex *, const char *, int)
__hidden;
+void _mutex_release(struct pthread_mutex *) __hidden;
void _libpthread_init(struct pthread *) __hidden;
struct pthread *_thr_alloc(struct pthread *) __hidden;
void _thread_exit(const char *, int, const char *) __hidden __dead2;
@@ -810,11 +811,11 @@
_mutex_obtain_success(m, file, line)
#define MUTEX_OBTAIN_FAILED() \
_mutex_obtain_failed(m, file, line)
+#define MUTEX_RELEASE(m) _mutex_release(m)
#else
-#define MUTEX_OBTAIN_SUCCESS() \
- do { } while (0)
-#define MUTEX_OBTAIN_FAILED() \
- do { } while (0)
+#define MUTEX_OBTAIN_SUCCESS() do { } while (0)
+#define MUTEX_OBTAIN_FAILED() do { } while (0)
+#define MUTEX_RELEASE(m) do { } while (0)
#endif
/* #include <fcntl.h> */
More information about the svn-soc-all
mailing list