Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libwebsockets
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Automate
Agent sessions
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
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This project is archived. Its data is
read-only
.
Show more breadcrumbs
Fork
libwebsockets
Commits
9cce1874
Commit
9cce1874
authored
May 2, 2018
by
Andy Green
Browse files
Options
Downloads
Patches
Plain Diff
context_destroy: figure out if anything still in event loop
parent
bce8cca0
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/context.c
+33
-0
33 additions, 0 deletions
lib/context.c
lib/private-libwebsockets.h
+1
-0
1 addition, 0 deletions
lib/private-libwebsockets.h
lib/service.c
+27
-2
27 additions, 2 deletions
lib/service.c
with
61 additions
and
2 deletions
lib/context.c
+
33
−
0
View file @
9cce1874
...
@@ -1721,6 +1721,10 @@ lws_vhost_destroy(struct lws_vhost *vh)
...
@@ -1721,6 +1721,10 @@ lws_vhost_destroy(struct lws_vhost *vh)
* destroys the context itself, setting what was info.pcontext to NULL.
* destroys the context itself, setting what was info.pcontext to NULL.
*/
*/
/*
* destroy the actual context itself
*/
static
void
static
void
lws_context_destroy3
(
struct
lws_context
*
context
)
lws_context_destroy3
(
struct
lws_context
*
context
)
{
{
...
@@ -1733,6 +1737,10 @@ lws_context_destroy3(struct lws_context *context)
...
@@ -1733,6 +1737,10 @@ lws_context_destroy3(struct lws_context *context)
*
pcontext_finalize
=
NULL
;
*
pcontext_finalize
=
NULL
;
}
}
/*
* really start destroying things
*/
void
void
lws_context_destroy2
(
struct
lws_context
*
context
)
lws_context_destroy2
(
struct
lws_context
*
context
)
{
{
...
@@ -1802,6 +1810,10 @@ lws_context_destroy2(struct lws_context *context)
...
@@ -1802,6 +1810,10 @@ lws_context_destroy2(struct lws_context *context)
lws_context_destroy3
(
context
);
lws_context_destroy3
(
context
);
}
}
/*
* Begin the context takedown
*/
LWS_VISIBLE
void
LWS_VISIBLE
void
lws_context_destroy
(
struct
lws_context
*
context
)
lws_context_destroy
(
struct
lws_context
*
context
)
{
{
...
@@ -1909,6 +1921,22 @@ lws_context_destroy(struct lws_context *context)
...
@@ -1909,6 +1921,22 @@ lws_context_destroy(struct lws_context *context)
lws_plat_context_early_destroy
(
context
);
lws_plat_context_early_destroy
(
context
);
/*
* We face two different needs depending if foreign loop or not.
*
* 1) If foreign loop, we really want to advance the destroy_context()
* past here, and block only for libuv-style async close completion.
*
* 2a) If poll, and we exited by ourselves and are calling a final
* destroy_context() outside of any service already, we want to
* advance all the way in one step.
*
* 2b) If poll, and we are reacting to a SIGINT, service thread(s) may
* be in poll wait or servicing. We can't advance the
* destroy_context() to the point it's freeing things; we have to
* leave that for the final destroy_context() after the service
* thread(s) are finished calling for service.
*/
if
(
context
->
event_loop_ops
->
destroy_context1
)
{
if
(
context
->
event_loop_ops
->
destroy_context1
)
{
context
->
event_loop_ops
->
destroy_context1
(
context
);
context
->
event_loop_ops
->
destroy_context1
(
context
);
...
@@ -1916,5 +1944,10 @@ lws_context_destroy(struct lws_context *context)
...
@@ -1916,5 +1944,10 @@ lws_context_destroy(struct lws_context *context)
return
;
return
;
}
}
if
(
!
context
->
pt
[
0
].
event_loop_foreign
)
for
(
n
=
0
;
n
<
context
->
count_threads
;
n
++
)
if
(
context
->
pt
[
n
].
inside_service
)
return
;
lws_context_destroy2
(
context
);
lws_context_destroy2
(
context
);
}
}
This diff is collapsed.
Click to expand it.
lib/private-libwebsockets.h
+
1
−
0
View file @
9cce1874
...
@@ -593,6 +593,7 @@ struct lws_context_per_thread {
...
@@ -593,6 +593,7 @@ struct lws_context_per_thread {
unsigned
char
tid
;
unsigned
char
tid
;
unsigned
char
lock_depth
;
unsigned
char
lock_depth
;
unsigned
char
inside_service
:
1
;
unsigned
char
event_loop_foreign
:
1
;
unsigned
char
event_loop_foreign
:
1
;
unsigned
char
event_loop_destroy_processing_done
:
1
;
unsigned
char
event_loop_destroy_processing_done
:
1
;
};
};
...
...
This diff is collapsed.
Click to expand it.
lib/service.c
+
27
−
2
View file @
9cce1874
...
@@ -939,24 +939,49 @@ lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd)
...
@@ -939,24 +939,49 @@ lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd)
LWS_VISIBLE
int
LWS_VISIBLE
int
lws_service
(
struct
lws_context
*
context
,
int
timeout_ms
)
lws_service
(
struct
lws_context
*
context
,
int
timeout_ms
)
{
{
struct
lws_context_per_thread
*
pt
=
&
context
->
pt
[
0
];
int
n
;
if
(
!
context
)
return
1
;
pt
->
inside_service
=
1
;
if
(
context
->
event_loop_ops
->
run_pt
)
{
if
(
context
->
event_loop_ops
->
run_pt
)
{
/* we are configured for an event loop */
/* we are configured for an event loop */
context
->
event_loop_ops
->
run_pt
(
context
,
0
);
context
->
event_loop_ops
->
run_pt
(
context
,
0
);
pt
->
inside_service
=
0
;
return
1
;
return
1
;
}
}
return
lws_plat_service
(
context
,
timeout_ms
);
n
=
lws_plat_service
(
context
,
timeout_ms
);
pt
->
inside_service
=
0
;
return
n
;
}
}
LWS_VISIBLE
int
LWS_VISIBLE
int
lws_service_tsi
(
struct
lws_context
*
context
,
int
timeout_ms
,
int
tsi
)
lws_service_tsi
(
struct
lws_context
*
context
,
int
timeout_ms
,
int
tsi
)
{
{
struct
lws_context_per_thread
*
pt
=
&
context
->
pt
[
tsi
];
int
n
;
pt
->
inside_service
=
1
;
if
(
context
->
event_loop_ops
->
run_pt
)
{
if
(
context
->
event_loop_ops
->
run_pt
)
{
/* we are configured for an event loop */
/* we are configured for an event loop */
context
->
event_loop_ops
->
run_pt
(
context
,
tsi
);
context
->
event_loop_ops
->
run_pt
(
context
,
tsi
);
pt
->
inside_service
=
0
;
return
1
;
return
1
;
}
}
return
_lws_plat_service_tsi
(
context
,
timeout_ms
,
tsi
);
n
=
_lws_plat_service_tsi
(
context
,
timeout_ms
,
tsi
);
pt
->
inside_service
=
0
;
return
n
;
}
}
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
sign in
to comment