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
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Fork
libwebsockets
Commits
0d8b11d2
Commit
0d8b11d2
authored
7 years ago
by
Andy Green
Browse files
Options
Downloads
Patches
Plain Diff
smp: add user pthread helpers that are NOP for LWS_SMP_MAX == 1
parent
3de2e9aa
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
READMEs/README.coding.md
+30
-5
30 additions, 5 deletions
READMEs/README.coding.md
lib/libwebsockets.h
+43
-0
43 additions, 0 deletions
lib/libwebsockets.h
with
73 additions
and
5 deletions
READMEs/README.coding.md
+
30
−
5
View file @
0d8b11d2
...
...
@@ -899,18 +899,43 @@ You can set fd_limit_per_thread to a nonzero number to control this manually, eg
the overall supported fd limit is less than the process allowance.
You can control the context basic data allocation for multithreading from Cmake
using -DLWS_MAX_SMP=, if not given it's set to
32
. The serv_buf allocation
using -DLWS_MAX_SMP=, if not given it's set to
1
. The serv_buf allocation
for the threads (currently 4096) is made at runtime only for active threads.
Because lws will limit the requested number of actual threads supported
according to LWS_MAX_SMP, there is an api lws_get_count_threads(context) to
discover how many threads were actually allowed when the context was created.
It's required to implement locking in the user code in the same way that
libwebsockets-test-server-pthread does it, for the FD locking callbacks.
See the test-server-pthreads.c sample for how to use.
There is no knowledge or dependency in lws itself about pthreads. How the
locking is implemented is entirely up to the user code.
@section smplocking SMP Locking Helpers
Lws provide a set of pthread mutex helpers that reduce to no code or
variable footprint in the case that LWS_MAX_SMP == 1.
Define your user mutex like this
```
lws_pthread_mutex(name);
```
If LWS_MAX_SMP > 1, this produces `
pthread_mutex_t name;
`. In the case
LWS_MAX_SMP == 1, it produces nothing.
Likewise these helpers for init, destroy, lock and unlock
```
void lws_pthread_mutex_init(pthread_mutex_t *lock)
void lws_pthread_mutex_destroy(pthread_mutex_t *lock)
void lws_pthread_mutex_lock(pthread_mutex_t *lock)
void lws_pthread_mutex_unlock(pthread_mutex_t *lock)
```
resolve to nothing if LWS_MAX_SMP == 1, otherwise produce the equivalent
pthread api.
pthreads is required in lws only if LWS_MAX_SMP > 1.
@section libevuv libev / libuv / libevent support
...
...
This diff is collapsed.
Click to expand it.
lib/libwebsockets.h
+
43
−
0
View file @
0d8b11d2
...
...
@@ -215,6 +215,49 @@ typedef unsigned long long lws_intptr_t;
#endif
/* not USE_WOLFSSL */
#endif
/*
* Helpers for pthread mutex in user code... if lws is built for
* multiple service threads, these resolve to pthread mutex
* operations. In the case LWS_MAX_SMP is 1 (the default), they
* are all NOPs and no pthread type or api is referenced.
*/
#if LWS_MAX_SMP > 1
#define lws_pthread_mutex(name) pthread_mutex_t name
static
LWS_INLINE
void
lws_pthread_mutex_init
(
pthread_mutex_t
*
lock
)
{
pthread_mutex_init
(
lock
,
NULL
);
}
static
LWS_INLINE
void
lws_pthread_mutex_destroy
(
pthread_mutex_t
*
lock
)
{
pthread_mutex_destroy
(
lock
);
}
static
LWS_INLINE
void
lws_pthread_mutex_lock
(
pthread_mutex_t
*
lock
)
{
pthread_mutex_lock
(
lock
);
}
static
LWS_INLINE
void
lws_pthread_mutex_unlock
(
pthread_mutex_t
*
lock
)
{
pthread_mutex_unlock
(
lock
);
}
#else
#define lws_pthread_mutex(name)
#define lws_pthread_mutex_init(_a)
#define lws_pthread_mutex_destroy(_a)
#define lws_pthread_mutex_lock(_a)
#define lws_pthread_mutex_unlock(_a)
#endif
#define CONTEXT_PORT_NO_LISTEN -1
#define CONTEXT_PORT_NO_LISTEN_SERVER -2
...
...
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