Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Kirill Smelkov
cpython
Commits
d0c1042f
Commit
d0c1042f
authored
Dec 17, 1996
by
Barry Warsaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed.
parent
8069f438
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
102 additions
and
102 deletions
+102
-102
Modules/threadmodule.c
Modules/threadmodule.c
+102
-102
No files found.
Modules/threadmodule.c
View file @
d0c1042f
...
...
@@ -32,7 +32,7 @@ PERFORMANCE OF THIS SOFTWARE.
/* Thread module */
/* Interface to Sjoerd's portable C thread library */
#include "
allobjects
.h"
#include "
Python
.h"
#ifndef WITH_THREAD
Error
!
The
rest
of
Python
is
not
compiled
with
thread
support
.
...
...
@@ -41,25 +41,25 @@ Rerun configure, adding a --with-thread option.
#include "thread.h"
extern
int
threads_s
tarted
;
extern
int
_PyThread_S
tarted
;
static
o
bject
*
ThreadError
;
static
PyO
bject
*
ThreadError
;
/* Lock objects */
typedef
struct
{
OB
_HEAD
PyObject
_HEAD
type_lock
lock_lock
;
}
lockobject
;
staticforward
typeo
bject
Locktype
;
staticforward
PyTypeO
bject
Locktype
;
#define is_lockobject(v) ((v)->ob_type == &Locktype)
type_lock
getlocklock
(
lock
)
o
bject
*
lock
;
PyO
bject
*
lock
;
{
if
(
lock
==
NULL
||
!
is_lockobject
(
lock
))
return
NULL
;
...
...
@@ -71,14 +71,14 @@ static lockobject *
newlockobject
()
{
lockobject
*
self
;
self
=
NEWOBJ
(
lockobject
,
&
Locktype
);
self
=
PyObject_NEW
(
lockobject
,
&
Locktype
);
if
(
self
==
NULL
)
return
NULL
;
self
->
lock_lock
=
allocate_lock
();
if
(
self
->
lock_lock
==
NULL
)
{
DEL
(
self
);
PyMem_
DEL
(
self
);
self
=
NULL
;
err_setstr
(
ThreadError
,
"can't allocate lock"
);
PyErr_SetString
(
ThreadError
,
"can't allocate lock"
);
}
return
self
;
}
...
...
@@ -92,90 +92,90 @@ lock_dealloc(self)
release_lock
(
self
->
lock_lock
);
free_lock
(
self
->
lock_lock
);
DEL
(
self
);
PyMem_
DEL
(
self
);
}
static
o
bject
*
static
PyO
bject
*
lock_acquire_lock
(
self
,
args
)
lockobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
int
i
;
if
(
args
!=
NULL
)
{
if
(
!
getargs
(
args
,
"i"
,
&
i
))
if
(
!
PyArg_Parse
(
args
,
"i"
,
&
i
))
return
NULL
;
}
else
i
=
1
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
i
=
acquire_lock
(
self
->
lock_lock
,
i
);
END_SAVE
Py_END_ALLOW_THREADS
if
(
args
==
NULL
)
{
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
else
return
newintobject
((
long
)
i
);
return
PyInt_FromLong
((
long
)
i
);
}
static
o
bject
*
static
PyO
bject
*
lock_release_lock
(
self
,
args
)
lockobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
/* Sanity check: the lock must be locked */
if
(
acquire_lock
(
self
->
lock_lock
,
0
))
{
release_lock
(
self
->
lock_lock
);
err_setstr
(
ThreadError
,
"release unlocked lock"
);
PyErr_SetString
(
ThreadError
,
"release unlocked lock"
);
return
NULL
;
}
release_lock
(
self
->
lock_lock
);
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
lock_locked_lock
(
self
,
args
)
lockobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
if
(
acquire_lock
(
self
->
lock_lock
,
0
))
{
release_lock
(
self
->
lock_lock
);
return
newintobject
(
0L
);
return
PyInt_FromLong
(
0L
);
}
return
newintobject
(
1L
);
return
PyInt_FromLong
(
1L
);
}
static
struct
methodlist
lock_methods
[]
=
{
{
"acquire_lock"
,
(
method
)
lock_acquire_lock
},
{
"acquire"
,
(
method
)
lock_acquire_lock
},
{
"release_lock"
,
(
method
)
lock_release_lock
},
{
"release"
,
(
method
)
lock_release_lock
},
{
"locked_lock"
,
(
method
)
lock_locked_lock
},
{
"locked"
,
(
method
)
lock_locked_lock
},
static
PyMethodDef
lock_methods
[]
=
{
{
"acquire_lock"
,
(
PyCFunction
)
lock_acquire_lock
},
{
"acquire"
,
(
PyCFunction
)
lock_acquire_lock
},
{
"release_lock"
,
(
PyCFunction
)
lock_release_lock
},
{
"release"
,
(
PyCFunction
)
lock_release_lock
},
{
"locked_lock"
,
(
PyCFunction
)
lock_locked_lock
},
{
"locked"
,
(
PyCFunction
)
lock_locked_lock
},
{
NULL
,
NULL
}
/* sentinel */
};
static
o
bject
*
static
PyO
bject
*
lock_getattr
(
self
,
name
)
lockobject
*
self
;
char
*
name
;
{
return
findmethod
(
lock_methods
,
(
o
bject
*
)
self
,
name
);
return
Py_FindMethod
(
lock_methods
,
(
PyO
bject
*
)
self
,
name
);
}
static
typeo
bject
Locktype
=
{
OB_HEAD_INIT
(
&
Typet
ype
)
static
PyTypeO
bject
Locktype
=
{
PyObject_HEAD_INIT
(
&
PyType_T
ype
)
0
,
/*ob_size*/
"lock"
,
/*tp_name*/
sizeof
(
lockobject
),
/*tp_size*/
...
...
@@ -196,113 +196,113 @@ static void
t_bootstrap
(
args_raw
)
void
*
args_raw
;
{
object
*
args
=
(
o
bject
*
)
args_raw
;
o
bject
*
func
,
*
arg
,
*
res
;
PyObject
*
args
=
(
PyO
bject
*
)
args_raw
;
PyO
bject
*
func
,
*
arg
,
*
res
;
threads_s
tarted
++
;
_PyThread_S
tarted
++
;
restore_t
hread
((
void
*
)
NULL
);
func
=
gettuplei
tem
(
args
,
0
);
arg
=
gettuplei
tem
(
args
,
1
);
res
=
call_o
bject
(
func
,
arg
);
DECREF
(
args
);
/* Matches the INCREF(args) in thread_start_new_thread */
PyEval_RestoreT
hread
((
void
*
)
NULL
);
func
=
PyTuple_GetI
tem
(
args
,
0
);
arg
=
PyTuple_GetI
tem
(
args
,
1
);
res
=
PyEval_CallO
bject
(
func
,
arg
);
Py_
DECREF
(
args
);
/* Matches the INCREF(args) in thread_start_new_thread */
if
(
res
==
NULL
)
{
if
(
err_occurred
()
==
SystemExit
)
err_c
lear
();
if
(
PyErr_Occurred
()
==
PyExc_
SystemExit
)
PyErr_C
lear
();
else
{
fprintf
(
stderr
,
"Unhandled exception in thread:
\n
"
);
print_error
();
/* From pythonmain.c */
PyErr_Print
();
/* From pythonmain.c */
}
}
else
DECREF
(
res
);
(
void
)
save_t
hread
();
/* Should always be NULL */
Py_
DECREF
(
res
);
(
void
)
PyEval_SaveT
hread
();
/* Should always be NULL */
exit_thread
();
}
static
o
bject
*
static
PyO
bject
*
thread_start_new_thread
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
o
bject
*
func
,
*
arg
;
PyO
bject
*
func
,
*
arg
;
if
(
!
getargs
(
args
,
"(OO)"
,
&
func
,
&
arg
))
if
(
!
PyArg_Parse
(
args
,
"(OO)"
,
&
func
,
&
arg
))
return
NULL
;
INCREF
(
args
);
Py_
INCREF
(
args
);
/* Initialize the interpreter's stack save/restore mechanism */
init_save_thread
();
PyEval_InitThreads
();
if
(
!
start_new_thread
(
t_bootstrap
,
(
void
*
)
args
))
{
DECREF
(
args
);
err_setstr
(
ThreadError
,
"can't start new thread
\n
"
);
Py_
DECREF
(
args
);
PyErr_SetString
(
ThreadError
,
"can't start new thread
\n
"
);
return
NULL
;
}
/* Otherwise the DECREF(args) is done by t_bootstrap */
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
thread_exit_thread
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
err_set
(
SystemExit
);
PyErr_SetNone
(
PyExc_
SystemExit
);
return
NULL
;
}
#ifndef NO_EXIT_PROG
static
o
bject
*
static
PyO
bject
*
thread_exit_prog
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
int
sts
;
if
(
!
getargs
(
args
,
"i"
,
&
sts
))
if
(
!
PyArg_Parse
(
args
,
"i"
,
&
sts
))
return
NULL
;
goaway
(
sts
);
/* Calls exit_prog(sts) or _exit_prog(sts) */
Py_Exit
(
sts
);
/* Calls exit_prog(sts) or _exit_prog(sts) */
for
(;;)
{
}
/* Should not be reached */
}
#endif
static
o
bject
*
static
PyO
bject
*
thread_allocate_lock
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
return
(
o
bject
*
)
newlockobject
();
return
(
PyO
bject
*
)
newlockobject
();
}
static
o
bject
*
static
PyO
bject
*
thread_get_ident
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
long
ident
;
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
ident
=
get_thread_ident
();
if
(
ident
==
-
1
)
{
err_setstr
(
ThreadError
,
"no current thread ident"
);
PyErr_SetString
(
ThreadError
,
"no current thread ident"
);
return
NULL
;
}
return
newintobject
(
ident
);
return
PyInt_FromLong
(
ident
);
}
static
struct
methodlist
thread_methods
[]
=
{
{
"start_new_thread"
,
(
method
)
thread_start_new_thread
},
{
"start_new"
,
(
method
)
thread_start_new_thread
},
{
"allocate_lock"
,
(
method
)
thread_allocate_lock
},
{
"allocate"
,
(
method
)
thread_allocate_lock
},
{
"exit_thread"
,
(
method
)
thread_exit_thread
},
{
"exit"
,
(
method
)
thread_exit_thread
},
{
"get_ident"
,
(
method
)
thread_get_ident
},
static
PyMethodDef
thread_methods
[]
=
{
{
"start_new_thread"
,
(
PyCFunction
)
thread_start_new_thread
},
{
"start_new"
,
(
PyCFunction
)
thread_start_new_thread
},
{
"allocate_lock"
,
(
PyCFunction
)
thread_allocate_lock
},
{
"allocate"
,
(
PyCFunction
)
thread_allocate_lock
},
{
"exit_thread"
,
(
PyCFunction
)
thread_exit_thread
},
{
"exit"
,
(
PyCFunction
)
thread_exit_thread
},
{
"get_ident"
,
(
PyCFunction
)
thread_get_ident
},
#ifndef NO_EXIT_PROG
{
"exit_prog"
,
(
method
)
thread_exit_prog
},
{
"exit_prog"
,
(
PyCFunction
)
thread_exit_prog
},
#endif
{
NULL
,
NULL
}
/* sentinel */
};
...
...
@@ -313,20 +313,20 @@ static struct methodlist thread_methods[] = {
void
initthread
()
{
o
bject
*
m
,
*
d
;
PyO
bject
*
m
,
*
d
;
/* Create the module and add the functions */
m
=
initm
odule
(
"thread"
,
thread_methods
);
m
=
Py_InitM
odule
(
"thread"
,
thread_methods
);
/* Add a symbolic constant */
d
=
getmoduled
ict
(
m
);
ThreadError
=
newstringobject
(
"thread.error"
);
INCREF
(
ThreadError
);
dictinsert
(
d
,
"error"
,
ThreadError
);
d
=
PyModule_GetD
ict
(
m
);
ThreadError
=
PyString_FromString
(
"thread.error"
);
Py_
INCREF
(
ThreadError
);
PyDict_SetItemString
(
d
,
"error"
,
ThreadError
);
/* Check for errors */
if
(
err_o
ccurred
())
fatal
(
"can't initialize module thread"
);
if
(
PyErr_O
ccurred
())
Py_FatalError
(
"can't initialize module thread"
);
/* Initialize the C thread library */
init_thread
();
...
...
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