File: Queue.cpp

package info (click to toggle)
pymol 1.8.4.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 42,248 kB
  • ctags: 24,095
  • sloc: cpp: 474,635; python: 75,034; ansic: 22,888; sh: 236; makefile: 78; csh: 21
file content (70 lines) | stat: -rw-r--r-- 1,608 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70


/* 
A* -------------------------------------------------------------------
B* This file contains source code for the PyMOL computer program
C* Copyright (c) Schrodinger, LLC. 
D* -------------------------------------------------------------------
E* It is unlawful to modify or remove this copyright notice.
F* -------------------------------------------------------------------
G* Please see the accompanying LICENSE file for further information. 
H* -------------------------------------------------------------------
I* Additional authors of this source file include:
-* 
-* 
-*
Z* -------------------------------------------------------------------
*/

#include"os_predef.h"
#include"MemoryDebug.h"
#include"OOMac.h"
#include"Queue.h"

CQueue *QueueNew(PyMOLGlobals * G, unsigned int mask)
{
  OOAlloc(G, CQueue);
  I->size = mask + 1;
  I->ptr = Alloc(char, I->size);
  I->mask = mask;
  I->inp = 0;
  I->out = 0;
  return (I);
}

void QueueStrIn(CQueue * I, const char *c)
{
  int i = I->inp;
  while(*c) {
    *(I->ptr + i) = *(c++);
    i = (i + 1) & I->mask;
  }
  *(I->ptr + i) = *c;
  i = (i + 1) & I->mask;
  I->inp = i;                   /* important not to do this until null has been written! */
}

int QueueStrCheck(CQueue * I)
{
  return (((I->inp + I->size) - I->out) & I->mask);
}

int QueueStrOut(CQueue * I, char *c)
{
  if(((I->inp + I->size) - I->out) & I->mask) {
    while(1) {
      *c = *(I->ptr + I->out);
      I->out = (I->out + 1) & I->mask;
      if(!*(c++)) {
        return 1;
      }
    }
  }
  return 0;
}

void QueueFree(CQueue * I)
{
  FreeP(I->ptr);
  OOFreeP(I);
}