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
732ddafa
Commit
732ddafa
authored
Aug 05, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add thead.lock locked() and locked_lock()
parent
e5da6ef5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
0 deletions
+18
-0
src/runtime/builtin_modules/thread.cpp
src/runtime/builtin_modules/thread.cpp
+14
-0
test/tests/thread_test.py
test/tests/thread_test.py
+4
-0
No files found.
src/runtime/builtin_modules/thread.cpp
View file @
732ddafa
...
...
@@ -163,6 +163,17 @@ public:
PyThread_free_lock
(
self
->
lock_lock
);
}
}
static
Box
*
locked
(
Box
*
_self
)
{
RELEASE_ASSERT
(
_self
->
cls
==
thread_lock_cls
,
""
);
BoxedThreadLock
*
self
=
static_cast
<
BoxedThreadLock
*>
(
_self
);
if
(
PyThread_acquire_lock
(
self
->
lock_lock
,
0
))
{
PyThread_release_lock
(
self
->
lock_lock
);
return
False
;
}
return
True
;
}
};
...
...
@@ -211,6 +222,9 @@ void setupThread() {
thread_lock_cls
->
giveAttr
(
"release_lock"
,
thread_lock_cls
->
getattr
(
internStringMortal
(
"release"
)));
thread_lock_cls
->
giveAttr
(
"__enter__"
,
thread_lock_cls
->
getattr
(
internStringMortal
(
"acquire"
)));
thread_lock_cls
->
giveAttr
(
"__exit__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedThreadLock
::
exit
,
NONE
,
4
)));
thread_lock_cls
->
giveAttr
(
"locked"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedThreadLock
::
locked
,
BOXED_BOOL
,
1
)));
thread_lock_cls
->
giveAttr
(
"locked_lock"
,
thread_lock_cls
->
getattr
(
internStringMortal
(
"locked"
)));
thread_lock_cls
->
freeze
();
ThreadError
=
BoxedHeapClass
::
create
(
type_cls
,
Exception
,
NULL
,
Exception
->
attrs_offset
,
...
...
test/tests/thread_test.py
View file @
732ddafa
...
...
@@ -30,9 +30,13 @@ while not done:
time
.
sleep
(
0
)
l
=
allocate_lock
()
print
"locked:"
,
l
.
locked
()
print
l
.
acquire
()
print
"locked:"
,
l
.
locked
()
print
l
.
acquire
(
0
)
print
"locked:"
,
l
.
locked
()
print
l
.
release
()
print
"locked:"
,
l
.
locked
()
print
l
.
acquire
(
0
)
...
...
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