4 * Copyright 2008 Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. Furthermore if you modify this software you must label
20 * your software as modified software and not distribute it in such a
21 * fashion that it might be confused with the original M.I.T. software.
22 * M.I.T. makes no representations about the suitability of
23 * this software for any purpose. It is provided "as is" without express
24 * or implied warranty.
30 #pragma warning (disable : 4996)
32 #include "win-utils.h"
36 #include "cci_debugging.h"
39 // CountedBuffer makes a copy of the data. Each CountedBuffer must be deleted.
41 void deleteBuffer(char** buf) {
48 // WorkItem contains a CountedBuffer which must be deleted,
49 // so each WorkItem must be deleted.
50 WorkItem::WorkItem(k5_ipc_stream buf, WIN_PIPE* pipe, const long type, const long sst)
51 : _buf(buf), _rpcmsg(type), _pipe(pipe), _sst(sst) { }
53 WorkItem::WorkItem(const WorkItem& item) : _buf(NULL), _rpcmsg(0), _pipe(NULL), _sst(0) {
55 k5_ipc_stream _buf = NULL;
56 krb5int_ipc_stream_new(&_buf);
57 krb5int_ipc_stream_write(_buf,
58 krb5int_ipc_stream_data(item.payload()),
59 krb5int_ipc_stream_size(item.payload()) );
60 WorkItem(_buf, item._pipe, item._rpcmsg, item._sst);
63 WorkItem::WorkItem() : _buf(NULL), _rpcmsg(CCMSG_INVALID), _pipe(NULL), _sst(0) { }
65 WorkItem::~WorkItem() {
66 if (_buf) krb5int_ipc_stream_release(_buf);
67 if (_pipe) ccs_win_pipe_release(_pipe);
70 const k5_ipc_stream WorkItem::take_payload() {
71 k5_ipc_stream temp = payload();
76 WIN_PIPE* WorkItem::take_pipe() {
77 WIN_PIPE* temp = pipe();
82 WorkList::WorkList() {
83 assert(InitializeCriticalSectionAndSpinCount(&cs, 0x80000400));
86 WorkList::~WorkList() {
87 // Delete any WorkItems in the queue:
89 cci_debug_printf("%s", __FUNCTION__);
91 char* pbuf = (char*)buf;
92 while (remove(&item)) {
93 cci_debug_printf("WorkList::~WorkList() deleting %s", item->print(pbuf));
97 DeleteCriticalSection(&cs);
100 char* WorkItem::print(char* buf) {
101 sprintf(buf, "WorkItem msg#:%d sst:%ld pipe:<%s>/0x%X", _rpcmsg, _sst,
102 ccs_win_pipe_getUuid(_pipe), ccs_win_pipe_getHandle(_pipe));
106 int WorkList::add(WorkItem* item) {
107 EnterCriticalSection(&cs);
109 LeaveCriticalSection(&cs);
113 int WorkList::remove(WorkItem** item) {
116 bEmpty = wl.empty() & 1;
119 EnterCriticalSection(&cs);
122 LeaveCriticalSection(&cs);