xaizek / pms (License: GPLv3+) (since 2018-12-07)
Older version of Practical Music Search written in C++.
Commit ae1f4c2d00f8777eeed5a179bec70b3c27e38afa

Remove unneccessary locking.
Author: Kim Tore Jensen
Author date (UTC): 2014-09-30 17:30
Committer name: Kim Tore Jensen
Committer date (UTC): 2014-09-30 17:30
Parent(s): 6058e32d78d982e5f2b8d68b47414ee937842364
Signing key:
Tree: fe8774250b53e4d9449a02d817fc902b28cc1e45
File Lines added Lines deleted
src/console.c 0 8
src/curses.c 0 8
src/curses.h 0 3
src/mpd.c 2 3
src/mpd.h 1 1
src/pms.c 0 10
src/pms.h 0 10
src/topbar.c 0 7
src/window.c 0 4
File src/console.c changed (mode: 100644) (index 7fcf19c..87bedbf)
... ... void console(const char * format, ...) {
65 65 time_t t; time_t t;
66 66 va_list ap; va_list ap;
67 67
68 pthread_mutex_lock(&console_mutex);
69
70 68 line = new_logline(); line = new_logline();
71 69
72 70 va_start(ap, format); va_start(ap, format);
 
... ... void console(const char * format, ...) {
93 91 if (console_window->num_lines < console_window->height || console_window->position + console_window->height + 1 >= console_window->num_lines) { if (console_window->num_lines < console_window->height || console_window->position + console_window->height + 1 >= console_window->num_lines) {
94 92 console_scroll(1); console_scroll(1);
95 93 } }
96
97 pthread_mutex_unlock(&console_mutex);
98 94 } }
99 95
100 96 void console_draw_lines(long start, long end) { void console_draw_lines(long start, long end) {
 
... ... void console_draw_lines(long start, long end) {
103 99 long ptr; long ptr;
104 100 logline_t * line; logline_t * line;
105 101
106 pms_curses_lock();
107
108 102 ptr = console_window->position + start; ptr = console_window->position + start;
109 103 for (s = start; s <= end; s++) { for (s = start; s <= end; s++) {
110 104 if (ptr >= console_window->num_lines) { if (ptr >= console_window->num_lines) {
 
... ... void console_draw_lines(long start, long end) {
116 110 } }
117 111
118 112 wrefresh(window_main); wrefresh(window_main);
119
120 pms_curses_unlock();
121 113 } }
122 114
123 115 int console_scroll(long delta) { int console_scroll(long delta) {
File src/curses.c changed (mode: 100644) (index 3f74f83..f8e3b98)
... ... void curses_shutdown() {
82 82 int curses_get_input() { int curses_get_input() {
83 83 return wgetch(window_statusbar); return wgetch(window_statusbar);
84 84 } }
85
86 void pms_curses_lock() {
87 pthread_mutex_lock(&curses_mutex);
88 }
89
90 void pms_curses_unlock() {
91 pthread_mutex_unlock(&curses_mutex);
92 }
File src/curses.h changed (mode: 100644) (index 10868f4..c9e07b2)
... ... void curses_init_windows();
39 39 void curses_destroy_windows(); void curses_destroy_windows();
40 40
41 41 int curses_get_input(); int curses_get_input();
42
43 void pms_curses_lock();
44 void pms_curses_unlock();
File src/mpd.c changed (mode: 100644) (index 0305d0d..8fc1fb2)
... ... struct mpd_connection * pms_mpd_connect(const char * server, unsigned int port,
45 45 return connection; return connection;
46 46 } }
47 47
48 void pms_get_mpd_status(struct mpd_connection * connection, struct pms_state_t * state) {
48 void pms_mpd_get_status(struct mpd_connection * connection, struct pms_state_t * state) {
49 49 if (state->status) { if (state->status) {
50 50 mpd_status_free(state->status); mpd_status_free(state->status);
51 51 } }
 
... ... void pms_handle_mpd_idle_update(struct mpd_connection * connection, struct pms_s
82 82 } }
83 83
84 84 if (flags & (MPD_IDLE_QUEUE | MPD_IDLE_PLAYER | MPD_IDLE_MIXER | MPD_IDLE_OPTIONS)) { if (flags & (MPD_IDLE_QUEUE | MPD_IDLE_PLAYER | MPD_IDLE_MIXER | MPD_IDLE_OPTIONS)) {
85 pms_get_mpd_status(connection, state);
85 pms_mpd_get_status(connection, state);
86 86 } }
87 87
88 88 topbar_draw(); topbar_draw();
89 89
90 90 } }
91
File src/mpd.h changed (mode: 100644) (index 245fe9e..d253068)
... ... struct pms_state_t;
23 23
24 24 struct mpd_connection * pms_mpd_connect(const char * server, unsigned int port, unsigned int timeout); struct mpd_connection * pms_mpd_connect(const char * server, unsigned int port, unsigned int timeout);
25 25
26 void pms_get_mpd_status(struct mpd_connection * connection, struct pms_state_t * state);
26 void pms_mpd_get_status(struct mpd_connection * connection, struct pms_state_t * state);
27 27
28 28 void pms_handle_mpd_idle_update(struct mpd_connection * connection, struct pms_state_t * state, enum mpd_idle flags); void pms_handle_mpd_idle_update(struct mpd_connection * connection, struct pms_state_t * state, enum mpd_idle flags);
File src/pms.c changed (mode: 100644) (index 9c8fca3..c1eb6dc)
... ... void shutdown() {
79 79
80 80 void signal_resize(int signal) { void signal_resize(int signal) {
81 81 console("Resized to %d x %d", LINES, COLS); console("Resized to %d x %d", LINES, COLS);
82 pms_curses_lock();
83 82 curses_destroy_windows(); curses_destroy_windows();
84 83 curses_init_windows(); curses_init_windows();
85 pms_curses_unlock();
86 84 } }
87 85
88 86 void signal_kill(int signal) { void signal_kill(int signal) {
 
... ... int main(int argc, char** argv) {
187 185
188 186 return PMS_EXIT_SUCCESS; return PMS_EXIT_SUCCESS;
189 187 } }
190
191 void pms_status_lock() {
192 pthread_mutex_lock(&status_mutex);
193 }
194
195 void pms_status_unlock() {
196 pthread_mutex_unlock(&status_mutex);
197 }
File src/pms.h changed (mode: 100644) (index 13533ff..90d92f3)
... ... void shutdown();
72 72 * Print a debug message to stderr * Print a debug message to stderr
73 73 */ */
74 74 void debug(const char * format, ...); void debug(const char * format, ...);
75
76 /**
77 * Lock MPD status object
78 */
79 void pms_status_lock();
80
81 /**
82 * Lock MPD status object
83 */
84 void pms_status_unlock();
File src/topbar.c changed (mode: 100644) (index feec7f2..8e9cebd)
... ... void topbar_draw() {
29 29 return; return;
30 30 } }
31 31
32 pms_curses_lock();
33 pms_status_lock();
34
35 32 mvwprintw(window_topbar, 0, 0, "%s %s %s [%s]", mvwprintw(window_topbar, 0, 0, "%s %s %s [%s]",
36 33 PACKAGE_NAME, PACKAGE_VERSION, PACKAGE_NAME, PACKAGE_VERSION,
37 34 topbar_playing_str(), topbar_playing_str(),
38 35 topbar_mode_str()); topbar_mode_str());
39 36 wrefresh(window_topbar); wrefresh(window_topbar);
40
41 pms_status_unlock();
42 pms_curses_unlock();
43
44 37 } }
45 38
46 39 const char * topbar_mode_str() { const char * topbar_mode_str() {
File src/window.c changed (mode: 100644) (index 5ca9b33..4b70a86)
... ... int window_scroll(window_t * window, long delta) {
29 29 return 0; return 0;
30 30 } }
31 31
32 pms_curses_lock();
33
34 32 if (delta > 0) { if (delta > 0) {
35 33 npos = window->position + delta; npos = window->position + delta;
36 34 if (npos + window->height > window->num_lines) { if (npos + window->height > window->num_lines) {
 
... ... int window_scroll(window_t * window, long delta) {
49 47 wscrl(window_main, delta); wscrl(window_main, delta);
50 48 wrefresh(window_main); wrefresh(window_main);
51 49
52 pms_curses_unlock();
53
54 50 return delta; return delta;
55 51
56 52 } }
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/pms

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/pms

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master