2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
32 #include "wine/winbase16.h"
33 #include "wine/winuser16.h"
36 #include "user_private.h"
38 #include "wine/debug.h"
39 #include "wine/server.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msg);
44 /***********************************************************************
45 * QUEUE_CreateMsgQueue
47 * Creates a message queue. Doesn't link it into queue list!
49 static HQUEUE16 QUEUE_CreateMsgQueue(void)
53 MESSAGEQUEUE * msgQueue;
55 TRACE_(msg)("(): Creating message queue...\n");
57 if (!(hQueue = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT,
58 sizeof(MESSAGEQUEUE) )))
61 msgQueue = (MESSAGEQUEUE *) GlobalLock16( hQueue );
65 SERVER_START_REQ( get_msg_queue )
67 wine_server_call_err( req );
68 handle = reply->handle;
73 ERR_(msg)("Cannot get thread queue\n");
74 GlobalFree16( hQueue );
77 msgQueue->server_queue = handle;
78 msgQueue->self = hQueue;
83 /***********************************************************************
86 * Get the current thread queue, creating it if required.
87 * QUEUE_Unlock is not needed since the queue can only be deleted by
88 * the current thread anyway.
90 MESSAGEQUEUE *QUEUE_Current(void)
92 HQUEUE16 hQueue = NtCurrentTeb()->queue;
96 if (!(hQueue = QUEUE_CreateMsgQueue())) return NULL;
97 SetThreadQueue16( 0, hQueue );
100 return GlobalLock16( hQueue );
105 /***********************************************************************
106 * QUEUE_DeleteMsgQueue
108 * Delete a message queue.
110 void QUEUE_DeleteMsgQueue(void)
112 HQUEUE16 hQueue = NtCurrentTeb()->queue;
113 MESSAGEQUEUE * msgQueue;
115 if (!hQueue) return; /* thread doesn't have a queue */
117 TRACE("(): Deleting message queue %04x\n", hQueue);
119 if (!(msgQueue = GlobalLock16( hQueue )))
121 ERR("invalid thread queue\n");
125 SetThreadQueue16( 0, 0 );
126 CloseHandle( msgQueue->server_queue );
127 GlobalFree16( hQueue );
131 /***********************************************************************
132 * InitThreadInput (USER.409)
134 HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags )
136 MESSAGEQUEUE *queue = QUEUE_Current();
137 return queue ? queue->self : 0;