Fawkes API  Fawkes Development Version
semset.h
1 
2 /***************************************************************************
3  * semset.h - IPC semaphore set
4  *
5  * Generated: Tue Sep 19 14:45:47 2006
6  * Copyright 2006 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __UTILS_IPC_SEMSET_H_
25 #define __UTILS_IPC_SEMSET_H_
26 
27 namespace fawkes {
28 
29 
30 class SemaphoreSetData;
31 
32 class SemaphoreSet {
33  public:
34 
35  SemaphoreSet(const char *path, char id,
36  int num_sems,
37  bool create = false,
38  bool destroy_on_delete = false);
39 
40  SemaphoreSet(int key,
41  int num_sems,
42  bool create = false,
43  bool destroy_on_delete = false);
44 
45  SemaphoreSet( int num_sems,
46  bool destroy_on_delete = false);
47 
48  ~SemaphoreSet();
49 
50  bool valid();
51  void lock(unsigned short sem_num = 0, short num = 1);
52  bool try_lock(unsigned short sem_num = 0, short num = 1);
53  void unlock(unsigned short sem_num = 0, short num = -1);
54  void set_value(int sem_num, int val);
55  int get_value(int sem_num);
56  int key();
57  void set_destroy_on_delete(bool destroy);
58 
59  static int free_key();
60  static void destroy(int key);
61 
62  protected:
64 
65  private:
66  SemaphoreSetData *data;
67 
68 };
69 
70 
71 } // end namespace fawkes
72 
73 #endif
IPC semaphore set.
Definition: semset.h:32
bool valid()
Check if the semaphore set is valid.
Definition: semset.cpp:216
Fawkes library namespace.
static int free_key()
Get a non-zero free key Scans the key space sequentially until a non-zero unused key is found...
Definition: semset.cpp:390
static void destroy(int key)
Destroy a semaphore set.
Definition: semset.cpp:414
void lock(unsigned short sem_num=0, short num=1)
Lock resources on the semaphore set.
Definition: semset.cpp:255
~SemaphoreSet()
Destructor.
Definition: semset.cpp:200
void set_destroy_on_delete(bool destroy)
Set if semaphore set should be destroyed on delete.
Definition: semset.cpp:373
int key()
Get key of semaphore.
Definition: semset.cpp:360
void unlock(unsigned short sem_num=0, short num=-1)
Unlock resources on the semaphore set.
Definition: semset.cpp:308
SemaphoreSet(const char *path, char id, int num_sems, bool create=false, bool destroy_on_delete=false)
Constructor.
Definition: semset.cpp:102
void set_value(int sem_num, int val)
Set the semaphore value.
Definition: semset.cpp:329
bool destroy_on_delete
Destroy this semaphore on delete?
Definition: semset.h:63
bool try_lock(unsigned short sem_num=0, short num=1)
Try to lock resources on the semaphore set.
Definition: semset.cpp:279
int get_value(int sem_num)
Get the semaphore value.
Definition: semset.cpp:348