more changes and some bug fixes for thread notify
[IRC.git] / Robust / src / Runtime / DSTM / interface / threadnotify.h
1 #ifndef _THREADNOTIFY_H_
2 #define _THREADNOTIFY_H_
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <pthread.h>
7
8 #define N_LOADFACTOR 0.75
9 #define N_HASH_SIZE 20
10
11 //Structure to notify object of which other objects/threads are waiting on it
12 typedef struct threadlist {
13         unsigned int threadid;
14         unsigned int mid;
15         struct threadlist *next;
16 } threadlist_t;
17
18 //Structure for objects involved in wait-notify call
19 typedef struct notifydata {
20         unsigned int numoid;    /* Number of oids on which we are waiting for updated notification */
21         unsigned int threadid;  /* The threadid that is waiting for  update notification response*/
22         unsigned int *oidarry;  /* Pointer to array of oids that this threadid is waiting on*/
23         unsigned short *versionarry;/* Pointer to array of versions of the oids that we are waiting on */
24         pthread_cond_t threadcond; /* Cond variable associated with each threadid that needs to be signaled*/
25 }notifydata_t;
26
27 typedef struct notifylistnode {
28         unsigned int threadid;
29         notifydata_t *ndata; 
30         struct notifylistnode *next;
31 } notifylistnode_t;
32
33 typedef struct notifyhashtable {
34         notifylistnode_t *table; //Points to beginning of hash table
35         unsigned int size;
36         unsigned int numelements;
37         float loadfactor;
38         pthread_mutex_t locktable; //Lock for the hashtable
39 } notifyhashtable_t;
40
41 void insNode(threadlist_t *head, unsigned int threadid, unsigned int mid); //Inserts nodes for one object that 
42                                                                            //needs to send notification to threads waiting on it
43 void display(threadlist_t *head);// Displays linked list of nodes for one object
44 unsigned int notifyhashCreate(unsigned int size, float loadfactor); //returns 1 if hashtable creation is not successful
45 unsigned int notifyhashFunction(unsigned int tid); //returns index in the hash table 
46 unsigned int notifyhashInsert(unsigned int tid, notifydata_t *ndata); //returns 1 if insert not successful
47 notifydata_t *notifyhashSearch(unsigned int tid); //returns pointer to notify data, NULL if not found
48 unsigned int notifyhashRemove(unsigned int tid); //returns 1 if not successful
49 unsigned int notifyhashResize(unsigned int newsize);
50
51 #endif