Where to place a Mutex for ALL .cgi functions?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Where to place a Mutex for ALL .cgi functions?

3,154 Views
MQXuser
Contributor III

All of my .cgi functions use variables which I am also using into another Task. I would like to place a Mutex to prevent every .cgi function from running while my Main Task is running.

Is there a place in the source code where I can place this mutex without having to place a mutex in each .cgi function?

 

Let me know if I the question isn't very clear.

 

Thanks,

 

Labels (1)
Tags (1)
0 Kudos
5 Replies

659 Views
PetrM
Senior Contributor I

If you want to completely disable cgi functions for a while, I think you can use HTTPD_SET_PARAM_CGI_TBL() macro and set some empty table, or table with dummy callbacks.

For more information, see webserver_demo.c (security_webserver).

 

PetrM

 

0 Kudos

659 Views
MQXuser
Contributor III

Thank you for your answer. Just to check if I understood correctly:

1.- Do you mean to say that I can change dynamically and asyncrhonously the value of the cgi function table?

2.- Could I do something like the following?

3.- What would happen if a cgi function is already running when I change the  table?

 

 

void Main_task(uint_32 index){
  
   while(TRUE){
      HTTPD_SET_PARAM_CGI_TBL(server,HTTPD_CGI_LINK_STRUCT*)dummy_lnk_tbl);
      //Functions using a lot of CGI variables
      //Functions using a lot of CGI variables
      //Functions using a lot of CGI variables    
      HTTPD_SET_PARAM_CGI_TBL(server,HTTPD_CGI_LINK_STRUCT*)cgi_lnk_tbl);
      _time_delay(150);
   }
}

 

 Regards,

 

 

 

 

0 Kudos

659 Views
PetrM
Senior Contributor I

Yes, I think it's possible to dynamically change it. It can just happen, that one request will be processed still using old table just after the switch.

But as I see you intention now, it's not good idea to use it like this. I thought, that you would like to temporarily disable web pages once a long time period.

So, unless you have write-write conflict, you don't have to switch the table nor use mutexes at all.

 

PetrM

 

0 Kudos

659 Views
MQXuser
Contributor III

So, would it be okay to read a global variable from different tasks without a protection mechanism (mutex) ?

 

What about write-read?

0 Kudos

659 Views
PetrM
Senior Contributor I

Just reads are not a problem. No mutexes.

One write + reads is ok for non dynamic variables (no pointer re-allocation).

Otherwise you have to use mutexes.