Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
3d505b2b
Commit
3d505b2b
authored
10 years ago
by
Loïc Blot
Browse files
Options
Downloads
Patches
Plain Diff
Use std::queue for HTTPFetchRequest and std::vector for log_output instead of std::list
parent
9749d9fe
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/httpfetch.cpp
+8
-8
8 additions, 8 deletions
src/httpfetch.cpp
src/log.cpp
+15
-18
15 additions, 18 deletions
src/log.cpp
with
23 additions
and
26 deletions
src/httpfetch.cpp
+
8
−
8
View file @
3d505b2b
...
...
@@ -37,7 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include
"settings.h"
JMutex
g_httpfetch_mutex
;
std
::
map
<
unsigned
long
,
std
::
list
<
HTTPFetchResult
>
>
g_httpfetch_results
;
std
::
map
<
unsigned
long
,
std
::
queue
<
HTTPFetchResult
>
>
g_httpfetch_results
;
HTTPFetchRequest
::
HTTPFetchRequest
()
{
...
...
@@ -57,7 +57,7 @@ static void httpfetch_deliver_result(const HTTPFetchResult &fetch_result)
unsigned
long
caller
=
fetch_result
.
caller
;
if
(
caller
!=
HTTPFETCH_DISCARD
)
{
JMutexAutoLock
lock
(
g_httpfetch_mutex
);
g_httpfetch_results
[
caller
].
push
_back
(
fetch_result
);
g_httpfetch_results
[
caller
].
push
(
fetch_result
);
}
}
...
...
@@ -70,11 +70,11 @@ unsigned long httpfetch_caller_alloc()
// Check each caller ID except HTTPFETCH_DISCARD
const
unsigned
long
discard
=
HTTPFETCH_DISCARD
;
for
(
unsigned
long
caller
=
discard
+
1
;
caller
!=
discard
;
++
caller
)
{
std
::
map
<
unsigned
long
,
std
::
list
<
HTTPFetchResult
>
>::
iterator
std
::
map
<
unsigned
long
,
std
::
queue
<
HTTPFetchResult
>
>::
iterator
it
=
g_httpfetch_results
.
find
(
caller
);
if
(
it
==
g_httpfetch_results
.
end
())
{
verbosestream
<<
"httpfetch_caller_alloc: allocating "
<<
caller
<<
std
::
endl
;
verbosestream
<<
"httpfetch_caller_alloc: allocating "
<<
caller
<<
std
::
endl
;
// Access element to create it
g_httpfetch_results
[
caller
];
return
caller
;
...
...
@@ -102,19 +102,19 @@ bool httpfetch_async_get(unsigned long caller, HTTPFetchResult &fetch_result)
JMutexAutoLock
lock
(
g_httpfetch_mutex
);
// Check that caller exists
std
::
map
<
unsigned
long
,
std
::
list
<
HTTPFetchResult
>
>::
iterator
std
::
map
<
unsigned
long
,
std
::
queue
<
HTTPFetchResult
>
>::
iterator
it
=
g_httpfetch_results
.
find
(
caller
);
if
(
it
==
g_httpfetch_results
.
end
())
return
false
;
// Check that result queue is nonempty
std
::
list
<
HTTPFetchResult
>
&
caller_results
=
it
->
second
;
std
::
queue
<
HTTPFetchResult
>
&
caller_results
=
it
->
second
;
if
(
caller_results
.
empty
())
return
false
;
// Pop first result
fetch_result
=
caller_results
.
front
();
caller_results
.
pop
_front
();
caller_results
.
pop
();
return
true
;
}
...
...
This diff is collapsed.
Click to expand it.
src/log.cpp
+
15
−
18
View file @
3d505b2b
...
...
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include
<sstream>
#include
<algorithm>
#include
"threads.h"
#include
"jthread/jmutexautolock.h"
#include
"debug.h"
#include
"gettime.h"
#include
"porting.h"
...
...
@@ -38,7 +39,7 @@ unsigned int android_log_level_mapping[] = {
};
#endif
std
::
list
<
ILogOutput
*>
log_outputs
[
LMT_NUM_VALUES
];
std
::
vector
<
ILogOutput
*>
log_outputs
[
LMT_NUM_VALUES
];
std
::
map
<
threadid_t
,
std
::
string
>
log_threadnames
;
JMutex
log_threadnamemutex
;
...
...
@@ -62,7 +63,7 @@ void log_add_output_all_levs(ILogOutput *out)
void
log_remove_output
(
ILogOutput
*
out
)
{
for
(
int
i
=
0
;
i
<
LMT_NUM_VALUES
;
i
++
){
std
::
list
<
ILogOutput
*>::
iterator
it
=
std
::
vector
<
ILogOutput
*>::
iterator
it
=
std
::
find
(
log_outputs
[
i
].
begin
(),
log_outputs
[
i
].
end
(),
out
);
if
(
it
!=
log_outputs
[
i
].
end
())
log_outputs
[
i
].
erase
(
it
);
...
...
@@ -71,33 +72,29 @@ void log_remove_output(ILogOutput *out)
void
log_set_lev_silence
(
enum
LogMessageLevel
lev
,
bool
silence
)
{
log_threadnamemutex
.
Lock
(
);
JMutexAutoLock
lock
(
log_threadnamemutex
);
for
(
std
::
list
<
ILogOutput
*>::
iterator
it
=
log_outputs
[
lev
].
begin
();
it
!=
log_outputs
[
lev
].
end
();
++
it
)
{
for
(
std
::
vector
<
ILogOutput
*>::
iterator
it
=
log_outputs
[
lev
].
begin
();
it
!=
log_outputs
[
lev
].
end
();
++
it
)
{
ILogOutput
*
out
=
*
it
;
out
->
silence
=
silence
;
}
log_threadnamemutex
.
Unlock
();
}
void
log_register_thread
(
const
std
::
string
&
name
)
{
threadid_t
id
=
get_current_thread_id
();
log_threadnamemutex
.
Lock
();
JMutexAutoLock
lock
(
log_threadnamemutex
);
log_threadnames
[
id
]
=
name
;
log_threadnamemutex
.
Unlock
();
}
void
log_deregister_thread
()
{
threadid_t
id
=
get_current_thread_id
();
log_threadnamemutex
.
Lock
();
JMutexAutoLock
lock
(
log_threadnamemutex
);
log_threadnames
.
erase
(
id
);
log_threadnamemutex
.
Unlock
();
}
static
std
::
string
get_lev_string
(
enum
LogMessageLevel
lev
)
...
...
@@ -119,7 +116,7 @@ static std::string get_lev_string(enum LogMessageLevel lev)
void
log_printline
(
enum
LogMessageLevel
lev
,
const
std
::
string
&
text
)
{
log_threadnamemutex
.
Lock
(
);
JMutexAutoLock
lock
(
log_threadnamemutex
);
std
::
string
threadname
=
"(unknown thread)"
;
std
::
map
<
threadid_t
,
std
::
string
>::
const_iterator
i
;
i
=
log_threadnames
.
find
(
get_current_thread_id
());
...
...
@@ -127,9 +124,10 @@ void log_printline(enum LogMessageLevel lev, const std::string &text)
threadname
=
i
->
second
;
std
::
string
levelname
=
get_lev_string
(
lev
);
std
::
ostringstream
os
(
std
::
ios_base
::
binary
);
os
<<
getTimestamp
()
<<
": "
<<
levelname
<<
"["
<<
threadname
<<
"]: "
<<
text
;
for
(
std
::
list
<
ILogOutput
*>::
iterator
i
=
log_outputs
[
lev
].
begin
();
i
!=
log_outputs
[
lev
].
end
();
i
++
){
os
<<
getTimestamp
()
<<
": "
<<
levelname
<<
"["
<<
threadname
<<
"]: "
<<
text
;
for
(
std
::
vector
<
ILogOutput
*>::
iterator
i
=
log_outputs
[
lev
].
begin
();
i
!=
log_outputs
[
lev
].
end
();
i
++
)
{
ILogOutput
*
out
=
*
i
;
if
(
out
->
silence
)
continue
;
...
...
@@ -138,7 +136,6 @@ void log_printline(enum LogMessageLevel lev, const std::string &text)
out
->
printLog
(
os
.
str
(),
lev
);
out
->
printLog
(
lev
,
text
);
}
log_threadnamemutex
.
Unlock
();
}
class
Logbuf
:
public
std
::
streambuf
...
...
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