Call CGit::DeleteRemoteRefs() to delete remote branch
[TortoiseGit.git] / src / AsyncFramework / Thread.h
blobffc401ad2175dfe547198982c5f430b8beab82ec
1 /***************************************************************************
2 * Copyright (C) 2009 by Stefan Fuhrmann *
3 * stefanfuhrmann@alice-dsl.de *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #pragma once
23 #include "WaitableEvent.h"
25 /**
26 * Repeatedly executes a function until \ref Terminate
27 * is called. The function should not be long-running.
28 * If the function returns \a true, the thread will terminate
29 * automatically and delete the CThread instance.
31 * \ref Suspend and \ref Resume will not wait until the
32 * thread actually enters the respective state.
33 * \ref Terminate, however, will only return when \ref func
34 * has exited and will not be called again.
36 * Please note that this class is designed to be controlled
37 * by _one_ outer thread. Trying to control it from multiple
38 * threads may result in unstable behavior.
41 namespace async
44 class CThread
46 private:
48 /// the thread handle
50 uintptr_t thread;
52 /// if set, the thread function should exit asap
54 volatile bool terminated;
56 /// set, if the thread function has terminated
58 CWaitableEvent done;
60 /// allow for the thread to become inactive
62 volatile bool suspended;
63 CWaitableEvent suspend;
64 CWaitableEvent resume;
66 /// to be executed cyclicly
68 bool (*func)(void *);
69 void* args;
71 /// the actual thread function
73 static void ThreadFunc (void*);
75 public:
77 /// auto-start thread during construction
79 CThread (bool (*func)(void *), void* args, bool startSuspended = false);
80 ~CThread(void);
82 /// thread control
84 void Suspend();
85 void Resume();
86 void Terminate();