The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
save_blocker.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Daniel Franke.
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
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  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include "save_blocker.hpp"
16 #include <exception>
17 #include <iostream>
18 
21 SDL_sem* save_blocker::sem_ = SDL_CreateSemaphore(1);
22 
24  block();
25 }
26 
28  try {
29  unblock();
30  if(controller_ && callback_) {
31  (controller_->*callback_)();
32  controller_ = nullptr;
33  callback_ = nullptr;
34  }
35  } catch (std::exception & e) {
36  std::cerr << "Save blocker dtor swallowing an exception: " << e.what() << "\n";
37  }
38 }
39 
41  if(try_block()) {
42  unblock();
43  (controller->*callback)();
44  } else {
46  callback_ = callback;
47  }
48 }
49 
51  return SDL_SemValue(sem_) == 0;
52 }
53 
55  SDL_SemWait(sem_);
56 }
57 
59  return SDL_SemTryWait(sem_) == 0;
60 }
61 
63  assert(SDL_SemValue(sem_) == 0);
64  SDL_SemPost(sem_);
65 }
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1806
static void unblock()
static void on_unblock(play_controller *controller, void(play_controller::*callback)())
static void(play_controller::* callback_)()
static bool saves_are_blocked()
static void block()
static play_controller * controller_
static SDL_sem * sem_
static bool try_block()
#define e