Software tool for automatically protecting shared resources within software source code
A method for identifying shared resources in multiple tasks in a multitasking system and for automatically inserting code to protect these shared resources from race conditions due to access by more than one task.
1 ) A method for protecting shared resources of a computer that are accessed by a plurality of computer programs running on said computer, comprising:
a) reading source codes of said computer programs and identifying said shared resources;
b) reading said source codes and identifying accesses to said shared resources;
c) inserting initial protection statements in said source codes before accesses of said shared resources; and
d) inserting ending protection statements in said source codes after accesses of said shared resources.
2 ) The method of claim 1) where initial protection statements set a mutex or semaphore and ending protecting statements reset a mutex or semaphore.
3 ) The method of claim 1) where initial protection statements turn off interrupts and ending protecting statements turn on interrupts.
4 ) The method of claim 1) where initial protection statements and ending protecting statements are independent of specific operating system software.
5 ) A method for creating a list of shared resources of a computer that are accessed by a plurality of computer programs running on said computer, comprising:
a) clearing a task flag;
b) reading source codes of said computer programs;
c) recognizing a task declaration statement in said source codes and setting said task flag;
d) recognizing an end-of-task statement in said source codes and clearing said task flag;
e) recognizing said shared resource declaration statements in said source codes when said task flag is not set; and
f) adding identifiers for said shared resources to a list.
6 ) A method for determining statements that access shared resources of a computer within source codes of a plurality of tasks of computer programs running on said computer, comprising:
a) clearing a task flag;
b) reading said source codes;
c) recognizing a task declaration statement in said source codes and setting said task flag;
d) recognizing an end-of-task statement in said source codes and clearing said task flag; and
e) recognizing statements in said source codes that access said shared resources when said task flag is set.
7 ) The method of claim 6) further comprising:
a) recording the locations of statements in said source codes that access said shared resources within tasks.
8 ) The method of claim 6) further comprising:
a) incrementing a counter corresponding to a said shared resource for each task that accesses said shared resource at least once.
9 ) The method of claim 8) further comprising:
a) eliminating from said list of said shared resources entries for all said shared resources that have a corresponding counter with a value of 0 or 1 after said source codes have been entirely read.
10 ) A method for protecting statements within the source codes of a plurality of computer programs running on a computer that access shared resources on said computer, comprising:
a) creating a list of said shared resources;
b) creating a list of statements in tasks within said source codes that access said shared resources;
c) clearing a task flag;
d) reading said source codes;
e) recognizing a task declaration statement in said source codes and setting said task flag;
f) recognizing an end-of-task statement in said source codes and clearing said task flag;
g) determining whether a statement is in said list of statements;
h) inserting an initial protection statement in said source codes before a statement that is in said list of statements; and
i) inserting an ending protection statement in said source codes after a statement that is in said list of statements.
11 ) The method of claim 10) where initial protection statements set a mutex or semaphore and ending protecting statements reset a mutex or semaphore.
12 ) The method of claim 10) where initial protection statements turn of interrupts and ending protecting statements turn on interrupts.
13 ) The method of claim 10) where initial protection statements and ending protecting statements are independent of specific operating system software.
14 ) An apparatus including a software program for protecting shared resources of a computer that are accessed by a plurality of computer programs running on said computer, comprising:
a) means for reading source codes of said computer programs and identifying said shared resources;
b) means for reading said source codes and identifying accesses to said shared resources;
c) means for inserting initial protection statements in said source codes before accesses of said shared resources; and
d) means for inserting ending protection statements in said source codes after accesses of said shared resources.
15 ) The apparatus of claim 14) where initial protection statements set a mutex or semaphore and ending protecting statements reset a mutex or semaphore.
16 ) The apparatus of claim 14) where initial protection statements turn off interrupts and ending protecting statements turn on interrupts.
17 ) The apparatus of claim 14) where initial protection statements and ending protecting statements are independent of specific operating system software.
18 ) An apparatus for creating a list of shared resources of a computer that are accessed by a plurality of computer programs running on said computer, comprising:
a) means for clearing a task flag;
b) means for reading source codes of said computer programs;
c) means for recognizing a task declaration statement in said source codes and setting said task flag;
d) means for recognizing an end-of-task statement in said source codes and clearing said task flag;
e) means for recognizing said shared resource declaration statements in said source codes when said task flag is not set; and
f) means for adding identifiers for said shared resources to a list.
19 ) An apparatus determining statements that access shared resources of a computer within source codes of a plurality of tasks of computer programs running on said computer, comprising
a) means for clearing a task flag;
b) means for reading said source codes;
c) means for recognizing a task declaration statement in said source codes and setting said task flag;
d) means for recognizing an end-of-task statement in said source codes and clearing said task flag; and
e) means for recognizing statements in said source codes that access said shared resources when said task flag is set.
20 ) The apparatus of claim 19) further comprising:
a) means for recording the locations of statements in said source codes that access said shared resources within tasks.
21 ) The apparatus of claim 19) further comprising:
a) means for incrementing a counter corresponding to a said shared resource for each task that accesses said shared resource at least once.
22 ) The apparatus of claim 21) further comprising:
a) means for eliminating from said list of said shared resources entries for all said shared resources that has a corresponding counter with a value of 0 or 1 after said source codes have been entirely read.
23 ) An apparatus for protecting statements within the source codes of a plurality of computer programs running on a computer that access shared resources on said computer, comprising:
a) means for creating a list of said shared resources;
b) means for creating a list of statements in tasks within said source codes that access said shared resources;
c) means for clearing a task flag;
d) means for reading said source codes;
e) means for recognizing a task declaration statement in said source codes and setting said task flag;
f) means for recognizing an end-of-task statement in said source codes and clearing said task flag;
g) means for determining whether a statement is in said list of statements;
h) means for inserting an initial protection statement in said source codes before a statement that is in said list of statements; and
i) means for inserting an ending protection statement in said source codes after a statement that is in said list of statements.
24 ) The apparatus of claim 23) where initial protection statements set a mutex or semaphore and ending protecting statements reset a mutex or semaphore.
25 ) The apparatus of claim 23) where initial protection statements turn of interrupts and ending protecting statements turn on interrupts.
26 ) The apparatus of claim 23) where initial protection statements and ending protecting statements are independent of specific operating system software.