process Lock implementation

This is a toy project I am doing which is a course project given in last summer from our school.(I didn't register that course, and now just do it for practice.)

The main idea is to implement a process lock. Add several system calls. Such as :

Code:
516     AUE_NULL        STD     { int set_lgname(char *lgn, int pid); }   // set lock group name
517     AUE_NULL        STD     { int get_lgname(char *lgn); }               // get lock group name
518     AUE_NULL        STD     { int create_lock(char *name, int perms); } 
519     AUE_NULL        STD     { int set_lock(char *name, int slpflg); }
520     AUE_NULL        STD     { int clear_lock(char *name); }
521     AUE_NULL        STD     { int check_lock(char *name); }
522     AUE_NULL        STD     { int destroy_lock(char *name); }

Instructor also said "You will need to be using linked list(s) to keep track of the locks inside the kernel. "

The question is here: how can I keep track of the locks inside the kernel? Should I save it as a file? or anything I can do? Stuck here.....need help.
Thank you !
 
"Linked list(s)" usually means some sort of list in memory, there is no point to save as a file for 'locks' task.
These lists are maked with struct that contains
1. Data or pointer to data
2. Pointer to next list item
3. (optional) Pointer to previous list item

So it looks like
Code:
struct linkedlist {
char data[100]; //Or pointer, or more space for data, whatever
linkedlist *next;
}
So, you save first item in variable like "linkedlist *first;", then you can iterate them like this
Code:
linkedlist *first, *curr;
// .... init *first, fill chain ...

// Use them
curr=first;
while( curr != NULL ) {
   // Do something with curr->data
   curr = curr->next;
}
If you want add an item to this list, you should do malloc(sizeof(linkedlist)) to last item(chain), and not forget to set 'next' var to NULL
 
Back
Top