source: Sophya/trunk/ArchTOIPipe/Kernel/toisegment.cc@ 1671

Last change on this file since 1671 was 1671, checked in by aubourg, 24 years ago

* empty log message *

File size: 1.3 KB
Line 
1#include "toisegment.h"
2
3
4/******* BufferSegment *********/
5TOISegmented::BufferSegment::BufferSegment(int sz) {
6 status = NEW;
7 bufferSize = sz;
8 sn0 = -1;
9
10 refcount = 0;
11
12 data = new double[sz];
13 flags = new uint_8[sz];
14
15 pthread_mutex_init(&refcount_mutex, NULL);
16}
17
18TOISegmented::BufferSegment::~BufferSegment() {
19 if (refcount > 0) {
20 throw(ForbiddenError("TOISegment : delete Buffer with refcount>0"));
21 }
22 delete[] data;
23 delete[] flags;
24 pthread_mutex_destroy(&refcount_mutex);
25}
26
27
28void TOISegmented::BufferSegment::putData(int sn, double d, uint_8 f) {
29 if (status == NEW) {
30 status = WRITE;
31 sn0 = sn;
32 }
33 if (status == COMMITTED) {
34 throw(ForbiddenError("TOISegment : putData in committed buffer"));
35 }
36 checkInRange(sn);
37 data[sn-sn0] = d;
38 flags[sn-sn0] = f;
39}
40
41void TOISegmented::BufferSegment::incRefCount() {
42 pthread_mutex_lock(&refcount_mutex);
43 refcount++;
44 pthread_mutex_unlock(&refcount_mutex);
45}
46
47void TOISegmented::BufferSegment::decRefCount() {
48 pthread_mutex_lock(&refcount_mutex);
49 int nrc = --refcount;
50 pthread_mutex_unlock(&refcount_mutex);
51 if (nrc<0)
52 throw(ForbiddenError("TOISegment : buffer refcount < 0"));
53}
54
55int TOISegmented::BufferSegment::getRefCount() {
56 pthread_mutex_lock(&refcount_mutex);
57 int rc = refcount;
58 pthread_mutex_unlock(&refcount_mutex);
59 return rc;
60}
61
Note: See TracBrowser for help on using the repository browser.