![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
MAIN
Fork of SOFT253_Template_Weather_OS_54 by
log.cpp@36:af6abc6f7590, 2017-05-15 (annotated)
- Committer:
- J_Satchell
- Date:
- Mon May 15 08:58:08 2017 +0000
- Revision:
- 36:af6abc6f7590
- Child:
- 37:13f74964a045
Almost done
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
J_Satchell | 36:af6abc6f7590 | 1 | #include "Data.hpp" |
J_Satchell | 36:af6abc6f7590 | 2 | |
J_Satchell | 36:af6abc6f7590 | 3 | Data queue_array[120]; |
J_Satchell | 36:af6abc6f7590 | 4 | int rear = 0; |
J_Satchell | 36:af6abc6f7590 | 5 | int front = 0; |
J_Satchell | 36:af6abc6f7590 | 6 | |
J_Satchell | 36:af6abc6f7590 | 7 | Mutex mutex_l; |
J_Satchell | 36:af6abc6f7590 | 8 | |
J_Satchell | 36:af6abc6f7590 | 9 | void log_init() |
J_Satchell | 36:af6abc6f7590 | 10 | { |
J_Satchell | 36:af6abc6f7590 | 11 | |
J_Satchell | 36:af6abc6f7590 | 12 | } |
J_Satchell | 36:af6abc6f7590 | 13 | |
J_Satchell | 36:af6abc6f7590 | 14 | void log_push(Data data) |
J_Satchell | 36:af6abc6f7590 | 15 | { |
J_Satchell | 36:af6abc6f7590 | 16 | rear = (rear + 1) % 120; |
J_Satchell | 36:af6abc6f7590 | 17 | |
J_Satchell | 36:af6abc6f7590 | 18 | if (rear == front){ |
J_Satchell | 36:af6abc6f7590 | 19 | front = (front + 1) % 120; |
J_Satchell | 36:af6abc6f7590 | 20 | } |
J_Satchell | 36:af6abc6f7590 | 21 | |
J_Satchell | 36:af6abc6f7590 | 22 | queue_array[rear] = data; |
J_Satchell | 36:af6abc6f7590 | 23 | } |
J_Satchell | 36:af6abc6f7590 | 24 | |
J_Satchell | 36:af6abc6f7590 | 25 | Data log_pop() |
J_Satchell | 36:af6abc6f7590 | 26 | { |
J_Satchell | 36:af6abc6f7590 | 27 | Data record; |
J_Satchell | 36:af6abc6f7590 | 28 | if (front != rear) |
J_Satchell | 36:af6abc6f7590 | 29 | { record = queue_array[rear]; |
J_Satchell | 36:af6abc6f7590 | 30 | rear = (rear + 1) % 120; |
J_Satchell | 36:af6abc6f7590 | 31 | } |
J_Satchell | 36:af6abc6f7590 | 32 | return record; |
J_Satchell | 36:af6abc6f7590 | 33 | |
J_Satchell | 36:af6abc6f7590 | 34 | } |
J_Satchell | 36:af6abc6f7590 | 35 | |
J_Satchell | 36:af6abc6f7590 | 36 | int log_length() |
J_Satchell | 36:af6abc6f7590 | 37 | { |
J_Satchell | 36:af6abc6f7590 | 38 | |
J_Satchell | 36:af6abc6f7590 | 39 | int length; |
J_Satchell | 36:af6abc6f7590 | 40 | length = (120 + rear - front) % 120; |
J_Satchell | 36:af6abc6f7590 | 41 | |
J_Satchell | 36:af6abc6f7590 | 42 | return length; |
J_Satchell | 36:af6abc6f7590 | 43 | |
J_Satchell | 36:af6abc6f7590 | 44 | } |
J_Satchell | 36:af6abc6f7590 | 45 | |
J_Satchell | 36:af6abc6f7590 | 46 | Data log_get(int index) |
J_Satchell | 36:af6abc6f7590 | 47 | { |
J_Satchell | 36:af6abc6f7590 | 48 | |
J_Satchell | 36:af6abc6f7590 | 49 | Data record; |
J_Satchell | 36:af6abc6f7590 | 50 | record = queue_array[(front + index) % 120]; |
J_Satchell | 36:af6abc6f7590 | 51 | |
J_Satchell | 36:af6abc6f7590 | 52 | return record; |
J_Satchell | 36:af6abc6f7590 | 53 | |
J_Satchell | 36:af6abc6f7590 | 54 | } |