mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:17:45 +00:00
Introduce LibCore and move GElapsedTimer => CElapsedTimer.
I need a layer somewhere between AK (usable both by userspace and kernel) and LibGUI (usable by userspace except WindowServer.) So here's LibCore.
This commit is contained in:
parent
a74f3615ac
commit
5e0577a042
21 changed files with 98 additions and 37 deletions
|
@ -1,29 +0,0 @@
|
|||
#include <LibGUI/GElapsedTimer.h>
|
||||
#include <AK/Assertions.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
void GElapsedTimer::start()
|
||||
{
|
||||
m_valid = true;
|
||||
gettimeofday(&m_start_time, nullptr);
|
||||
}
|
||||
|
||||
inline void timersub(const struct timeval* a, const struct timeval* b, struct timeval* result)
|
||||
{
|
||||
result->tv_sec = a->tv_sec - b->tv_sec;
|
||||
result->tv_usec = a->tv_usec - b->tv_usec;
|
||||
if (result->tv_usec < 0) {
|
||||
--result->tv_sec;
|
||||
result->tv_usec += 1000000;
|
||||
}
|
||||
}
|
||||
|
||||
int GElapsedTimer::elapsed() const
|
||||
{
|
||||
ASSERT(is_valid());
|
||||
struct timeval now;
|
||||
gettimeofday(&now, nullptr);
|
||||
struct timeval diff;
|
||||
timersub(&now, &m_start_time, &diff);
|
||||
return diff.tv_sec * 1000 + diff.tv_usec / 1000;
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <time.h>
|
||||
|
||||
class GElapsedTimer {
|
||||
public:
|
||||
GElapsedTimer() { }
|
||||
|
||||
bool is_valid() const { return m_valid; }
|
||||
void start();
|
||||
int elapsed() const;
|
||||
|
||||
private:
|
||||
bool m_valid { false };
|
||||
struct timeval m_start_time { 0, 0 };
|
||||
};
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibGUI/GElapsedTimer.h>
|
||||
#include <LibCore/CElapsedTimer.h>
|
||||
#include <LibGUI/GEvent.h>
|
||||
#include <LibGUI/GObject.h>
|
||||
#include <SharedGraphics/Rect.h>
|
||||
|
@ -174,5 +174,5 @@ private:
|
|||
bool m_fill_with_background_color { false };
|
||||
bool m_visible { true };
|
||||
|
||||
GElapsedTimer m_click_clock;
|
||||
CElapsedTimer m_click_clock;
|
||||
};
|
||||
|
|
|
@ -52,7 +52,6 @@ LIBGUI_OBJS = \
|
|||
GAbstractView.o \
|
||||
GItemView.o \
|
||||
GIcon.o \
|
||||
GElapsedTimer.o \
|
||||
GFrame.o \
|
||||
GTreeView.o \
|
||||
GFileSystemModel.o \
|
||||
|
@ -69,8 +68,6 @@ LIBGUI_OBJS = \
|
|||
|
||||
OBJS = $(SHAREDGRAPHICS_OBJS) $(LIBGUI_OBJS)
|
||||
|
||||
LIBS = -lc
|
||||
|
||||
LIBRARY = libgui.a
|
||||
STANDARD_FLAGS = -std=c++17 -Wno-sized-deallocation
|
||||
WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fallthrough
|
||||
|
@ -88,7 +85,7 @@ AR = i686-pc-serenity-ar
|
|||
all: $(LIBRARY)
|
||||
|
||||
$(LIBRARY): $(OBJS)
|
||||
@echo "LIB $@"; $(AR) rcs $@ $(OBJS) $(LIBS)
|
||||
@echo "LIB $@"; $(AR) rcs $@ $(OBJS)
|
||||
|
||||
.cpp.o:
|
||||
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue