~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/lck/sge_lock_fifo.h

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _SGE_LOCK_FIFO_H_
 
2
#define _SGE_LOCK_FIFO_H_
 
3
 
 
4
#include <pthread.h>
 
5
 
 
6
#include "basis_types.h"
 
7
 
 
8
#include "lck/sge_lock.h"
 
9
 
 
10
typedef struct sge_fifo_elem_t__ {
 
11
   /*
 
12
    * is the waiting thread a reader or writer
 
13
    */
 
14
   bool is_reader;
 
15
 
 
16
   /*
 
17
    * has this thread already been signaled
 
18
    */
 
19
   bool is_signaled;
 
20
 
 
21
   /*
 
22
    * condition to wakeup a waiting thread
 
23
    */
 
24
   pthread_cond_t cond;
 
25
} sge_fifo_elem_t;
 
26
 
 
27
typedef struct sge_fifo_rw_lock_t__ {
 
28
   /* 
 
29
    * mutex to guard this structure
 
30
    */
 
31
   pthread_mutex_t mutex;
 
32
 
 
33
   /*
 
34
    * condition to wakeup a waiting thread which got not
 
35
    * no position in the queue of waiting threads
 
36
    */
 
37
   pthread_cond_t cond;
 
38
 
 
39
   /*
 
40
    * fifo array where information about waiting threads is stored.
 
41
    */
 
42
   sge_fifo_elem_t *array;
 
43
 
 
44
   /* 
 
45
    * position of the next thread which gets the lock 
 
46
    */
 
47
   int head;            
 
48
 
 
49
   /* 
 
50
    * position in the array where the next thread will be placed which has to wait 
 
51
    */
 
52
   int tail;          
 
53
 
 
54
   /* 
 
55
    * maximum array size 
 
56
    */ 
 
57
   int size;            
 
58
 
 
59
   /* 
 
60
    * number of reader threads currently active 
 
61
    */
 
62
   int reader_active;   
 
63
 
 
64
   /* 
 
65
    * number of waiting threads in the queue which try to get a read lock 
 
66
    */
 
67
   int reader_waiting;  
 
68
   
 
69
   /*
 
70
    * number of writer threads currently active (maximum is 1)
 
71
    */
 
72
   int writer_active;
 
73
 
 
74
   /*
 
75
    * number of waiting threads in the queue which try to get the write lock
 
76
    */
 
77
   int writer_waiting;  
 
78
 
 
79
   /*
 
80
    * number of threads which do neither get a lock nor get a free position in the array
 
81
    */
 
82
   int waiting;       
 
83
 
 
84
   /*
 
85
    * number of waiting threads which have been signaled so that they wake up (maximum is 1)
 
86
    */
 
87
   int signaled;
 
88
} sge_fifo_rw_lock_t;
 
89
 
 
90
bool 
 
91
sge_fifo_lock_init(sge_fifo_rw_lock_t *lock);
 
92
 
 
93
bool 
 
94
sge_fifo_lock(sge_fifo_rw_lock_t *lock, bool is_reader);
 
95
 
 
96
bool 
 
97
sge_fifo_ulock(sge_fifo_rw_lock_t *lock, bool is_reader);
 
98
 
 
99
void 
 
100
sge_fifo_debug(sge_locktype_t aType);
 
101
 
 
102
void 
 
103
sge_debug_time(sge_locktype_t aType);
 
104
 
 
105
#endif