diff options
author | Dan Gudmundsson <[email protected]> | 2015-12-04 12:10:04 +0100 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2015-12-04 12:10:04 +0100 |
commit | 7a13283ac6f4a7738dbe2a2ccfce392a820dca2a (patch) | |
tree | c9c8735eef6ff80854c2814010f54b30f3d7f50d /lib/wx/c_src/wxe_helpers.cpp | |
parent | 7b57b86a78f668747cc28e1820a0e6e8474111ea (diff) | |
parent | 80483dcb40c382e38405204370dfac7a8b6513aa (diff) | |
download | otp-7a13283ac6f4a7738dbe2a2ccfce392a820dca2a.tar.gz otp-7a13283ac6f4a7738dbe2a2ccfce392a820dca2a.tar.bz2 otp-7a13283ac6f4a7738dbe2a2ccfce392a820dca2a.zip |
Merge branch 'dgud/wx/rewrite-cmd-loop/OTP-13160' into maint
* dgud/wx/rewrite-cmd-loop/OTP-13160:
wx: Fix some function specifications
wx: Remove call to disconnect_impl from server
wx: Add a command queue check after event sent to erlang
wx: Make wxPostScriptDC optional
wx: Add wxOverlay
wx: Use only one ring buffer for command queue
Diffstat (limited to 'lib/wx/c_src/wxe_helpers.cpp')
-rw-r--r-- | lib/wx/c_src/wxe_helpers.cpp | 58 |
1 files changed, 49 insertions, 9 deletions
diff --git a/lib/wx/c_src/wxe_helpers.cpp b/lib/wx/c_src/wxe_helpers.cpp index cc57374d5b..1696b8bd50 100644 --- a/lib/wx/c_src/wxe_helpers.cpp +++ b/lib/wx/c_src/wxe_helpers.cpp @@ -61,6 +61,7 @@ wxeFifo::wxeFifo(unsigned int sz) m_max = sz; m_n = 0; m_first = 0; + cb_start = 0; m_old = NULL; for(unsigned int i = 0; i < sz; i++) { m_q[i].buffer = NULL; @@ -76,15 +77,30 @@ wxeFifo::~wxeFifo() { wxeCommand * wxeFifo::Get() { unsigned int pos; - if(m_n > 0) { + do { + if(m_n <= 0) + return NULL; + pos = m_first++; m_n--; m_first %= m_max; - return &m_q[pos]; - } - return NULL; + } while(m_q[pos].op == -1); + return &m_q[pos]; +} + +wxeCommand * wxeFifo::Peek(unsigned int *i) +{ + unsigned int pos; + do { + if(*i >= m_n || m_n <= 0) + return NULL; + pos = (m_first+*i) % m_max; + (*i)++; + } while(m_q[pos].op == -1); + return &m_q[pos]; } + void wxeFifo::Add(int fc, char * cbuf,int buflen, wxe_data *sd) { unsigned int pos; @@ -140,10 +156,12 @@ void wxeFifo::Append(wxeCommand *orig) pos = (m_first + m_n) % m_max; m_n++; + curr = &m_q[pos]; + curr->op = orig->op; + if(curr->op == -1) return; curr->caller = orig->caller; curr->port = orig->port; - curr->op = orig->op; curr->len = orig->len; curr->bin[0] = orig->bin[0]; curr->bin[1] = orig->bin[1]; @@ -171,17 +189,19 @@ void wxeFifo::Realloc() wxeCommand * old = m_q; wxeCommand * queue = (wxeCommand *)driver_alloc(new_sz*sizeof(wxeCommand)); + // fprintf(stderr, "\r\nrealloc qsz %d\r\n", new_sz);fflush(stderr); + m_max=new_sz; m_first = 0; m_n=0; m_q = queue; for(i=0; i < n; i++) { - unsigned int pos = i+first; - if(old[pos%max].op >= 0) { - Append(&old[pos%max]); - } + unsigned int pos = (i+first)%max; + if(old[pos].op >= 0) + Append(&old[pos]); } + for(i = m_n; i < new_sz; i++) { // Reset the rest m_q[i].buffer = NULL; m_q[i].op = -1; @@ -190,6 +210,26 @@ void wxeFifo::Realloc() m_old = old; } +// Strip end of queue if ops are already taken care of, avoids reallocs +void wxeFifo::Strip() +{ + while((m_n > 0) && (m_q[(m_first + m_n - 1)%m_max].op == -1)) { + m_n--; + } +} + +unsigned int wxeFifo::Cleanup(unsigned int def) +{ + if(m_old) { + driver_free(m_old); + m_old = NULL; + // Realloced we need to start from the beginning + return 0; + } else { + return def; + } +} + /* **************************************************************************** * TreeItemData * ****************************************************************************/ |