Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
a49ee6fc
Commit
a49ee6fc
authored
Apr 2, 1999
by
Fredrik Hübinette (Hubbe)
Browse files
Options
Downloads
Patches
Plain Diff
recursive mutexes implemented through mutex->lock(2)
Rev: src/threads.c:1.92
parent
819b1fc5
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/threads.c
+60
-26
60 additions, 26 deletions
src/threads.c
with
60 additions
and
26 deletions
src/threads.c
+
60
−
26
View file @
a49ee6fc
#include
"global.h"
RCSID
(
"$Id: threads.c,v 1.9
1
1999/0
3/21 21:34:29 gr
ubb
a
Exp $"
);
RCSID
(
"$Id: threads.c,v 1.9
2
1999/0
4/02 23:23:47 h
ubb
e
Exp $"
);
int
num_threads
=
1
;
int
threads_disabled
=
0
;
...
...
@@ -16,6 +16,7 @@ int threads_disabled = 0;
#include
"program.h"
#include
"gc.h"
#include
"main.h"
#include
"module_support.h"
int
live_threads
=
0
;
COND_T
live_threads_change
;
...
...
@@ -617,14 +618,23 @@ void f_mutex_lock(INT32 args)
{
struct
mutex_storage
*
m
;
struct
object
*
o
;
INT_TYPE
type
;
m
=
THIS_MUTEX
;
/* Needs to be cloned here, since create()
* might use threads.
*/
o
=
clone_object
(
mutex_key
,
0
);
if
(
!
args
||
IS_ZERO
(
sp
-
args
))
if
(
!
args
)
type
=
0
;
else
get_all_args
(
"mutex->lock"
,
args
,
"%i"
,
&
type
);
switch
(
type
)
{
default:
bad_arg_error
(
"mutex->lock"
,
sp
-
args
,
args
,
2
,
"int(0..2)"
,
sp
+
1
-
args
,
"Unknown mutex locking style: %d
\n
"
,
type
);
case
0
:
case
2
:
if
(
m
->
key
&&
OB2KEY
(
m
->
key
)
->
owner
==
thread_id
)
{
THREADS_FPRINTF
(
0
,
...
...
@@ -633,11 +643,21 @@ void f_mutex_lock(INT32 args)
(
unsigned
int
)
m
,
(
unsigned
int
)
OB2KEY
(
m
->
key
)
->
mut
,
(
unsigned
int
)
thread_id
));
free_object
(
o
);
error
(
"Recursive mutex locks!
\n
"
);
if
(
type
==
0
)
error
(
"Recursive mutex locks!
\n
"
);
pop_n_elems
(
args
);
push_int
(
0
);
}
case
1
:
break
;
}
/* Needs to be cloned here, since create()
* might use threads.
*/
o
=
clone_object
(
mutex_key
,
0
);
if
(
m
->
key
)
{
SWAP_OUT_CURRENT_THREAD
();
...
...
@@ -664,24 +684,39 @@ void f_mutex_trylock(INT32 args)
{
struct
mutex_storage
*
m
;
struct
object
*
o
;
int
type
;
int
i
=
0
;
o
=
clone_object
(
mutex_key
,
0
);
m
=
THIS_MUTEX
;
/* No reason to release the interpreter lock here
* since we aren't calling any functions that take time.
*/
if
(
!
args
||
IS_ZERO
(
sp
-
args
))
m
=
THIS_MUTEX
;
if
(
!
args
)
type
=
0
;
else
get_all_args
(
"mutex->lock"
,
args
,
"%i"
,
&
type
);
switch
(
type
)
{
default:
bad_arg_error
(
"mutex->trylock"
,
sp
-
args
,
args
,
2
,
"int(0..2)"
,
sp
+
1
-
args
,
"Unknown mutex locking style: %d
\n
"
,
type
);
case
0
:
if
(
m
->
key
&&
OB2KEY
(
m
->
key
)
->
owner
==
thread_id
)
{
free_object
(
o
);
error
(
"Recursive mutex locks!
\n
"
);
}
case
2
:
case
1
:
break
;
}
o
=
clone_object
(
mutex_key
,
0
);
if
(
!
m
->
key
)
{
OB2KEY
(
o
)
->
mut
=
m
;
...
...
@@ -1007,8 +1042,7 @@ void th_init(void)
start_new_program
();
ADD_STORAGE
(
struct
mutex_storage
);
/* function(int|void:object) */
ADD_FUNCTION
(
"lock"
,
f_mutex_lock
,
tFunc
(
tOr
(
tInt
,
tVoid
),
tObj
),
0
);
add_function
(
"lock"
,
f_mutex_lock
,
"function(int(0..2)|void:object)"
,
0
);
/* function(int|void:object) */
ADD_FUNCTION
(
"trylock"
,
f_mutex_trylock
,
tFunc
(
tOr
(
tInt
,
tVoid
),
tObj
),
0
);
set_init_callback
(
init_mutex_obj
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment