summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael J. Chudobiak <mjc@avtechpulse.com>2012-10-17 08:15:39 -0400
committerMichael J. Chudobiak <mjc@avtechpulse.com>2012-10-17 08:15:39 -0400
commit8b369f263f10de056c3633806a7f1ed87e2b7145 (patch)
tree8a0d9c4ed35663da416abb08412eb0aa920ba697
parentb4a429729774f91ff259fe17d256b00134bc9f1f (diff)
init threading properly, added more mutex locks
-rw-r--r--CMakeLists.txt2
-rw-r--r--device-functions.c5
-rw-r--r--error_utils.c25
-rw-r--r--flash.c7
-rw-r--r--instr-daemon.c1
5 files changed, 27 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 70c4c24..6ab132b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -32,7 +32,7 @@ add_executable(instr-daemon instr-daemon.c
)
add_executable(instr-client instr-client.c)
-target_link_libraries(instr-daemon gio-2.0 gobject-2.0 glib-2.0 mhash m pam user)
+target_link_libraries(instr-daemon gio-2.0 gobject-2.0 glib-2.0 gthread-2.0 mhash m pam user)
target_link_libraries(instr-client gio-2.0 gobject-2.0 glib-2.0)
INSTALL(TARGETS instr-daemon instr-client
diff --git a/device-functions.c b/device-functions.c
index 8e59686..726b782 100644
--- a/device-functions.c
+++ b/device-functions.c
@@ -4462,6 +4462,9 @@ void Set_Sav(int setting_num)
void Main_update_shift_registers()
{
+ static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+ g_static_mutex_lock (&mutex);
+
/* send MSB first, LSB last */
/* send highest # SR first */
@@ -4549,6 +4552,8 @@ void Main_update_shift_registers()
globals.Changes.update_amp = 0;
globals.Changes.update_zout = 0;
globals.Changes.update_load = 0;
+
+ g_static_mutex_unlock (&mutex);
}
diff --git a/error_utils.c b/error_utils.c
index d4c48a3..bb2cd32 100644
--- a/error_utils.c
+++ b/error_utils.c
@@ -528,13 +528,16 @@ void get_error_text(gchar **response, int error_num)
int Error_check(ChannelStruct ChannelStateToTest[max_channels])
{
+ static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+ g_static_mutex_lock (&mutex);
float max_duty_high_ampl,max_duty_low_ampl,max_duty_this_ampl;
float ampl_fixed_max_duty;
float temp;
float duty_scale;
float duty_cycle;
- int report_error;
+ int report_error = OK;
+ gboolean early_quit = FALSE;
int i;
int num_of_chan;
@@ -640,29 +643,33 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels])
}
- report_error=OK;
-
- for (i=0; i<num_of_chan; ++i) {
+ for (i=0; (i<num_of_chan) && !early_quit; ++i) {
/* Must be changing a setting */
globals.Timers.last_activity_at[i] = sec_timer ();
/* ignore errors if it is in programming mode */
if (globals.Flash.fully_programmed != All_Programmed) {
- return OK;
+ early_quit = TRUE;
+ break;
}
if (globals.Flags.do_check_settings==NO) {
- return OK;
+ early_quit = TRUE;
+ break;
}
/* check for settings that would cause divide-by-zero errors in the error-checking routine */
if (ChannelStateToTest[i].frequency<smallest_allowed_number) {
- return freq_lower_limit;
+ early_quit = TRUE;
+ report_error = freq_lower_limit;
+ break;
}
if (ChannelStateToTest[i].pw<smallest_allowed_number
&& globals.Flash.min_pw[i]>0.0) {
- return pw_lower_limit;
+ early_quit = TRUE;
+ report_error = pw_lower_limit;
+ break;
}
/* calculate maximum duty cycle based on amplitude and load, for later use */
@@ -1421,6 +1428,8 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels])
/* --- done all per-channel checking ---- */
}
+ g_static_mutex_unlock (&mutex);
+
return report_error;
}
diff --git a/flash.c b/flash.c
index 5228bc5..7fd5bb8 100644
--- a/flash.c
+++ b/flash.c
@@ -295,9 +295,8 @@ void writeUserBlock(FlashStruct *mem, int addr, int numbytes)
// *** that the main file is valid before backing it up I guess... ***
// *** but I don't think this situation should arise. ***
- static GMutex mutex;
-
- g_mutex_lock (&mutex);
+ static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+ g_static_mutex_lock (&mutex);
if (!globals.Flags.flash_writes_suspended) {
@@ -325,7 +324,7 @@ void writeUserBlock(FlashStruct *mem, int addr, int numbytes)
}
}
- g_mutex_unlock (&mutex);
+ g_static_mutex_unlock (&mutex);
}
diff --git a/instr-daemon.c b/instr-daemon.c
index b64a94e..0c897ce 100644
--- a/instr-daemon.c
+++ b/instr-daemon.c
@@ -194,6 +194,7 @@ int main(int argc, char **argv)
GIOChannel* stdinChannel = NULL;
g_type_init ();
+ g_thread_init (NULL);
bus_init();