This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from erikd/ao-curses
Add two new locks
- Loading branch information
Showing
4 changed files
with
78 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
#include <pthread.h> | ||
#include <stdbool.h> | ||
|
||
#include "ux_locks.h" | ||
|
||
static bool music_playing = false; | ||
static pthread_mutex_t music_playing_mutex = PTHREAD_MUTEX_INITIALIZER; | ||
|
||
static int musicnum = 0; | ||
static pthread_mutex_t musicnum_mutex = PTHREAD_MUTEX_INITIALIZER; | ||
|
||
bool | ||
get_music_playing (void) | ||
{ | ||
bool value; | ||
|
||
pthread_mutex_lock (&music_playing_mutex); | ||
value = music_playing; | ||
pthread_mutex_unlock (&music_playing_mutex); | ||
return value; | ||
} | ||
|
||
|
||
bool | ||
set_music_playing (bool new_value) | ||
{ | ||
bool old_value; | ||
|
||
pthread_mutex_lock (&music_playing_mutex); | ||
old_value = music_playing; | ||
music_playing = new_value; | ||
pthread_mutex_unlock (&music_playing_mutex); | ||
return old_value; | ||
} | ||
|
||
|
||
int | ||
get_musicnum (void) | ||
{ | ||
int value; | ||
|
||
pthread_mutex_lock (&musicnum_mutex); | ||
value = musicnum; | ||
pthread_mutex_unlock (&musicnum_mutex); | ||
return value; | ||
} | ||
|
||
|
||
int | ||
set_musicnum (int new_value) | ||
{ | ||
int old_value; | ||
|
||
pthread_mutex_lock (&musicnum_mutex); | ||
old_value = musicnum; | ||
musicnum = new_value; | ||
pthread_mutex_unlock (&musicnum_mutex); | ||
return old_value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
bool get_music_playing (void); | ||
bool set_music_playing (bool new_value); | ||
|
||
int get_musicnum (void); | ||
int set_musicnum (int new_value); |