appwindow.c
fpscounter.c
keyblogger.c
- main.c)
+ main.c
+ shared.c)
add_executable(lfsLinBench ${lfsLinBench_SRCS})
-target_link_libraries(lfsLinBench ${X11_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} m cap)
\ No newline at end of file
+target_link_libraries(lfsLinBench ${X11_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} m cap)
*/
#include "appwindow.h"
-#include "sharedstructs.h"
+#include "shared.h"
#include <X11/Xutil.h>
#include <X11/keysym.h>
case KeyPress:
if (Xev.xkey.keycode == KC_Q) {
run_loop = 0;
- pthread_mutex_lock(etd->exit_mutex);
- *(etd->pexit_app) = 1;
- pthread_mutex_unlock(etd->exit_mutex);
+ stop_app(etd);
}
+ break;
case Expose:
redraw_window();
break;
case ClientMessage:
if (Xev.xclient.data.l[0] == wmDeleteWindow) {
run_loop = 0;
- pthread_mutex_lock(etd->exit_mutex);
- *(etd->pexit_app) = 1;
- pthread_mutex_unlock(etd->exit_mutex);
+ stop_app(etd);
}
break;
default:
}
/* Check if we should exit the loop */
- pthread_mutex_lock(etd->exit_mutex);
- if (*(etd->pexit_app) == 1)
+ if (is_app_stopped(etd))
run_loop = 0;
- pthread_mutex_unlock(etd->exit_mutex);
}
return NULL;
if (lfs_pid == 0)
lfs_pid = find_pid_by_name(noexe);
- pthread_mutex_lock(etd->exit_mutex);
- if (*(etd->pexit_app) == 1) {
- pthread_mutex_unlock(etd->exit_mutex);
+ if (is_app_stopped(etd))
goto out;
- }
- pthread_mutex_unlock(etd->exit_mutex);
sleep(1);
}
append_window_text("LFS process found.", 0);
}
waitpid(lfs_pid, NULL, 0);
return 0;
-}
\ No newline at end of file
+}
#ifndef _FPSCOUNTER_H
#define _FPSCOUNTER_H
-#include "sharedstructs.h"
+#include "shared.h"
#include <fcntl.h>
#include <unistd.h>
int start_stop_benchmark();
void stop_benchmark();
-#endif
\ No newline at end of file
+#endif
#include "appwindow.h"
#include "keyblogger.h"
#include "fpscounter.h"
-#include "sharedstructs.h"
+#include "shared.h"
#include <linux/input.h>
#define EV_RELEASED 0
}
}
- pthread_mutex_lock(etd->exit_mutex);
- if (*(etd->pexit_app) == 1)
+ if (is_app_stopped(etd))
run_loop = 0;
- pthread_mutex_unlock(etd->exit_mutex);
}
return NULL;
#include "appwindow.h"
#include "fpscounter.h"
#include "keyblogger.h"
-#include "sharedstructs.h"
+#include "shared.h"
#include <sys/capability.h>
#include <unistd.h>
char* evdev_path;
int exit_app;
+exit_thrdata exdata;
int main(int argc, char** argv)
{
}
/* Setup threading data */
- exit_thrdata etd;
- exit_app = 0;
- if (pthread_mutex_init(&exit_mutex, NULL) != 0) {
+ if (pthread_mutex_init(&exdata.exit_mutex, NULL) != 0) {
fprintf(stderr, "CRITICAL: Cannot create exit_mutex!");
goto bail_out_1;
}
-
- etd.exit_mutex = &exit_mutex;
- etd.pexit_app = &exit_app;
+ exdata.exit_app = 0;
if (XInitThreads() <= 0) {
fprintf(stderr, "Unable to initialize X11 threads\n");
if (create_window() < 0)
goto bail_out_2;
/* Start main window event loop */
- if (pthread_create(&win_event_loop, NULL, &window_event_loop, &etd) != 0) {
+ if (pthread_create(&win_event_loop, NULL, &window_event_loop, &exdata) != 0) {
fprintf(stderr, "CRITICAL: Cannot start main window event loop!\n");
goto bail_out_2;
}
if (init_keyb_logging(evdev_path) != 0)
goto bail_out_3;
- if (init_fps_counter(&etd) != 0)
+ if (init_fps_counter(&exdata) != 0)
goto bail_out_3;
- if (pthread_create(&kb_event_loop, NULL, &get_keyb_events, &etd) != 0) {
+ if (pthread_create(&kb_event_loop, NULL, &get_keyb_events, &exdata) != 0) {
fprintf(stderr, "CRITICAL: Cannot start boundkeys event loop!\n");
goto bail_out_3;
}
return EXIT_SUCCESS;
bail_out_3:
+ stop_app(&exdata);
pthread_join(win_event_loop, NULL);
bail_out_2:
- pthread_mutex_destroy(&exit_mutex);
+ pthread_mutex_destroy(&exdata.exit_mutex);
bail_out_1:
free(evdev_path);
return EXIT_FAILURE;
--- /dev/null
+#ifndef _SHAREDSTRUCTS_H
+#define _SHAREDSTRUCTS_H
+
+#include <pthread.h>
+
+typedef struct {
+ pthread_mutex_t exit_mutex;
+ int exit_app;
+} exit_thrdata;
+
+int is_app_stopped(exit_thrdata* exdata);
+void stop_app(exit_thrdata* exdata);
+
+#endif
+++ /dev/null
-#ifndef _SHAREDSTRUCTS_H
-#define _SHAREDSTRUCTS_H
-
-#include <pthread.h>
-
-typedef struct {
- pthread_mutex_t* exit_mutex;
- int* pexit_app;
-} exit_thrdata;
-
-#endif
\ No newline at end of file