Skip to content

Commit

Permalink
Merge pull request #338 from automaticp/no_allocation_in_log_callback
Browse files Browse the repository at this point in the history
Remove memory allocation from logging callback invocation
  • Loading branch information
scheibel authored Feb 13, 2023
2 parents aedb549 + 54a072e commit 88567ed
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion source/glbinding-aux/include/glbinding-aux/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ GLBINDING_AUX_API void resume();
* @remark
* This function is intended to get used by glbinding and not by a user of glbinding
*/
GLBINDING_AUX_API void log(LogEntry call);
GLBINDING_AUX_API void log(FunctionCall && call);


} } // namespace glbinding::aux
5 changes: 3 additions & 2 deletions source/glbinding-aux/source/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <chrono>
#include <fstream>
#include <sstream>
#include <utility>

#ifdef GLBINDING_USE_BOOST_THREAD
#include <boost/chrono.hpp>
Expand Down Expand Up @@ -148,7 +149,7 @@ void resume()
glbinding::addCallbackMask(CallbackMask::Timestamp | CallbackMask::Logging);
}

void log(LogEntry call)
void log(FunctionCall && call)
{
auto available = false;
auto next = g_buffer.nextHead(available);
Expand All @@ -162,7 +163,7 @@ void log(LogEntry call)
assert(!g_buffer.isFull());

delete next;
g_buffer.push(call);
g_buffer.push(new FunctionCall(std::move(call)));
}

void startWriter(const std::string & filepath)
Expand Down
2 changes: 1 addition & 1 deletion source/glbinding/include/glbinding/Binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class GLBINDING_API Binding
* @brief
* The callback type of a function log callback with parameters and return value
*/
using FunctionLogCallback = std::function<void(FunctionCall *)>;
using FunctionLogCallback = std::function<void(FunctionCall &&)>;

using ContextSwitchCallback = std::function<void(ContextHandle)>; ///< The signature of the context switch callback

Expand Down
2 changes: 1 addition & 1 deletion source/glbinding/include/glbinding/glbinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class FunctionCall;

using SimpleFunctionCallback = std::function<void(const AbstractFunction &)>; ///< The signature of the unresolved callback
using FunctionCallback = std::function<void(const FunctionCall &)>; ///< The signature of the before and after callbacks
using FunctionLogCallback = std::function<void(FunctionCall *)>; ///< The signature of the log callback
using FunctionLogCallback = std::function<void(FunctionCall &&)>; ///< The signature of the log callback
using ContextSwitchCallback = std::function<void(ContextHandle)>; ///< The signature of the context switch callback

/**
Expand Down
2 changes: 1 addition & 1 deletion source/glbinding/source/Binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void Binding::log(FunctionCall && call)
{
if (s_logCallback())
{
s_logCallback()(new FunctionCall(std::move(call)));
s_logCallback()(std::move(call));
}
}

Expand Down

0 comments on commit 88567ed

Please sign in to comment.