Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
41a64e23
Commit
41a64e23
authored
May 22, 2015
by
Michael Arntzenius
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add src/deadlock_debug_helper.cpp
parent
6aa8adcb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
0 deletions
+60
-0
src/CMakeLists.txt
src/CMakeLists.txt
+1
-0
src/deadlock_debug_helper.cpp
src/deadlock_debug_helper.cpp
+59
-0
No files found.
src/CMakeLists.txt
View file @
41a64e23
...
...
@@ -68,6 +68,7 @@ add_library(PYSTON_OBJECTS OBJECT ${OPTIONAL_SRCS}
core/stats.cpp
core/threading.cpp
core/util.cpp
deadlock_debug_helper.cpp
gc/collector.cpp
gc/gc_alloc.cpp
gc/heap.cpp
...
...
src/deadlock_debug_helper.cpp
0 → 100644
View file @
41a64e23
// Copyright (c) 2014-2015 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This file is a hack for debugging deadlocks. It makes pthread_mutex_lock() complain if it takes more than given time
// (TIMEOUT_S) to grab a lock. Perhaps it will be useful in future.
#if 0 // set to 1 to enable
#include <errno.h>
#include <pthread.h>
#include <string.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include "core/common.h"
#define TIMEOUT_S 2
extern "C" int pthread_mutex_lock(pthread_mutex_t* lock) {
struct timespec timeout;
memset(&timeout, 0, sizeof timeout);
timeout.tv_sec = TIMEOUT_S;
pid_t tid = syscall(SYS_gettid);
RELEASE_ASSERT(tid > 1, "negative or invalid TID");
time_t started = time(NULL);
RELEASE_ASSERT(started != (time_t)-1, "could not get time()");
int err;
for (;;) {
err = pthread_mutex_timedlock(lock, &timeout);
if (err != ETIMEDOUT)
break;
time_t now = time(NULL);
RELEASE_ASSERT(now != (time_t)-1, "could not get time()");
if (now - started >= TIMEOUT_S) {
printf("%d: mutex %p TIMED OUT\n", tid, (void*)lock);
started = now;
}
}
RELEASE_ASSERT(!err, "could not lock mutex, error %d", err);
return err;
}
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment