-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For #2188, Threads, refine API and main workflow.
1. Use SrsThreadPool to execute the hybrid server. 2. Right now, directly run in primordial thread, that is no threads. 3. Define the main APIs of SrsThreadPool.
- Loading branch information
Showing
4 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2013-2020 Winlin | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#include <srs_app_threads.hpp> | ||
|
||
#include <srs_kernel_error.hpp> | ||
|
||
SrsThreadPool::SrsThreadPool() | ||
{ | ||
} | ||
|
||
SrsThreadPool::~SrsThreadPool() | ||
{ | ||
} | ||
|
||
srs_error_t SrsThreadPool::initialize() | ||
{ | ||
srs_error_t err = srs_success; | ||
return err; | ||
} | ||
|
||
srs_error_t SrsThreadPool::execute(srs_error_t (*start)(void* arg), void* arg) | ||
{ | ||
srs_error_t err = start(arg); | ||
return err; | ||
} | ||
|
||
srs_error_t SrsThreadPool::run() | ||
{ | ||
srs_error_t err = srs_success; | ||
return err; | ||
} | ||
|
||
void SrsThreadPool::stop() | ||
{ | ||
} | ||
|
||
SrsThreadPool* _srs_thread_pool = new SrsThreadPool(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2013-2020 Winlin | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#ifndef SRS_APP_THREADS_HPP | ||
#define SRS_APP_THREADS_HPP | ||
|
||
#include <srs_core.hpp> | ||
|
||
// Allocate a(or almost) fixed thread poll to execute tasks, | ||
// so that we can take the advantage of multiple CPUs. | ||
class SrsThreadPool | ||
{ | ||
public: | ||
SrsThreadPool(); | ||
virtual ~SrsThreadPool(); | ||
public: | ||
// Initialize the thread pool. | ||
srs_error_t initialize(); | ||
// Execute start function in thread. | ||
srs_error_t execute(srs_error_t (*start)(void* arg), void* arg); | ||
// Run in the primordial thread, util stop or quit. | ||
srs_error_t run(); | ||
// Stop the thread pool and quit the primordial thread. | ||
void stop(); | ||
}; | ||
|
||
// The global thread pool. | ||
extern SrsThreadPool* _srs_thread_pool; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters