From 2c6f57276972cc47b338480de7a32b30e0491887 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 3 Sep 2013 12:33:37 +0100 Subject: [PATCH] various: comment static variables that are locked or otherwise OK Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68610 --- dbus/dbus-bus.c | 5 +++-- dbus/dbus-dataslot.c | 1 + dbus/dbus-internals.c | 7 +++++++ dbus/dbus-memory.c | 1 + dbus/dbus-pending-call.c | 1 + dbus/dbus-spawn.c | 2 ++ dbus/dbus-sysdeps-thread-win.c | 3 ++- dbus/dbus-sysdeps-win.c | 4 ++++ dbus/dbus-threads.c | 2 ++ dbus/dbus-userdb.c | 1 + 10 files changed, 24 insertions(+), 3 deletions(-) diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c index 9d2095f..a14dae0 100644 --- a/dbus/dbus-bus.c +++ b/dbus/dbus-bus.c @@ -83,17 +83,18 @@ typedef struct } BusData; /** The slot we have reserved to store BusData. + * Protected by _DBUS_LOCK_connection_slots. */ static dbus_int32_t bus_data_slot = -1; /** Number of bus types */ #define N_BUS_TYPES 3 +/* Protected by _DBUS_LOCK_bus, except during shutdown, which can't safely + * be done in a threaded application anyway. */ static DBusConnection *bus_connections[N_BUS_TYPES]; static char *bus_connection_addresses[N_BUS_TYPES] = { NULL, NULL, NULL }; - static DBusBusType activation_bus_type = DBUS_BUS_STARTER; - static dbus_bool_t initialized = FALSE; static void diff --git a/dbus/dbus-dataslot.c b/dbus/dbus-dataslot.c index e37c9dd..1ce0d1e 100644 --- a/dbus/dbus-dataslot.c +++ b/dbus/dbus-dataslot.c @@ -352,6 +352,7 @@ _dbus_data_slot_list_free (DBusDataSlotList *list) #include "dbus-test.h" #include +/* Test-only, does not need to be thread-safe */ static int free_counter; static void diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index e248259..7a702a2 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -183,7 +183,14 @@ */ const char *_dbus_no_memory_message = "Not enough memory"; +/* Not necessarily thread-safe, but if writes don't propagate between + * threads, the worst that will happen is that we duplicate work in more than + * one thread. */ static dbus_bool_t warn_initted = FALSE; + +/* Not necessarily thread-safe, but if writes don't propagate between + * threads, the worst that will happen is that warnings get their default + * fatal/non-fatal nature. */ static dbus_bool_t fatal_warnings = FALSE; static dbus_bool_t fatal_warnings_on_check_failed = TRUE; diff --git a/dbus/dbus-memory.c b/dbus/dbus-memory.c index d59e8f8..168de2f 100644 --- a/dbus/dbus-memory.c +++ b/dbus/dbus-memory.c @@ -98,6 +98,7 @@ */ #ifdef DBUS_ENABLE_EMBEDDED_TESTS +/* Test-only, does not need to be thread-safe */ static dbus_bool_t debug_initialized = FALSE; static int fail_nth = -1; static size_t fail_size = 0; diff --git a/dbus/dbus-pending-call.c b/dbus/dbus-pending-call.c index be53410..4474011 100644 --- a/dbus/dbus-pending-call.c +++ b/dbus/dbus-pending-call.c @@ -93,6 +93,7 @@ _dbus_pending_call_trace_ref (DBusPendingCall *pending_call, #endif } +/* protected by _DBUS_LOCK_pending_call_slots */ static dbus_int32_t notify_user_data_slot = -1; /** diff --git a/dbus/dbus-spawn.c b/dbus/dbus-spawn.c index f8d5fd1..5c6e0a7 100644 --- a/dbus/dbus-spawn.c +++ b/dbus/dbus-spawn.c @@ -1035,6 +1035,8 @@ check_babysit_events (pid_t grandchild_pid, } } +/* Only used in a single-threaded child process, does not need to be + * thread-safe */ static int babysit_sigchld_pipe = -1; static void diff --git a/dbus/dbus-sysdeps-thread-win.c b/dbus/dbus-sysdeps-thread-win.c index 0887a54..dda3336 100644 --- a/dbus/dbus-sysdeps-thread-win.c +++ b/dbus/dbus-sysdeps-thread-win.c @@ -30,6 +30,7 @@ #include +/* Protected by DllMain lock, effectively */ static dbus_bool_t global_init_done = FALSE; static CRITICAL_SECTION init_lock; @@ -52,7 +53,7 @@ struct DBusCondVar { static DWORD dbus_cond_event_tls = TLS_OUT_OF_INDEXES; - +/* Protected by DllMain lock, effectively */ static HMODULE dbus_dll_hmodule; void * diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 5d0ea0f..9c4a06b 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -116,6 +116,10 @@ typedef MIB_TCPROW_OWNER_PID _MIB_TCPROW_EX; typedef MIB_TCPTABLE_OWNER_PID MIB_TCPTABLE_EX; typedef PMIB_TCPTABLE_OWNER_PID PMIB_TCPTABLE_EX; typedef DWORD (WINAPI *ProcAllocateAndGetTcpExtTableFromStack)(PMIB_TCPTABLE_EX*,BOOL,HANDLE,DWORD,DWORD); + +/* Not protected by a lock, but if we miss a write, all that + * happens is that the lazy initialization will happen in two threads + * concurrently - it results in the same value either way so that's OK */ static ProcAllocateAndGetTcpExtTableFromStack lpfnAllocateAndGetTcpExTableFromStack = NULL; /** diff --git a/dbus/dbus-threads.c b/dbus/dbus-threads.c index 12d4049..2d03a95 100644 --- a/dbus/dbus-threads.c +++ b/dbus/dbus-threads.c @@ -26,6 +26,7 @@ #include "dbus-threads-internal.h" #include "dbus-list.h" +/* Protected by _dbus_threads_lock_platform_specific() */ static int thread_init_generation = 0; /** @@ -283,6 +284,7 @@ _dbus_condvar_wake_one (DBusCondVar *cond) _dbus_platform_condvar_wake_one (cond); } +/* Protected by _dbus_threads_lock_platform_specific() */ static DBusRMutex *global_locks[_DBUS_N_GLOBAL_LOCKS] = { NULL }; static void diff --git a/dbus/dbus-userdb.c b/dbus/dbus-userdb.c index b792cbe..0965a46 100644 --- a/dbus/dbus-userdb.c +++ b/dbus/dbus-userdb.c @@ -219,6 +219,7 @@ _dbus_user_database_lookup (DBusUserDatabase *db, } } +/* Protected by _DBUS_LOCK_system_users */ static dbus_bool_t database_locked = FALSE; static DBusUserDatabase *system_db = NULL; static DBusString process_username; -- 1.8.4.rc3