Jack2  1.9.10
JackWinProcessSync.h
00001 /*
00002  Copyright (C) 2004-2008 Grame
00003 
00004  This program is free software; you can redistribute it and/or modify
00005  it under the terms of the GNU Lesser General Public License as published by
00006  the Free Software Foundation; either version 2.1 of the License, or
00007  (at your option) any later version.
00008 
00009  This program is distributed in the hope that it will be useful,
00010  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  GNU Lesser General Public License for more details.
00013 
00014  You should have received a copy of the GNU Lesser General Public License
00015  along with this program; if not, write to the Free Software
00016  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 
00018 */
00019 
00020 #ifndef __JackWinProcessSync__
00021 #define __JackWinProcessSync__
00022 
00023 #include "JackWinMutex.h"
00024 
00025 namespace Jack
00026 {
00027 
00032 class JackWinProcessSync : public JackWinMutex
00033 {
00034 
00035     private:
00036 
00037         HANDLE fEvent;
00038 
00039     public:
00040 
00041         JackWinProcessSync(const char* name = NULL):JackWinMutex(name)
00042         {
00043             if (name) {
00044                 char buffer[MAX_PATH];
00045                 snprintf(buffer, sizeof(buffer), "%s_%s", "JackWinProcessSync", name);
00046                 fEvent = CreateEvent(NULL, TRUE, FALSE, buffer);  // Needs ResetEvent
00047                 //fEvent = CreateEvent(NULL, FALSE, FALSE, buffer);   // Auto-reset event
00048             } else {
00049                 fEvent = CreateEvent(NULL, TRUE, FALSE, NULL);   // Needs ResetEvent
00050                 //fEvent = CreateEvent(NULL, FALSE, FALSE, NULL);   // Auto-reset event
00051             }
00052 
00053             ThrowIf((fEvent == 0), JackException("JackWinProcessSync: could not init the event"));
00054         }
00055         virtual ~JackWinProcessSync()
00056         {
00057             CloseHandle(fEvent);
00058         }
00059 
00060         bool TimedWait(long usec);
00061         bool LockedTimedWait(long usec);
00062 
00063         void Wait();
00064         void LockedWait();
00065 
00066         void Signal();
00067         void LockedSignal();
00068 
00069         void SignalAll();
00070         void LockedSignalAll();
00071 };
00072 
00073 } // end of namespace
00074 
00075 #endif
00076