core: Add global threading utility
For now, we only store what's the main thread of the program.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* gcal-core-macros.h
|
||||
*
|
||||
* Copyright 2023 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gcal-global.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GCAL_IS_THREAD(thread_) (g_thread_self () == (thread_))
|
||||
#define GCAL_IS_MAIN_THREAD() (g_thread_self () == gcal_get_main_thread ())
|
||||
|
||||
G_END_DECLS
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* gcal-global.c
|
||||
*
|
||||
* Copyright 2023 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#include "gcal-global.h"
|
||||
#include "gconstructor.h"
|
||||
|
||||
static GThread *main_thread;
|
||||
|
||||
#if defined (G_HAS_CONSTRUCTORS)
|
||||
# ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
|
||||
# pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(gcal_init_ctor)
|
||||
# endif
|
||||
G_DEFINE_CONSTRUCTOR(gcal_init_ctor)
|
||||
#else
|
||||
# error Your platform/compiler is missing constructor support
|
||||
#endif
|
||||
|
||||
static void
|
||||
gcal_init_ctor (void)
|
||||
{
|
||||
main_thread = g_thread_self ();
|
||||
}
|
||||
|
||||
GThread *
|
||||
gcal_get_main_thread (void)
|
||||
{
|
||||
return main_thread;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* gcal-global.h
|
||||
*
|
||||
* Copyright 2023 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
GThread * gcal_get_main_thread (void);
|
||||
|
||||
G_END_DECLS
|
||||
@@ -6,6 +6,7 @@ sources += files(
|
||||
'gcal-clock.c',
|
||||
'gcal-context.c',
|
||||
'gcal-event.c',
|
||||
'gcal-global.c',
|
||||
'gcal-log.c',
|
||||
'gcal-manager.c',
|
||||
'gcal-range.c',
|
||||
|
||||
Reference in New Issue
Block a user