65{
66 if (m_buf == NULL) return 0;
67 if (nword == 0) return 0;
68 if (nword > m_nword) return -1;
69
70 while (true) {
71 unsigned int i_w = m_header.nword_in % m_nword;
72 unsigned int i_r = m_header.nword_out % m_nword;
73 if ((serial == 0 || serial - 1 == m_header.count_in) &&
74 m_header.nword_in - m_header.nword_out < m_nword - (nword + 1)) {
75 if (i_w >= i_r) {
76 unsigned int count = m_nword - i_w;
77 if (nword + 1 < count) {
78 m_buf[i_w] = nword;
79 memcpy((m_buf + i_w + 1), buf, sizeof(int) * nword);
80 } else {
81 m_buf[i_w] = nword;
82 memcpy((m_buf + i_w + 1), buf, sizeof(int) * count);
83 if (nword >= count)
84 memcpy(m_buf, buf + count, sizeof(int) * (nword - count));
85 }
86 } else {
87 m_buf[i_w] = nword;
88 memcpy((m_buf + i_w + 1), buf, sizeof(int) * nword);
89 }
90 break;
91 }
92 }
93 m_header.nword_in += nword + 1;
94 unsigned int count = ++m_header.count_in;
95 return count;
96}