helpful progress reporting
[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.5
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   pthread_mutex_t threadnotify;
26 } notifydata_t;
27
28 typedef struct notifylistnode {
29   unsigned int threadid;
30   notifydata_t *ndata;
31   struct notifylistnode *next;
32 } notifylistnode_t;
33
34 typedef struct notifyhashtable {
35   notifylistnode_t *table;       //Points to beginning of hash table
36   unsigned int size;
37   unsigned int numelements;
38   float loadfactor;
39   pthread_mutex_t locktable;       //Lock for the hashtable
40 } notifyhashtable_t;
41
42 threadlist_t *insNode(threadlist_t *head, unsigned int threadid, unsigned int mid); //Inserts nodes for one object that
43 //needs to send notification to threads waiting on it
44 void display(threadlist_t *head); // Displays linked list of nodes for one object
45 unsigned int notifyhashCreate(unsigned int size, float loadfactor); //returns 1 if hashtable creation is not successful
46 unsigned int notifyhashFunction(unsigned int tid); //returns index in the hash table
47 unsigned int notifyhashInsert(unsigned int tid, notifydata_t *ndata); //returns 1 if insert not successful
48 notifydata_t *notifyhashSearch(unsigned int tid); //returns pointer to notify data, NULL if not found
49 unsigned int notifyhashRemove(unsigned int tid); //returns 1 if not successful
50 unsigned int notifyhashResize(unsigned int newsize);
51
52 #endif