mirror of
https://github.com/godotengine/godot.git
synced 2025-10-29 04:34:39 +00:00
Modernize atomics
- Based on C++11's `atomic` - Reworked `SafeRefCount` (based on the rewrite by @hpvb) - Replaced free atomic functions by the new `SafeNumeric<T>` - Replaced wrong cases of `volatile` by the new `SafeFlag` - Platform-specific implementations no longer needed Co-authored-by: Hein-Pieter van Braam-Stewart <hp@tmm.cx>
This commit is contained in:
parent
6d89f675b1
commit
4485b43a57
54 changed files with 641 additions and 676 deletions
|
|
@ -49,7 +49,7 @@ Error HTTPRequest::_parse_url(const String &p_url) {
|
|||
got_response = false;
|
||||
body_len = -1;
|
||||
body.resize(0);
|
||||
downloaded = 0;
|
||||
downloaded.set(0);
|
||||
redirections = 0;
|
||||
|
||||
String url_lower = url.to_lower();
|
||||
|
|
@ -108,10 +108,10 @@ Error HTTPRequest::request(const String &p_url, const Vector<String> &p_custom_h
|
|||
|
||||
requesting = true;
|
||||
|
||||
if (use_threads) {
|
||||
if (use_threads.is_set()) {
|
||||
|
||||
thread_done = false;
|
||||
thread_request_quit = false;
|
||||
thread_done.clear();
|
||||
thread_request_quit.clear();
|
||||
client->set_blocking_mode(true);
|
||||
thread.start(_thread_func, this);
|
||||
} else {
|
||||
|
|
@ -137,7 +137,7 @@ void HTTPRequest::_thread_func(void *p_userdata) {
|
|||
if (err != OK) {
|
||||
hr->call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PoolStringArray(), PoolByteArray());
|
||||
} else {
|
||||
while (!hr->thread_request_quit) {
|
||||
while (!hr->thread_request_quit.is_set()) {
|
||||
|
||||
bool exit = hr->_update_connection();
|
||||
if (exit)
|
||||
|
|
@ -146,7 +146,7 @@ void HTTPRequest::_thread_func(void *p_userdata) {
|
|||
}
|
||||
}
|
||||
|
||||
hr->thread_done = true;
|
||||
hr->thread_done.set();
|
||||
}
|
||||
|
||||
void HTTPRequest::cancel_request() {
|
||||
|
|
@ -156,10 +156,10 @@ void HTTPRequest::cancel_request() {
|
|||
if (!requesting)
|
||||
return;
|
||||
|
||||
if (!use_threads) {
|
||||
if (!use_threads.is_set()) {
|
||||
set_process_internal(false);
|
||||
} else {
|
||||
thread_request_quit = true;
|
||||
thread_request_quit.set();
|
||||
thread.wait_to_finish();
|
||||
}
|
||||
|
||||
|
|
@ -188,7 +188,7 @@ bool HTTPRequest::_handle_response(bool *ret_value) {
|
|||
List<String> rheaders;
|
||||
client->get_response_headers(&rheaders);
|
||||
response_headers.resize(0);
|
||||
downloaded = 0;
|
||||
downloaded.set(0);
|
||||
for (List<String>::Element *E = rheaders.front(); E; E = E->next()) {
|
||||
response_headers.push_back(E->get());
|
||||
}
|
||||
|
|
@ -229,7 +229,7 @@ bool HTTPRequest::_handle_response(bool *ret_value) {
|
|||
got_response = false;
|
||||
body_len = -1;
|
||||
body.resize(0);
|
||||
downloaded = 0;
|
||||
downloaded.set(0);
|
||||
redirections = new_redirs;
|
||||
*ret_value = false;
|
||||
return true;
|
||||
|
|
@ -349,7 +349,7 @@ bool HTTPRequest::_update_connection() {
|
|||
client->poll();
|
||||
|
||||
PoolByteArray chunk = client->read_response_body_chunk();
|
||||
downloaded += chunk.size();
|
||||
downloaded.add(chunk.size());
|
||||
|
||||
if (file) {
|
||||
PoolByteArray::Read r = chunk.read();
|
||||
|
|
@ -362,14 +362,14 @@ bool HTTPRequest::_update_connection() {
|
|||
body.append_array(chunk);
|
||||
}
|
||||
|
||||
if (body_size_limit >= 0 && downloaded > body_size_limit) {
|
||||
if (body_size_limit >= 0 && downloaded.get() > body_size_limit) {
|
||||
call_deferred("_request_done", RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PoolByteArray());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (body_len >= 0) {
|
||||
|
||||
if (downloaded == body_len) {
|
||||
if (downloaded.get() == body_len) {
|
||||
call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, body);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -404,7 +404,7 @@ void HTTPRequest::_notification(int p_what) {
|
|||
|
||||
if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
|
||||
|
||||
if (use_threads)
|
||||
if (use_threads.is_set())
|
||||
return;
|
||||
bool done = _update_connection();
|
||||
if (done) {
|
||||
|
|
@ -424,12 +424,12 @@ void HTTPRequest::_notification(int p_what) {
|
|||
void HTTPRequest::set_use_threads(bool p_use) {
|
||||
|
||||
ERR_FAIL_COND(get_http_client_status() != HTTPClient::STATUS_DISCONNECTED);
|
||||
use_threads = p_use;
|
||||
use_threads.set_to(p_use);
|
||||
}
|
||||
|
||||
bool HTTPRequest::is_using_threads() const {
|
||||
|
||||
return use_threads;
|
||||
return use_threads.is_set();
|
||||
}
|
||||
|
||||
void HTTPRequest::set_body_size_limit(int p_bytes) {
|
||||
|
|
@ -483,7 +483,7 @@ int HTTPRequest::get_max_redirects() const {
|
|||
|
||||
int HTTPRequest::get_downloaded_bytes() const {
|
||||
|
||||
return downloaded;
|
||||
return downloaded.get();
|
||||
}
|
||||
int HTTPRequest::get_body_size() const {
|
||||
return body_len;
|
||||
|
|
@ -577,9 +577,6 @@ HTTPRequest::HTTPRequest() {
|
|||
request_sent = false;
|
||||
requesting = false;
|
||||
client.instance();
|
||||
use_threads = false;
|
||||
thread_done = false;
|
||||
downloaded = 0;
|
||||
body_size_limit = -1;
|
||||
file = NULL;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue